import { readFileSync, writeFileSync } from 'node:fs'; import { Game } from '../src/game'; import { solve } from '../src/solver'; import type { Level } from '../src/types'; const file = new URL('../levels/campaign.json', import.meta.url); const pack = JSON.parse(readFileSync(file, 'utf8')) as { levels: Level[] }; for (const level of pack.levels) { if (level.solution?.length) continue; let found = false; for (let trial = 0; trial < 24; trial++) { const start = Date.now(); const game = new Game(level); const solution = solve(game, level.id < 7 ? 12 : 18); console.log(`L${level.id} seed=${level.seed} ${solution ? `WIN ${solution.path.length} moves / ${solution.visited} states` : 'no proof'} ${Date.now() - start}ms`); if (solution) { level.solution = solution.path; level.par = solution.path.length; writeFileSync(file, JSON.stringify(pack, null, 2) + '\n'); found = true; break; } level.seed += 137; } if (!found) throw new Error(`Unable to find L${level.id}`); }