A generator for solvable Sudokus using Wave Function Collapse principles.
npm install
npm run build
node . [N]
N is the number of fields that should remaing unsolved. A value of 0 solves the entire field.
The generator relies on the same principles behind Wave Function Collapse, though it was optimized according to the rules of Sudoku. With a little extra work it could even support abnormal cell groupings, as seen on harder ("impossible") Sudokus. As a step by step:
- Generate 3*N
Set
s containing all possible numbers for a Row, Column and Group. - Generate an
Array
of N*NCell
s and assign them aSet
for Row, Column and Group generated in Step 1. - While we still have unsolved
Cell
s:- Randomize the
Array
of unsolvedCell
s fairly. - Pick a
Cell
with the lowest available options. - Collapse the chosen
Cell
. - Remove the chosen
Cell
from the remaining unsolvedCell
s.
- Randomize the
- Done!
- Sometimes it needs more than one cycle to generate a field, which is most likely due to the naive collapse() function.
- Perhaps this may be solvable with validated solving to ensure that the chosen value will not eliminate all possible solutions from another Row, Column or Group.