|
@@ -1,7 +1,6 @@
|
|
|
import type { SolverStep } from '@wordle/shared';
|
|
import type { SolverStep } from '@wordle/shared';
|
|
|
|
|
|
|
|
const VOWELS = new Set(['a','e','i','o','u']);
|
|
const VOWELS = new Set(['a','e','i','o','u']);
|
|
|
-const VOWEL_STARTS = ['adieu','audio','raise','arose','irate'];
|
|
|
|
|
|
|
|
|
|
function getFeedback(target: string, guess: string): string {
|
|
function getFeedback(target: string, guess: string): string {
|
|
|
const tu = target.toLowerCase(), gu = guess.toLowerCase();
|
|
const tu = target.toLowerCase(), gu = guess.toLowerCase();
|
|
@@ -15,6 +14,17 @@ function getFeedback(target: string, guess: string): string {
|
|
|
|
|
|
|
|
function matchesFeedback(c: string, g: string, fb: string): boolean { return getFeedback(c, g) === fb; }
|
|
function matchesFeedback(c: string, g: string, fb: string): boolean { return getFeedback(c, g) === fb; }
|
|
|
|
|
|
|
|
|
|
+function pickBestVowelWord(pool: string[], knownVowels: Set<string>): string {
|
|
|
|
|
+ let bestGuess = pool[0];
|
|
|
|
|
+ let best = -1;
|
|
|
|
|
+ for (const w of pool) {
|
|
|
|
|
+ const newV = [...w].filter((c) => VOWELS.has(c) && !knownVowels.has(c)).length;
|
|
|
|
|
+ const s = newV * 3 + new Set(w.split('')).size;
|
|
|
|
|
+ if (s > best) { best = s; bestGuess = w; }
|
|
|
|
|
+ }
|
|
|
|
|
+ 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: SolverStep[] } {
|
|
|
let candidates = [...allWords];
|
|
let candidates = [...allWords];
|
|
|
const knownVowels = new Set<string>();
|
|
const knownVowels = new Set<string>();
|
|
@@ -22,16 +32,9 @@ export function solveVowelFirst(target: string, allWords: string[], maxAttempts
|
|
|
|
|
|
|
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
|
let bestGuess: string;
|
|
let bestGuess: string;
|
|
|
- if (attempt === 1) {
|
|
|
|
|
- bestGuess = VOWEL_STARTS.find((w) => allWords.includes(w)) ?? 'arise';
|
|
|
|
|
- } else if (attempt <= 3 && knownVowels.size < 5) {
|
|
|
|
|
|
|
+ if (attempt <= 3 && knownVowels.size < 5) {
|
|
|
const pool = candidates.length > 0 ? candidates : allWords;
|
|
const pool = candidates.length > 0 ? candidates : allWords;
|
|
|
- bestGuess = pool[0]; let best = -1;
|
|
|
|
|
- for (const w of pool) {
|
|
|
|
|
- const newV = [...w].filter((c) => VOWELS.has(c) && !knownVowels.has(c)).length;
|
|
|
|
|
- const s = newV * 3 + new Set(w.split('')).size;
|
|
|
|
|
- if (s > best) { best = s; bestGuess = w; }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ bestGuess = pickBestVowelWord(pool, knownVowels);
|
|
|
} else {
|
|
} else {
|
|
|
bestGuess = candidates[0];
|
|
bestGuess = candidates[0];
|
|
|
}
|
|
}
|