-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (50 loc) · 1.97 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
import concurrent.futures
from collections import defaultdict
import pguess
from server import Color, Server, RemoteServer
from concurrent.futures import ProcessPoolExecutor
PARALLEL = 10
def run_guess(word, words, possible_words):
server = Server(word)
guesser = pguess.Guess(words, possible_words)
while True:
guess_word = guesser.next_guess
result = server.guess(guess_word)
if result == (Color.GREEN,) * 5:
return guess_word, guesser.guesses
guesser.notify_result(result)
def self_eval(guess_words, possible_words):
total = 0
six_or_less = 0
guess_results = defaultdict(int)
with ProcessPoolExecutor(max_workers=PARALLEL) as executor:
futures = []
for word in possible_words:
futures.append(executor.submit(run_guess, word, guess_words, possible_words))
for future in concurrent.futures.as_completed(futures):
word, guesses = future.result()
total += 1
six_or_less += 1 if guesses <= 6 else 0
print(f"success rate {six_or_less}/{total} - {six_or_less/total*100}%; guessed {word} in {guesses} guesses")
guess_results[guesses] += 1
print(guess_results)
def interactive(guess_words, possible_words):
server = RemoteServer()
guesser = pguess.Guess(guess_words, possible_words)
while True:
guess_word = guesser.next_guess
result = server.guess(guess_word)
if result == (Color.GREEN,) * 5:
return guess_word, guesser.guesses
guesser.notify_result(result)
if __name__ == '__main__':
choice = input("Run test? [N/y] ")
with open("all_valid_guesses.txt") as wordlist:
guess_words = wordlist.read().splitlines()
with open("possible.txt") as possible:
possible_words = possible.read().splitlines()
if choice.lower() == 'y':
self_eval(guess_words, possible_words)
else:
interactive(guess_words, possible_words)