A word guessing puzzle game. Find the secret 5-letter word in 6 tries using visual feedback.
When you submit a guess, coloring the boxes Green (correct letter, correct spot), Yellow (correct letter, wrong spot), or Gray (wrong letter) seems simple. But a naive implementation will have severe bugs when it comes to duplicate letters.
Imagine the secret word is APPLE and you guess PAPER.
A naive algorithm loops through your guess one letter at a time:
Wait, the secret word only has two P's, but the algorithm just colored both of your P's (one Yellow, one Green), and might even color a third if you guessed PPPPP. This gives the player incorrect information about the word's letter counts.
To fix this, the game uses a Two-Pass Evaluation Algorithm:
Why does the evaluation algorithm require two separate passes instead of just one?