|
@@ -2,7 +2,8 @@ import { Router, Request, Response } from 'express';
|
|
|
import type { WordBank, GuessResponse, CachedResult } from '@wordle/shared';
|
|
import type { WordBank, GuessResponse, CachedResult } from '@wordle/shared';
|
|
|
import { isValidGuess, getTargetWord } from '../validate.js';
|
|
import { isValidGuess, getTargetWord } from '../validate.js';
|
|
|
import { computeFeedback } from '../feedback.js';
|
|
import { computeFeedback } from '../feedback.js';
|
|
|
-import { computeReplays, computeReplaysFull } from '@wordle/shared';
|
|
|
|
|
|
|
+import { computeReplays } from '@wordle/shared';
|
|
|
|
|
+import { runSolverInWorker } from '../solver-pool.js';
|
|
|
|
|
|
|
|
export function createGuessRouter(wordBank: WordBank, cache: Map<number, CachedResult>): Router {
|
|
export function createGuessRouter(wordBank: WordBank, cache: Map<number, CachedResult>): Router {
|
|
|
const router = Router();
|
|
const router = Router();
|
|
@@ -61,13 +62,12 @@ export function createGuessRouter(wordBank: WordBank, cache: Map<number, CachedR
|
|
|
cache.set(wordId, result);
|
|
cache.set(wordId, result);
|
|
|
|
|
|
|
|
// Fire background computation with all 4 solvers (including entropy)
|
|
// Fire background computation with all 4 solvers (including entropy)
|
|
|
- // Once complete, the cache is upgraded for the next time this word is played
|
|
|
|
|
|
|
+ // in a worker thread so the ~14s entropy run never blocks the API.
|
|
|
const targetWord = target.word;
|
|
const targetWord = target.word;
|
|
|
const guessable = wordBank.guessable;
|
|
const guessable = wordBank.guessable;
|
|
|
- setTimeout(() => {
|
|
|
|
|
- const full = computeReplaysFull(targetWord, guessable);
|
|
|
|
|
- cache.set(wordId, full);
|
|
|
|
|
- }, 0);
|
|
|
|
|
|
|
+ runSolverInWorker({ target: targetWord, allWords: guessable, mode: 'full' })
|
|
|
|
|
+ .then((full) => { cache.set(wordId, full); })
|
|
|
|
|
+ .catch((err) => { console.error('Solver worker failed:', err); });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
response.difficulty = result.difficulty;
|
|
response.difficulty = result.difficulty;
|