Exemple #1
0
 private void CreateTiles()
 {
     foreach (var pos in SudokuBoard.Box(tiles.GetLength(0), tiles.GetLength(1)))
     {
         tiles[pos.Item1, pos.Item2] = new SudokuTile(pos.Item1, pos.Item2, _maxValue);
     }
 }
Exemple #2
0
        internal void AddBoxesCount(int boxesX, int boxesY)
        {
            int sizeX = Width / boxesX;
            int sizeY = Height / boxesY;

            var boxes = SudokuBoard.Box(sizeX, sizeY);

            foreach (var pos in boxes)
            {
                IEnumerable <SudokuTile> boxTiles = TileBox(pos.Item1 * sizeX, pos.Item2 * sizeY, sizeX, sizeY);
                CreateRule("Box at (" + pos.Item1.ToString() + ", " + pos.Item2.ToString() + ")", boxTiles);
            }
        }
Exemple #3
0
        public SudokuBoard(SudokuBoard copy)
        {
            _maxValue = copy._maxValue;
            tiles     = new SudokuTile[copy.Width, copy.Height];
            CreateTiles();
            // Copy the tile values
            foreach (var pos in SudokuBoard.Box(Width, Height))
            {
                tiles[pos.Item1, pos.Item2]       = new SudokuTile(pos.Item1, pos.Item2, _maxValue);
                tiles[pos.Item1, pos.Item2].Value = copy.tiles[pos.Item1, pos.Item2].Value;
            }

            // Copy the rules
            foreach (SudokuRule rule in copy.rules)
            {
                var ruleTiles = new HashSet <SudokuTile>();
                foreach (SudokuTile tile in rule)
                {
                    ruleTiles.Add(tiles[tile.X, tile.Y]);
                }
                rules.Add(new SudokuRule(ruleTiles, rule.Description));
            }
        }
Exemple #4
0
 internal IEnumerable <SudokuTile> TileBox(int startX, int startY, int sizeX, int sizeY)
 {
     return(from pos in SudokuBoard.Box(sizeX, sizeY) select tiles[startX + pos.Item1, startY + pos.Item2]);
 }