Improved repeat letter marking in wordle.

This commit is contained in:
ThePendulum 2024-06-04 23:56:51 +02:00
parent 055440418e
commit 13e0bb9a8c
2 changed files with 16 additions and 10 deletions

View File

@ -137,7 +137,6 @@ module.exports = {
wordle: {
minLength: 3,
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: {
length: 6,

View File

@ -118,29 +118,36 @@ function play(guess, context) {
}
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 alreadySeen = settings.highlightRepeat ? false : processed.has(letter);
processed.add(letter);
const guessLetters = upperGuess.split('');
const check = guessLetters.map((letter) => [letter, null]);
// correct
guessLetters.forEach((letter, index) => {
if (wordle.word[index] === letter) {
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.letters.get(letter) !== true) {
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);
return [letter, null];
});
wordle.guesses = wordle.guesses.concat([[context.user.username, upperGuess]]);