Sfoglia il codice sorgente

refactor: simplify solver steps from objects to string arrays

Steps changed from [{guess: 'raise'}, ...] to ['raise', ...].
Removed SolverStep interface entirely. Data files ~25% smaller.
Oleg Panashchenko 1 settimana fa
parent
commit
16534fe334

+ 3 - 3
client/src/screens/Screen3Results.tsx

@@ -52,11 +52,11 @@ function MiniBoard({ replay, targetWord }: { replay: SolverReplay; targetWord: s
       <div style={{ fontSize: '0.7rem', fontWeight: 'bold', color: '#555', marginBottom: '4px', textAlign: 'center' }}>
         {replay.solver}
       </div>
-      {replay.steps.map((step, rowIdx) => {
-        const colors = computeFeedback(targetWord, step.guess);
+      {replay.steps.map((guess, rowIdx) => {
+        const colors = computeFeedback(targetWord, guess);
         return (
           <div key={rowIdx} style={{ display: 'flex', gap: '2px', justifyContent: 'center', marginBottom: '2px' }}>
-            {step.guess.split('').map((letter, colIdx) => {
+            {guess.split('').map((letter, colIdx) => {
               const c = colors[colIdx];
               return (
                 <div key={colIdx} style={{

File diff suppressed because it is too large
+ 194 - 582
data/word-bank-ru.json


File diff suppressed because it is too large
+ 188 - 564
data/word-bank.json


+ 2 - 6
shared/src/word-bank.ts

@@ -1,12 +1,8 @@
-/** A single solver replay step — colors are computed client-side from the known target word */
-export interface SolverStep {
-  guess: string;
-}
-
 /** Replay from one solver algorithm */
 export interface SolverReplay {
   solver: string;
-  steps: SolverStep[];
+  /** Sequence of guesses the solver made (colors computed client-side from the known target word) */
+  steps: string[];
 }
 
 /** A target word with its pre-computed difficulty score */

+ 3 - 5
solver/src/entropy.ts

@@ -1,5 +1,3 @@
-import type { SolverStep } from '@wordle/shared';
-
 const ALL_FEEDBACK: string[] = [];
 
 function buildFeedbackPatterns(): string[] {
@@ -23,10 +21,10 @@ function getFeedback(target: string, guess: string): string {
   return r.join('');
 }
 
-export function solveEntropy(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: SolverStep[] } {
+export function solveEntropy(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: string[] } {
   buildFeedbackPatterns();
   let candidates = [...allWords];
-  const steps: SolverStep[] = [];
+  const steps: string[] = [];
 
   for (let attempt = 1; attempt <= maxAttempts; attempt++) {
     let bestGuess = candidates[0];
@@ -45,7 +43,7 @@ export function solveEntropy(target: string, allWords: string[], maxAttempts = 6
     }
 
     const fb = getFeedback(target, bestGuess);
-    steps.push({ guess: bestGuess });
+    steps.push(bestGuess);
 
     if (fb === 'ggggg') return { attempts: attempt, steps };
 

+ 3 - 5
solver/src/frequency.ts

@@ -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> = {};
@@ -25,9 +23,9 @@ function scoreWord(word: string, freq: Record<string, number>): number {
   return s;
 }
 
-export function solveFrequency(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: SolverStep[] } {
+export function solveFrequency(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: string[] } {
   let candidates = [...allWords];
-  const steps: SolverStep[] = [];
+  const steps: string[] = [];
 
   for (let attempt = 1; attempt <= maxAttempts; attempt++) {
     const freq = letterFrequency(candidates);
@@ -36,7 +34,7 @@ export function solveFrequency(target: string, allWords: string[], maxAttempts =
     for (const g of pool) { const s = scoreWord(g, freq); if (s > bestScore) { bestScore = s; bestGuess = g; } }
 
     const fb = getFeedback(target, bestGuess);
-    steps.push({ guess: bestGuess });
+    steps.push(bestGuess);
     if (fb === 'ggggg') return { attempts: attempt, steps };
 
     candidates = candidates.filter((c) => getFeedback(c, bestGuess) === fb);

+ 3 - 5
solver/src/greedy.ts

@@ -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 });
+    steps.push(guess);
     if (fb === 'ggggg') return { attempts: attempt, steps };
 
     candidates = candidates.filter((c) => matchesFeedback(c, guess, fb));

+ 3 - 5
solver/src/vowel-first.ts

@@ -1,5 +1,3 @@
-import type { SolverStep } from '@wordle/shared';
-
 const VOWELS = new Set(['a','e','i','o','u']);
 
 function getFeedback(target: string, guess: string): string {
@@ -25,10 +23,10 @@ function pickBestVowelWord(pool: string[], knownVowels: Set<string>): string {
   return bestGuess;
 }
 
-export function solveVowelFirst(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: SolverStep[] } {
+export function solveVowelFirst(target: string, allWords: string[], maxAttempts = 6): { attempts: number; steps: string[] } {
   let candidates = [...allWords];
   const knownVowels = new Set<string>();
-  const steps: SolverStep[] = [];
+  const steps: string[] = [];
 
   for (let attempt = 1; attempt <= maxAttempts; attempt++) {
     let bestGuess: string;
@@ -40,7 +38,7 @@ export function solveVowelFirst(target: string, allWords: string[], maxAttempts
     }
 
     const fb = getFeedback(target, bestGuess);
-    steps.push({ guess: bestGuess });
+    steps.push(bestGuess);
     if (fb === 'ggggg') return { attempts: attempt, steps };
 
     for (let i = 0; i < 5; i++) { if ((fb[i] === 'g' || fb[i] === 'y') && VOWELS.has(bestGuess[i])) knownVowels.add(bestGuess[i]); }

Some files were not shown because too many files changed in this diff