/// <summary> /// Initializes a new instance of the <see cref="SudokuBoard"/> class. /// </summary> /// <param name="copy">The copy.</param> /// <param name="language">The language.</param> private SudokuBoard(SudokuBoard copy, ILanguage language) { this.language = language; this.maximumValue = copy.maximumValue; this.tiles = new SudokuTile[copy.Width, copy.Height]; this.CreateTiles(); // Copy the tile values foreach (var position in SudokuFactory.Box(this.Width, this.Height)) { this.tiles[position.Item1, position.Item2] = new SudokuTile(position.Item1, position.Item2, this.maximumValue, this.language) { Value = copy.tiles[position.Item1, position.Item2].Value }; } // Copy the rules foreach (var rule in copy.rules) { var ruleTiles = new HashSet <SudokuTile>(); foreach (var tile in rule) { ruleTiles.Add(this.tiles[tile.X, tile.Y]); } this.rules.Add(new SudokuRule(ruleTiles, rule.Description)); } }
/// <summary> /// Creates the tiles. /// </summary> private void CreateTiles() { foreach (var position in SudokuFactory.Box(this.tiles.GetLength(0), this.tiles.GetLength(1))) { this.tiles[position.Item1, position.Item2] = new SudokuTile(position.Item1, position.Item2, this.maximumValue, this.language); } }
/// <summary> /// Adds the boxes count. /// </summary> /// <param name="boxesX">The boxes X value.</param> /// <param name="boxesY">The boxes Y value.</param> internal void AddBoxesCount(int boxesX, int boxesY) { var sizeX = this.Width / boxesX; var sizeY = this.Height / boxesY; var boxes = SudokuFactory.Box(sizeX, sizeY); foreach (var position in boxes) { var boxTiles = this.TileBox(position.Item1 * sizeX, position.Item2 * sizeY, sizeX, sizeY); this.CreateRule(this.language.GetWord("BoxAt") + position.Item1 + ", " + position.Item2 + ")", boxTiles); } }
/// <summary> /// Gets the tile box. /// </summary> /// <param name="startX">The start x value.</param> /// <param name="startY">The start y value.</param> /// <param name="sizeX">The size x value.</param> /// <param name="sizeY">The size y value.</param> /// <returns>A <see cref="IEnumerable{T}"/> of <see cref="SudokuTile"/>s.</returns> private IEnumerable <SudokuTile> TileBox(int startX, int startY, int sizeX, int sizeY) { return(from pos in SudokuFactory.Box(sizeX, sizeY) select this.tiles[startX + pos.Item1, startY + pos.Item2]); }