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(); } }
public bool IsComplete() { return(!UnsolvedCells.Any()); }
internal bool IsComplete() { return(!UnsolvedCells.Any()); }