Example #1
0
        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());
        }
Example #3
0
        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();
                }
            }
        }
Example #4
0
 public HiddenSubsetTechnique(LogicalSolver logicalSolver) : base(logicalSolver)
 {
 }
Example #5
0
 public NakedSubsetTechnique(LogicalSolver logicalSolver) : base(logicalSolver)
 {
 }
Example #6
0
 public TwoDirectionTechnique(LogicalSolver logicalSolver) : base(logicalSolver)
 {
 }
Example #7
0
 public SolverTechnique(LogicalSolver logicalSolver)
 {
     LogicalSolver = logicalSolver;
 }
Example #8
0
 public SingleOptionTechnique(LogicalSolver logicalSolver) : base(logicalSolver)
 {
 }
 public SquareRowInteractionTechnique(LogicalSolver logicalSolver) : base(logicalSolver)
 {
 }