Пример #1
0
        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();
            }
        }
Пример #2
0
 public bool IsComplete()
 {
     return(!UnsolvedCells.Any());
 }
Пример #3
0
 internal bool IsComplete()
 {
     return(!UnsolvedCells.Any());
 }