-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordleSolver.py
More file actions
85 lines (78 loc) · 2.43 KB
/
WordleSolver.py
File metadata and controls
85 lines (78 loc) · 2.43 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def get_words(file):
with open(file, 'r')as f:
dict_list = f.readlines()
for index in range(len(dict_list)):
dict_list[index] = dict_list[index][:-1]
return dict_list
def show_words(word_list):
word_per_row = 20
count = 0
for word in word_list:
if count < word_per_row:
print(word, end=' ')
count = count+1
else:
print(word)
count = 0
def start_new_game():
dataset = get_words('dataset.txt')
valid_word_list = dataset
green = ['', '', '', '', '']
yellow = []
black = []
print("=================================")
print("Start a new game, choose a word:")
show_words(valid_word_list)
while(True):
word = ''
result = ''
while len(word) != 5:
word = input('\nYou choose the word: ')
while len(result) != 5:
result = input('Result is (Green:G, Yellow:Y, Black:B):')
if result.upper()=='GGGGG':
break
#print('38')
for index in range(5):
result_char = result[index].upper()
word_char = word[index].upper()
if result_char == 'G':
green[index] = word_char
elif result_char == 'Y':
yellow.append(word_char)
elif result_char == 'B':
black.append(word_char)
else:
print('error')
#print(green)
#print(yellow)
#print(black)
#print()
for index in range(5):
if green[index]!='':
temp = []
for word in valid_word_list:
if word[index].upper()==green[index]:
temp.append(word)
valid_word_list = temp
#print(valid_word_list)
for char in yellow:
temp = []
for word in valid_word_list:
if char in word.upper():
temp.append(word)
valid_word_list = temp
#print(valid_word_list)
for char in black:
temp = []
for word in valid_word_list:
if char not in word.upper():
temp.append(word)
valid_word_list = temp
print("Avalible words are:")
show_words(valid_word_list)
if __name__=="__main__":
while(True):
start_new_game()
import os
os.system("PAUSE")