play_solve

This commit is contained in:
Daniel Tsvetkov 2022-01-18 19:36:57 +01:00
parent 387fd7f2f0
commit 18e9c6a151
2 changed files with 8 additions and 4 deletions

11
play.py
View File

@ -22,6 +22,12 @@ def build_letter_hint(guess, word):
word_break[first_index] = BLANK
return ''.join(letters_hints)
def build_non_letter_hint(guess, word):
non_letters_hints = ''
for letter in guess:
if letter not in word and letter not in non_letters_hints:
non_letters_hints += letter
return non_letters_hints
def main_loop():
word = random.choice([w for w in cat_words()])
@ -31,10 +37,7 @@ def main_loop():
guess = input("Guess: ")
if len(guess) != 5 and not all([x.islower() for x in guess]):
print("ERROR: {}".format(PLAY_INSTRUCTIONS))
non_letters_hints = ''
for letter in guess:
if letter not in word and letter not in non_letters_hints:
non_letters_hints += letter
non_letters_hints = build_non_letter_hint(guess, word)
letters_hints = build_letter_hint(guess, word)
print("Non-letters: {}".format(non_letters_hints))
print("Letters: {}".format(letters_hints))

View File

@ -147,6 +147,7 @@ def test():
assert [w for w in round_words('', ['----y'], ['y----'], dictionary=['slyly'])] == ['slyly']
assert [w for w in round_words('', ['---yy'], ['y----'], dictionary=['slyyy'])] == ['slyyy']
assert [w for w in round_words('', ['---yy'], ['-----'], dictionary=['slyyy'])] == ['slyyy']
assert [w for w in round_words('', ['-y---'], ['--y--'], dictionary=['sysys'])] == ['sysys']
def main():