Check yellow counts even in Hard difficulty (fixes #58)
This commit is contained in:
parent
7c11cfc5a2
commit
ddba750d12
65
src/clue.ts
65
src/clue.ts
|
@ -66,46 +66,41 @@ export function violation(
|
||||||
if (difficulty === Difficulty.Normal) {
|
if (difficulty === Difficulty.Normal) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
const ultra = difficulty === Difficulty.UltraHard;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const { letter, clue } of clues) {
|
for (const { letter, clue } of clues) {
|
||||||
const upper = letter.toUpperCase();
|
const clueCount = clues.filter(
|
||||||
|
(c) => c.letter === letter && c.clue !== Clue.Absent
|
||||||
|
).length;
|
||||||
|
const guessCount = guess.split(letter).length - 1;
|
||||||
|
const glyph = letter.toUpperCase();
|
||||||
|
const glyphs = glyph + (clueCount !== 1 ? "s" : "");
|
||||||
const nth = ordinal(i + 1);
|
const nth = ordinal(i + 1);
|
||||||
if (clue === Clue.Correct) {
|
|
||||||
if (guess[i] !== letter) {
|
// Hard: enforce greens stay in place.
|
||||||
return nth + " letter must be " + upper;
|
if (clue === Clue.Correct && guess[i] !== letter) {
|
||||||
}
|
return nth + " letter must be " + glyph;
|
||||||
} else if (clue === Clue.Elsewhere) {
|
|
||||||
if (!guess.includes(letter)) {
|
|
||||||
return "Guess must contain " + upper;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (difficulty === Difficulty.UltraHard) {
|
|
||||||
if (clue !== Clue.Correct && guess[i] === letter) {
|
// Hard: enforce yellows are used.
|
||||||
return nth + " letter can't be " + upper;
|
if (guessCount < clueCount) {
|
||||||
}
|
const atLeastN =
|
||||||
const clueCount = clues.filter(
|
clueCount > 1 ? `at least ${englishNumbers[clueCount]} ` : "";
|
||||||
(c) => c.letter === letter && c.clue !== Clue.Absent
|
return `Guess must contain ${atLeastN}${glyphs}`;
|
||||||
).length;
|
|
||||||
const guessCount = guess.split(letter).length - 1;
|
|
||||||
const hasAbsent = clues.some(
|
|
||||||
(c) => c.letter === letter && c.clue === Clue.Absent
|
|
||||||
);
|
|
||||||
const amount = englishNumbers[clueCount];
|
|
||||||
const s = clueCount !== 1 ? "s" : "";
|
|
||||||
if (hasAbsent) {
|
|
||||||
if (guessCount !== clueCount) {
|
|
||||||
if (clueCount === 0) {
|
|
||||||
return `Guess can't contain ${upper}`;
|
|
||||||
} else {
|
|
||||||
return `Guess must contain exactly ${amount} ${upper}${s}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (guessCount < clueCount) {
|
|
||||||
return `Guess must contain at least ${amount} ${upper}${s}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ultra Hard: disallow would-be greens.
|
||||||
|
if (ultra && clue !== Clue.Correct && guess[i] === letter) {
|
||||||
|
return nth + " letter can't be " + glyph;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ultra Hard: if the exact amount is known because of an Absent clue, enforce it.
|
||||||
|
if (ultra && clue === Clue.Absent && guessCount !== clueCount) {
|
||||||
|
return clueCount === 0
|
||||||
|
? `Guess can't contain ${glyph}`
|
||||||
|
: `Guess must contain exactly ${englishNumbers[clueCount]} ${glyphs}`;
|
||||||
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
Loading…
Reference in a new issue