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) {
|
||||
return undefined;
|
||||
}
|
||||
const ultra = difficulty === Difficulty.UltraHard;
|
||||
let i = 0;
|
||||
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);
|
||||
if (clue === Clue.Correct) {
|
||||
if (guess[i] !== letter) {
|
||||
return nth + " letter must be " + upper;
|
||||
}
|
||||
} else if (clue === Clue.Elsewhere) {
|
||||
if (!guess.includes(letter)) {
|
||||
return "Guess must contain " + upper;
|
||||
}
|
||||
|
||||
// Hard: enforce greens stay in place.
|
||||
if (clue === Clue.Correct && guess[i] !== letter) {
|
||||
return nth + " letter must be " + glyph;
|
||||
}
|
||||
if (difficulty === Difficulty.UltraHard) {
|
||||
if (clue !== Clue.Correct && guess[i] === letter) {
|
||||
return nth + " letter can't be " + upper;
|
||||
}
|
||||
const clueCount = clues.filter(
|
||||
(c) => c.letter === letter && c.clue !== Clue.Absent
|
||||
).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}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Hard: enforce yellows are used.
|
||||
if (guessCount < clueCount) {
|
||||
const atLeastN =
|
||||
clueCount > 1 ? `at least ${englishNumbers[clueCount]} ` : "";
|
||||
return `Guess must contain ${atLeastN}${glyphs}`;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
return undefined;
|
||||
|
|
Loading…
Reference in a new issue