|
|
@@ -1,5 +1,3 @@
|
|
|
-import type { SolverStep } from '@wordle/shared';
|
|
|
-
|
|
|
function getFeedback(target: string, guess: string): string {
|
|
|
const tu = target.toLowerCase(), gu = guess.toLowerCase();
|
|
|
const counts: Record<string, number> = {};
|
|
|
@@ -12,15 +10,15 @@ function getFeedback(target: string, guess: string): string {
|
|
|
|
|
|
function matchesFeedback(c: string, g: string, fb: string): boolean { return getFeedback(c, g) === fb; }
|
|
|
|
|
|
-export function solveGreedy(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: SolverStep[] } {
|
|
|
+export function solveGreedy(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: string[] } {
|
|
|
let candidates = [...allWords];
|
|
|
const STARTERS = ['crane','slate','arise','stare'];
|
|
|
- const steps: SolverStep[] = [];
|
|
|
+ const steps: string[] = [];
|
|
|
|
|
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
|
const guess = attempt === 1 ? (STARTERS.find((w) => allWords.includes(w)) ?? allWords[0]) : candidates[0];
|
|
|
const fb = getFeedback(target, guess);
|
|
|
- steps.push({ guess, colors: fb.split('') });
|
|
|
+ steps.push(guess);
|
|
|
if (fb === 'ggggg') return { attempts: attempt, steps };
|
|
|
|
|
|
candidates = candidates.filter((c) => matchesFeedback(c, guess, fb));
|