Merge branch 'master' of git.pi2.dev:daniel/wordle

This commit is contained in:
Daniel Tsvetkov 2022-01-19 13:12:41 +01:00
commit 98dcab943a
2 changed files with 15 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,8 +5,9 @@ from lib import cat_words, INSTRUCTIONS, BLANK, ROUNDS, DEBUG, DICTIONARY
def remove_non_letters(word, non_letters, unconsumed_letters, non_pos_unconsumed_letters):
for non_letter in non_letters:
if non_letter in word and non_letter in unconsumed_letters and non_letter in non_pos_unconsumed_letters:
return True
if non_letter in word:
if non_letter in unconsumed_letters or non_letter in non_pos_unconsumed_letters:
return True
return False
@ -23,17 +24,19 @@ def remove_positional_letters(word, positional_letters):
return rv, unconsumed_letters
def remove_non_positional_letters(word, non_positional_letters):
rv, unconsumed_letters = False, ''
def remove_non_positional_letters(word, non_positional_letters, unconsumed_letters):
rv, non_pos_unconsumed_letters = False, ''
for non_pos_idx, non_positional_letter in enumerate(non_positional_letters):
if non_positional_letter == BLANK:
continue
unconsumed_letters += word[non_pos_idx]
non_pos_unconsumed_letters += word[non_pos_idx]
if non_positional_letter in unconsumed_letters:
unconsumed_letters = unconsumed_letters.replace(non_positional_letter, '', 1)
if non_positional_letter not in word:
rv = True
elif word[non_pos_idx] == non_positional_letter:
rv = True
return rv, unconsumed_letters
return rv, non_pos_unconsumed_letters, unconsumed_letters
def round_words(non_letters, all_positional_letters, all_non_positional_letters, dictionary=DICTIONARY):
@ -48,7 +51,8 @@ def round_words(non_letters, all_positional_letters, all_non_positional_letters,
continue
# Find non-positional letters, e.g. h-s--
for non_positional_letters in all_non_positional_letters:
skip, non_pos_unconsumed_letters = remove_non_positional_letters(word, non_positional_letters)
skip, non_pos_unconsumed_letters, unconsumed_letters = remove_non_positional_letters(
word, non_positional_letters, unconsumed_letters)
if skip:
break
if skip:
@ -157,6 +161,7 @@ def do_test():
assert [w for w in round_words('', ['towns'], ['-----'], dictionary=['towns'])] == ['towns']
assert [w for w in round_words('', ['-----'], ['stown'], dictionary=['towns'])] == ['towns']
assert [w for w in round_words('', ['----y'], ['-----'], dictionary=['slily'])] == ['slily']
assert [w for w in round_words('', ['-----'], ['yy---'], dictionary=['slyly'])] == ['slyly']
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']
@ -164,6 +169,7 @@ def do_test():
assert [w for w in round_words('', ['--b-y'], ['ab---'], dictionary=['cabby'])] == ['cabby']
assert [w for w in round_words('', ['--b-y'], ['-a-b-'], dictionary=['abbey'])] == ['abbey']
assert [w for w in round_words('nu', ['-o-ns'], ['-----'], dictionary=['towns'])] == ['towns'] # nouns
assert [w for w in round_words('r', ['p-int'], ['-----'], dictionary=['print', 'point'])] == ['point']
assert [w for w in round_words('fos', ['-l---'], ['---s-'], dictionary=['slung'])] == ['slung'] # typed basil floss