feat: expand sudoku analysis and interoperability
This commit is contained in:
@@ -111,6 +111,13 @@ export function solveExact(
|
||||
"timeoutMs",
|
||||
);
|
||||
const compiled = compilePuzzle(normalized);
|
||||
const preferredSolution =
|
||||
normalized.solution !== undefined &&
|
||||
board.every(
|
||||
(value, cell) => value === 0 || value === normalized.solution?.[cell],
|
||||
)
|
||||
? normalized.solution
|
||||
: undefined;
|
||||
const random: RandomSource | undefined =
|
||||
options.seed === undefined ? undefined : seededRandom(options.seed);
|
||||
const solutions: number[][] = [];
|
||||
@@ -157,6 +164,15 @@ export function solveExact(
|
||||
const chosen = selection[0];
|
||||
let choices = selection[1];
|
||||
if (random !== undefined) choices = shuffled(choices, random);
|
||||
else {
|
||||
const preferred = preferredSolution?.[chosen];
|
||||
if (preferred !== undefined && choices.includes(preferred)) {
|
||||
choices = [
|
||||
preferred,
|
||||
...choices.filter((value) => value !== preferred),
|
||||
];
|
||||
}
|
||||
}
|
||||
for (const value of choices) {
|
||||
board[chosen] = value;
|
||||
search();
|
||||
|
||||
Reference in New Issue
Block a user