kopia lustrzana https://github.com/lynn/hello-wordl
Ultra Hard: enforce letter counts even without absent clues
For example, with a target word of RALLY ([challenge link]), guessing LEVEL gives [elsewhere, absent, absent, absent, elsewhere]. This commit makes guessing WORLD afterwards a violation, as there must be at least two Ls in the target word. This commit also makes it clearer that, when there is an absent clue, the count of the letter must be exactly (number of non-absent clues with that letter). [challenge link]: https://hellowordl.net/?challenge=cmFsbHkpull/55/head
rodzic
e9a29122c9
commit
5511a4fcdf
38
src/clue.ts
38
src/clue.ts
|
@ -70,19 +70,7 @@ export function violation(
|
|||
for (const { letter, clue } of clues) {
|
||||
const upper = letter.toUpperCase();
|
||||
const nth = ordinal(i + 1);
|
||||
if (clue === Clue.Absent) {
|
||||
if (difficulty === Difficulty.UltraHard) {
|
||||
const max = clues.filter(
|
||||
(c) => c.letter === letter && c.clue !== Clue.Absent
|
||||
).length;
|
||||
const count = guess.split(letter).length - 1;
|
||||
if (count > max) {
|
||||
const amount = max ? `more than ${englishNumbers[max]} ` : "";
|
||||
const s = max > 1 ? "s" : "";
|
||||
return `Guess can't contain ${amount}${upper}${s}`;
|
||||
}
|
||||
}
|
||||
} else if (clue === Clue.Correct) {
|
||||
if (clue === Clue.Correct) {
|
||||
if (guess[i] !== letter) {
|
||||
return nth + " letter must be " + upper;
|
||||
}
|
||||
|
@ -93,6 +81,30 @@ export function violation(
|
|||
return nth + " letter can't be " + upper;
|
||||
}
|
||||
}
|
||||
if (difficulty === Difficulty.UltraHard) {
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return undefined;
|
||||
|
|
Ładowanie…
Reference in New Issue