This doesn't handle Yellow result correctly. Specifically, if there is a repeated letter in the guess but that letter appears once in the actual word, then the second occurrence will get a Black instead of a Yellow.
In other words, a Yellow result doesn't just mean that letter occurs somewhere. A Black also doesn't mean the letter occurs nowhere.
There seems to be a lot of confusion and different opinions around how repeated letters should be treated; we really need FIDW (Fédération Internationale de Wordle) to make a definitive ruling.
It depends on how you look at it. Wordle is just an online implementation of the game "Lingo", after all. You could argue that Lingo is a letter implementation of Mastermind.
When building a new word grid game, would you take Wordfeud's rules over Scravble's? I don't think I would.
I see your point. But calling it a "Wordle clone" implies it follows the same rules. If you want to change the rules, call it "inspired by Wordle" or something similar.
I used to have exactly this bug in my revolt Wordle chatbot. It's especially annoying when one of the duplicates is in the correct position but get's marked as BLACK since a previous repeat has been marked YELLOW.
(I don't think this can be classed as correct behavior)
Here is one way to fix it (but it will push you over 50 lines!)
remaining="" output=""
for ((i = 0; i < ${#actual}; i++)); do
if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then
remaining+=${actual:$i:1}
fi
done
for ((i = 0; i < ${#actual}; i++)); do
if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then
if [[ "$remaining" == *"${guess:$i:1}"* ]]; then
output+="\033[30;103m ${guess:$i:1} \033[0m"
remaining=${remaining/"${guess:$i:1}"/}
else
output+="\033[30;107m ${guess:$i:1} \033[0m"
fi
else
output+="\033[30;102m ${guess:$i:1} \033[0m"
fi
done
printf "$output\n"
Explanation:
The variable `remaining` tracks the letters of `actual` that can contribute toward yellows.
That isn't a bug. In the original if a guess contains a repeated letter and there is only one occurrence of that letter in the target work then the first (on the left) letter will be yellow and the second black.
You can see this with today's word by guessing MOTTO. The leftmost T will be yellow and the rightmost will be black.
Similarly, if you guess TENET the initial T is black but the final T is green.
In other words, a Yellow result doesn't just mean that letter occurs somewhere. A Black also doesn't mean the letter occurs nowhere.