Hello. This photo was taken when I actually played Wordle.
The answer at this time was "ULTRA".
In this case, the second letter A of "MAMMA" seems to be judged as gray.
Similarly, for example, when the answer is ROBIN and WORRY is entered, the fourth R seems to be a gray judgment.
I forked your project and tried to write a code like this.
so,I checked green and yellow in order and tried to remove the hit words.
class Wordle:
"""Main Wordle game taking arguments of the answer and whether to check against the dictionary."""
def __init__(self, word: str, real_words: bool):
self.word = word.upper()
self.real_words = real_words
def response(self, guess: str):
response = []
answer = [c for c in self.word]
guess = [c for c in guess]
# correct(green) check
for pos, char in enumerate(guess):
if answer[pos] == char:
# append hint
hint = f"*{guess[pos]}* "
response.append({'pos': pos, 'hint': hint})
# remove char
answer[pos] = ''
guess[pos] = ''
# present(yellow) check
for pos, char in enumerate(guess):
if not char:
continue
if char in answer:
hint = char + " "
response.append({'pos': pos, 'hint': hint})
# remove char
guess[pos] = ''
for _pos, _char in enumerate(answer):
if _char == char:
answer[_pos] = ''
break
# remains all absent(gray)
for pos, char in enumerate(guess):
if not char:
continue
hint = guess[pos].lower() + " "
response.append({'pos': pos, 'hint': hint})
# sort by pos
response.sort(key=lambda x: x['pos'])
return [r['hint'] for r in response]
...
import wordle
game = wordle.Wordle(word='WRYYY', real_words=False)
game.run()
>>>
Attempt 1 >>> yyaaa
Y Y a a a
Attempt 2 >>> rrryy
r *R* r *Y* *Y*
Attempt 3 >>> yyyaa
Y Y *Y* a a
Attempt 4 >>> yyayy
Y y a *Y* *Y*
Attempt 5 >>> wryyy
*W* *R* *Y* *Y* *Y*
Congratulations, you passed the wordle in 5 tries.