public void SetCellValue(int row, int col, int value) { Cell activeCell = this.Cells.SingleOrDefault(cell => cell.Row == row && cell.Column == col); if (activeCell == null) { throw new Exception("You shouldn't have done that, he's just a cell mmmhmmm."); } activeCell.Value = value; // remove given value from possibilities for row foreach (var rowCell in this.Cells.Where(cell => cell.Row == row && !cell.IsSolved)) { rowCell.PossibleValues.Remove(value); } // remove given value from possibilities for column foreach (var colCell in this.Cells.Where(cell => cell.Column == col && !cell.IsSolved)) { colCell.PossibleValues.Remove(value); } // remove given value from possibilities for square foreach (var squareCell in this.Cells.Where(cell => cell.Square == activeCell.Square && !cell.IsSolved)) { squareCell.PossibleValues.Remove(value); } if (this.solving) { // solve any others that only have one possibility LogicalSolver.SetCellValueForNakedSingles(this); } }
public int[][] Solve(int[][] sudoku) { LogicalSolver solver = new LogicalSolver(sudoku); solver.Solve(); Debug.Assert(solver.IsCorrect()); return(solver.ExportSolution()); }
public void SolvePuzzle() { this.solving = true; if (!this.BruteForceSolve) { LogicalSolver.Solve(this); // not solved, do we fall back? Debugger.Break(); } else { LogicalSolver.SetCellValueForNakedSingles(this); this.Solved = BruteForceSolver.Solve(this); if (!this.Solved) { Debugger.Break(); } } }
public HiddenSubsetTechnique(LogicalSolver logicalSolver) : base(logicalSolver) { }
public NakedSubsetTechnique(LogicalSolver logicalSolver) : base(logicalSolver) { }
public TwoDirectionTechnique(LogicalSolver logicalSolver) : base(logicalSolver) { }
public SolverTechnique(LogicalSolver logicalSolver) { LogicalSolver = logicalSolver; }
public SingleOptionTechnique(LogicalSolver logicalSolver) : base(logicalSolver) { }
public SquareRowInteractionTechnique(LogicalSolver logicalSolver) : base(logicalSolver) { }