Esempio n. 1
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);
        }
Esempio n. 2
0
 private protected virtual void Guess(Game game, CellWithSolutions cellWithLeastSolutions)
 {
     foreach (var guess in cellWithLeastSolutions.Solutions)
     {
         var gameSnapshot = game.Clone();
         gameSnapshot.AssignGuess(cellWithLeastSolutions, guess);
         Solve(gameSnapshot);
     }
 }
Esempio n. 3
0
        private protected override void Guess(Game game, CellWithSolutions cellWithLeastSolutions)
        {
            var mixedSolutions = cellWithLeastSolutions.Solutions.ToList().Shuffle();

            foreach (var guess in mixedSolutions)
            {
                var gameSnapshot = game.Clone();
                gameSnapshot.AssignGuess(cellWithLeastSolutions, guess);
                Solve(gameSnapshot);
            }
        }
Esempio n. 4
0
        internal CellWithSolutions?FindCellWithLeastSolutions()
        {
            var leastSolutions = 10;
            CellWithSolutions?cellWithLeastOptions = null;

            foreach (var cell in UnsolvedCells)
            {
                var elements  = Board.GetSudokuElements(cell.X, cell.Y);
                var solutions = SudokuElementSolution.GetValidValues(elements);
                var count     = solutions.Count();
                if (count < leastSolutions && count > 0)
                {
                    leastSolutions       = count;
                    cellWithLeastOptions = new CellWithSolutions(cell, solutions);
                }
            }

            return(cellWithLeastOptions);
        }