diff --git a/config/default.js b/config/default.js index c871b36..86121ad 100755 --- a/config/default.js +++ b/config/default.js @@ -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, diff --git a/src/games/wordle.js b/src/games/wordle.js index ee6d8b7..abb2258 100644 --- a/src/games/wordle.js +++ b/src/games/wordle.js @@ -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]]);