示例#1
0
        public Puzzle(string filename)
        {
            Rows = new Group[9];
            Columns = new Group[9];
            Grids = new Group[9];
            Solutions = new List<int[,]>();

            int rowIndex = 0;
            using (StreamReader sr = new StreamReader(filename))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    Group row = new Group();

                    for (int i = 0; i < 9; i++)
                    {
                        Tile tile = new Tile();

                        char c = line[i];
                        if (c == 'B')
                        {
                            tile.Given = false;
                        }
                        else
                        {
                            tile.Given = true;
                            tile.Value = c - 48; // Convert to "face value" of char; 0 is ascii 48.
                        }

                        row.Tiles[i] = tile;
                        tile.RowIndex = rowIndex;
                    }

                    Rows[rowIndex] = row;
                    rowIndex++;
                }
            }

            SetupColumns();

            SetupGrids();
        }
示例#2
0
        public Puzzle(int[,] input)
        {
            Rows = new Group[9];
            Columns = new Group[9];
            Grids = new Group[9];
            Solutions = new List<int[,]>();

            for (int row = 0; row < 9; row++)
            {
                Rows[row] = new Group();

                for (int col = 0; col < 9; col++)
                {
                    int value = input[row, col];

                    Tile tile = new Tile();
                    tile.RowIndex = row;

                    if (value > 0)
                    {
                        // This is a given tile.
                        tile.Given = true;

                        tile.Value = value;
                    }
                    else
                    {
                        // This is an unknown value to solve for.
                        tile.Given = false;
                    }

                    Rows[row].Tiles[col] = tile;
                }
            }

            SetupColumns();

            SetupGrids();
        }
示例#3
0
 public Group()
 {
     Tiles = new Tile[9];
     Solutions = new List<int[]>();
 }