Beispiel #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();
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 public bool IsComplete()
 {
     return(!UnsolvedCells.Any());
 }
Beispiel #5
0
 internal bool IsComplete()
 {
     return(!UnsolvedCells.Any());
 }