Clone of the famous Wordle game built with Mavo.
The incomplete quotient of a letter index
(inside the collection of used letters) and 5
(the length of a guess) is the answer: floor($index / 5)
. E.g., a letter with $index = 13
belongs to the third guess (guesses are numbered starting from 0) since floor(13 / 5) = 2
.
-
We begin coloring letters after the first guess is committed (from the second attempt), i.e., the corresponding letters belong to the previous guesses:
row < attempt - 1
, whererow = floor($index / 5)
. -
If a letter matches the corresponding letter of the hidden word, it's marked as
correct
(and colored green):get(hiddenWordLetters, $index mod 5) = letter
. -
A letter that is among letters of the hidden word is marked as
elsewhere
(and colored yellow) unless it's only one in the hidden word (i) and is already in the right spot in the corresponding guess (ii):count(filter(hiddenWordLetters, hiddenWordLetters != letter)) = 4
letter in filter(hiddenWordLetters, hiddenWordLetters = thisRowLetters)
-
In all other cases, a letter is marked as
absent
(and colored dark gray). -
1 + 2 + 3 + 4:
if(row < attempt - 1, if(get(hiddenWordLetters, $index mod 5) = letter, correct, if(letter in hiddenWordLetters, if(letter in filter(hiddenWordLetters, hiddenWordLetters = thisRowLetters) and count(filter(hiddenWordLetters, hiddenWordLetters != letter)) = 4, absent, elsewhere), absent)))
By hitting the Delete button, we expect to delete letters only from the current guess, not the previous ones:
deleteif(guessLength > 0, last(game.usedLetters))
We allow constructing guesses not more than 5 characters long:
if(guessLength < 5, add(group('letter': key), usedLetters) & add(key, guessLetters))
-
We begin coloring the keyboard after the first guess is committed:
attempt > 1
. -
To be colored, the
key
has to be among characters of any previous guess:
contains(join(guesses), key)
- If the
key
is among previously correctly guessed letters, it's marked ascorrect
(and colored green). Else if the hidden word contains thekey
, thekey
is marked aselsewhere
(and colored yellow). Otherwise, it's marked asabsent
(and colored dark gray):
if(key in correctLetters, correct, if(contains(hiddenWord, key), elsewhere, absent))
- 1 + 2 + 3:
if(attempt > 1, if(contains(join(guesses), key), if(key in correctLetters, correct, if(contains(hiddenWord, key), elsewhere, absent))))
- The user wins the game if the guess (5 letters word) matches the hidden word:
guessLength = 5 and guess = hiddenWord
- The user loses the game if they have used their last (the 6th) attempt and the guess (valid 5 letters word) doesn't match the hidden word:
guessLength = 5 and attempt = 6 and guessValid and guess != hiddenWord