83 lines
4.8 KiB
Python
83 lines
4.8 KiB
Python
import random
|
|
from collections import defaultdict
|
|
from time import time
|
|
|
|
from lib import ROUNDS, cat_words
|
|
from play import build_letter_hint, build_non_letter_hint
|
|
from solve import round_words, first_round_words, resolve_positions
|
|
|
|
|
|
def main():
|
|
guess_words_d = defaultdict(list)
|
|
guess_distro = defaultdict(int)
|
|
i = 0
|
|
while True:
|
|
i += 1
|
|
start = time()
|
|
word = random.choice([w for w in cat_words()])
|
|
all_non_letters = ''
|
|
all_positional_letters = []
|
|
all_non_positional_letters = []
|
|
guesses = []
|
|
round_words_stats = []
|
|
for round_number in range(ROUNDS+1):
|
|
if round_number == 0:
|
|
if not guess_words_d:
|
|
this_round_words = [w for w in first_round_words()]
|
|
else:
|
|
explore_exploit = random.choices((1, 0), (0.2, 0.8))[0]
|
|
if explore_exploit:
|
|
sorted_distro_w = sorted(guess_words_d.items(), key=lambda x: sum(x[1])/len(x[1]))
|
|
this_round_words = [sorted_distro_w[0][0]]
|
|
else:
|
|
this_round_words = [w for w in first_round_words()]
|
|
else:
|
|
this_round_words = [w for w in
|
|
round_words(all_non_letters, all_positional_letters, all_non_positional_letters)]
|
|
if len(this_round_words) == 0:
|
|
print("ERROR: NO HINTS")
|
|
break
|
|
guess = random.choice(this_round_words)
|
|
guesses.append(guess)
|
|
round_words_stats.append(len(this_round_words))
|
|
|
|
non_letters_hints = build_non_letter_hint(guess, word)
|
|
letters_hints = build_letter_hint(guess, word)
|
|
if all([letter.isupper() for letter in letters_hints]):
|
|
# print("WIN")
|
|
break
|
|
|
|
positional_letters, non_positional_letters, is_good = resolve_positions(letters_hints)
|
|
|
|
all_non_letters += non_letters_hints
|
|
all_positional_letters.append(positional_letters)
|
|
all_non_positional_letters.append(non_positional_letters)
|
|
else:
|
|
# print("LOSE")
|
|
guess_distro[-1] += 1
|
|
delta_t = time() - start
|
|
guess_words_d[guesses[0]].append(len(guesses))
|
|
guess_distro[len(guesses)] += 1
|
|
print("{:5d}: {:2.2f}".format(i, delta_t))
|
|
# print("word : {}".format(word))
|
|
# print("gues_len: {}".format(len(guesses)))
|
|
# print("guesses : {}".format(guesses))
|
|
# print("word_dis: {}".format(["{:5d}".format(s) for s in round_words_stats]))
|
|
if i % 10 == 0:
|
|
print("-" * 80)
|
|
# print("g_dis_w : {}".format(guess_words_d))
|
|
sorted_distro_w = sorted(guess_words_d.items(), key=lambda x: sum(x[1])/len(x[1]))[:10]
|
|
print("g_dis_w : {}".format(sorted_distro_w))
|
|
# print("g_dis : {}".format(guess_distro))
|
|
sorted_distro = sorted(guess_distro.items(), key=lambda x: x[1])
|
|
print("g_dis : {}".format(sorted_distro))
|
|
|
|
# defaultdict(<class 'int'>, {5: 253, 4: 369, 6: 92, 3: 210, 2: 37, 7: 59, -1: 30})
|
|
|
|
# [('flute', [2]), ('ulnae', [2]), ('neath', [2]), ('guile', [2]), ('brave', [2]), ('bulge', [2]), ('lunge', [2]), ('avoid', [2]), ('suing', [2]), ('cased', [2]), ('flesh', [2]), ('boned', [2]), ('query', [2]), ('squat', [2]), ('gazer', [2]), ('crest', [2]), ('moray', [2]), ('nodal', [2]), ('stain', [2]), ('snort', [2]), ('satyr', [2]), ('stage', [2]), ('often', [2]), ('snark', [2]), ('laugh', [2]), ('relay', [2]), ('flown', [2]), ('aping', [2]), ('pious', [2]), ('islet', [2]), ('whorl', [3, 2]), ('bitch', [2, 3]), ('mused', [3, 2, 4]), ('scary', [4, 2]), ('teary', [2, 4]), ('parse', [4, 2, 4]), ('manse', [2, 6]), ('robed', [3]), ('aisle', [3]), ('stare', [3]), ('angry', [3]), ('nixed', [3]), ('clang', [3]), ('avert', [3]), ('wager', [3]), ('bushy', [3]), ('gayer', [3]), ('vouch', [3]), ('spite', [3]), ('fazes', [3]), ('buxom', [3]), ('hound', [3]), ('enrol', [3]), ('pearl', [3]), ('ultra', [3]), ('whine', [3]), ('leach', [3]), ('sheaf', [3]), ('clove', [3]), ('smoke', [3]), ('scant', [3]), ('gamer', [3]), ('after', [3]), ('first', [3]), ('tenor', [3]), ('adult', [3]), ('vowed', [3]), ('gnarl', [3]), ('begin', [3]), ('umiak', [3]), ('spore', [3]), ('strap', [3]), ('right', [3]), ('vista', [3]), ('unbar', [3]), ('dowse', [3]), ('intro', [3]), ('hefty', [3]), ('lover', [3]), ('wormy', [3]), ('fails', [3]), ('vicar', [3]), ('torus', [3]), ('civet', [3]), ('lured', [3]), ('flint', [3]), ('shaft', [3]), ('whelp', [3]), ('oldie', [3]), ('blimp', [3]), ('locus', [3]), ('poxes', [3]), ('flame', [3]), ('beryl', [3]), ('dance', [3]), ('store', [3]), ('pried', [3]), ('awoke', [3]), ('copes', [3]), ('overt', [3...
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|