public void Solve() { IList <Cell> solvedCells = new List <Cell>(); foreach (var cell in UnsolvedCells) { var elements = Board.GetSudokuElementsAtCell(cell.X, cell.Y); var cellSolution = SudokuElementSolution.GetUniqueCellSolution(elements); if (cellSolution == SudokuElementSolution.INVALID_VALUE) { continue; } solvedCells.Add(cell); Board.Cells[cell.X, cell.Y] = cellSolution; SudokuElementSolution.RemovePossibility(elements, cellSolution); } if (!solvedCells.Any()) { throw new Exception("Unsolvable sudoku: ran out of solutions"); } UnsolvedCells = UnsolvedCells.Except(solvedCells).ToList(); if (UnsolvedCells.Any()) { Solve(); } }
internal void AssignGuess(CellWithSolutions cellWithLeastSolutions, int guess) { var cell = cellWithLeastSolutions.Cell; var elements = Board.GetSudokuElements(cell.X, cell.Y); SudokuElementSolution.RemovePossibility(elements, guess); Board.CellsSolution[cell.X, cell.Y] = guess; UnsolvedCells.Remove(cell); }
public Game Clone() { var clonedGame = MemberwiseClone() as Game; var clonedBoard = Board.Clone() as GameBoard; clonedGame.Board = clonedBoard; clonedGame.UnsolvedCells = UnsolvedCells.ToArray().CloneElementsDeep().ToList(); return(clonedGame); }
public bool IsComplete() { return(!UnsolvedCells.Any()); }
internal bool IsComplete() { return(!UnsolvedCells.Any()); }