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); }
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); } }
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); } }
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); }