Improved repeat letter marking in wordle.
This commit is contained in:
parent
055440418e
commit
13e0bb9a8c
|
@ -137,7 +137,6 @@ module.exports = {
|
||||||
wordle: {
|
wordle: {
|
||||||
minLength: 3,
|
minLength: 3,
|
||||||
defaultLength: 5,
|
defaultLength: 5,
|
||||||
highlightRepeat: false, // in wordle, if the I in the guess HINDI is in the wrong place, only the first I is orange
|
|
||||||
},
|
},
|
||||||
numbers: {
|
numbers: {
|
||||||
length: 6,
|
length: 6,
|
||||||
|
|
|
@ -118,29 +118,36 @@ function play(guess, context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const upperGuess = guess.toUpperCase();
|
const upperGuess = guess.toUpperCase();
|
||||||
const processed = new Set();
|
const occurrences = wordle.word.split('').reduce((acc, letter) => acc.set(letter, (acc.get(letter) || 0) + 1), new Map());
|
||||||
|
|
||||||
const check = upperGuess.split('').map((letter, index) => {
|
const guessLetters = upperGuess.split('');
|
||||||
const alreadySeen = settings.highlightRepeat ? false : processed.has(letter);
|
const check = guessLetters.map((letter) => [letter, null]);
|
||||||
|
|
||||||
processed.add(letter);
|
|
||||||
|
|
||||||
|
// correct
|
||||||
|
guessLetters.forEach((letter, index) => {
|
||||||
if (wordle.word[index] === letter) {
|
if (wordle.word[index] === letter) {
|
||||||
wordle.letters.set(letter, true);
|
wordle.letters.set(letter, true);
|
||||||
return [letter, true];
|
check[index] = [letter, true];
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// wrong place
|
||||||
|
guessLetters.forEach((letter, index) => {
|
||||||
if (wordle.word.includes(letter)) {
|
if (wordle.word.includes(letter)) {
|
||||||
if (wordle.letters.get(letter) !== true) {
|
if (wordle.letters.get(letter) !== true) {
|
||||||
wordle.letters.set(letter, false);
|
wordle.letters.set(letter, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [letter, alreadySeen ? null : false]; // repeating letter in the wrong place is not highlighted
|
const marks = check.filter(([checkLetter, status]) => checkLetter === letter && status !== null).length;
|
||||||
|
|
||||||
|
if (check[index][1] !== true && marks < occurrences.get(letter)) {
|
||||||
|
check[index] = [letter, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wordle.letters.delete(letter);
|
wordle.letters.delete(letter);
|
||||||
|
|
||||||
return [letter, null];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
wordle.guesses = wordle.guesses.concat([[context.user.username, upperGuess]]);
|
wordle.guesses = wordle.guesses.concat([[context.user.username, upperGuess]]);
|
||||||
|
|
Loading…
Reference in New Issue