Optimize simulation with logic-only solver, fix rectangular grid support, and improve worker pool
All checks were successful
Deploy to Production / deploy (push) Successful in 8s

This commit is contained in:
2026-02-13 05:18:55 +01:00
parent 48def6c400
commit 2cd32d4a3e
15 changed files with 641 additions and 282 deletions

View File

@@ -0,0 +1,49 @@
import { describe, it, expect } from 'vitest';
import { solvePuzzle } from './solver';
import { calculateHints } from './puzzleUtils';
describe('Solver Repro', () => {
it('should solve a simple generated puzzle', () => {
const grid = [
[1, 0, 1, 1, 0],
[1, 1, 0, 0, 1],
[0, 0, 1, 0, 0],
[1, 1, 1, 1, 1],
[0, 1, 0, 1, 0]
];
const { rowHints, colHints } = calculateHints(grid);
const result = solvePuzzle(rowHints, colHints);
expect(result.percentSolved).toBe(100);
});
it('should not fail on random valid lines', () => {
// Test solveLine indirectly via solvePuzzle on small grids
for (let i = 0; i < 100; i++) {
const size = 10;
const grid = [];
for(let r=0; r<size; r++) {
const row = [];
for(let c=0; c<size; c++) row.push(Math.random() > 0.5 ? 1 : 0);
grid.push(row);
}
const { rowHints, colHints } = calculateHints(grid);
const result = solvePuzzle(rowHints, colHints);
// It might not be 100% solvable without guessing (logic only),
// but since our solver HAS backtracking, it MUST be 100% solvable
// (unless timeout/max depth reached, but for 10x10 it should solve).
// If it returns 0% or low %, it implies it failed to find the solution
// or found a contradiction (which shouldn't happen for valid hints).
if (result.percentSolved < 100) {
console.log('Failed Grid:', JSON.stringify(grid));
console.log('Result:', result);
}
expect(result.percentSolved).toBe(100);
}
});
});