-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay_game.py
70 lines (56 loc) · 1.78 KB
/
play_game.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
65
66
67
68
69
70
import sys
from tqdm import tqdm
from board import Board, Row
from colouring import States, colouring
from guessing import calc_openings
def prGreen(skk):
return "\033[92m {}\033[00m".format(skk)
def prYellow(skk):
return "\033[93m {}\033[00m".format(skk)
def prBlack(skk):
return "\033[98m {}\033[00m".format(skk)
def playGame(target: str) -> int:
target = target.lower()
score = 0
guesses = 0
coloredGuesses = ""
notSolved = True
words, scores = calc_openings()
board = Board([], words)
while guesses < 6 and notSolved:
currGuess = words[-1]
currState = colouring(currGuess, target)
correctLetters = 0
for i in range(5):
if currState[i] == States.Correct:
coloredGuesses += prGreen(currGuess[i])
correctLetters += 1
if correctLetters == 5:
notSolved = False
elif currState[i] == States.Present:
coloredGuesses += prYellow(currGuess[i])
else:
coloredGuesses += prBlack(currGuess[i])
guesses += 1
score += 1
coloredGuesses += "\n"
print(coloredGuesses)
row = Row.from_states(currState, currGuess)
board = board.add_row(row)
words, scores = board.scan_words()
if notSolved:
return 0
else:
return score
if __name__ == "__main__":
file = open("./data/wordle-answers-alphabetical.txt", "r")
lines = file.readlines()
# totalScores = 0
# # for i in tqdm(range(len(lines))):
# for i in range(len(lines)):
# word = lines[i].strip("\n")
# res = playGame(word)
# totalScores += res
# print("average score is: " + (totalScores / len(lines)))
word = "chant"
playGame(word)