Sudoku Solver

UNITY

Sudoku Solver

Instant Sudoku solver.

Overview

An instant Sudoku solver implementing constraint-based logic with recursive backtracking as a fallback mechanism.

Algorithm

The solver iterates through several different approaches, such as going by row, column and 3x3 subgrid constraint rules. Once these deterministic methods fail, the solver selects the cell with the fewest possible candidates and assumes one of the possible numbers. If at some point the solver reaches a dead-end or an invalid grid (meaning it guessed wrong), it backtracks to the decision point where a fork was made. This recursive-backtracking approach is rarely called for standard-difficulty Sudoku puzzles, as the other methods are capable of finishing it on their own. The recursive guessing method has a fixed maximum depth to avoid a stack overflow.

Controls

• Left click on a cell to increment its number. • Right click on a cell to decrement its number. • Click 'SOLVE' to solve the Sudoku puzzle. The grid must have at least 17 present numbers to be solvable. If you click solve and nothing happens, then it's not solvable. • Click 'CLEAR' to clear the grid. The solver typically takes a few milliseconds to solve a Sudoku puzzle, but can take up to a second for really hard ones. It takes the solver around 2.5 seconds to solve the hardest Sudoku puzzle.

Tags

UnityRecursionC#