@@ -43,6 +43,19 @@ def enter_word(word):
43
43
time .sleep (2 )
44
44
45
45
46
+ def create_regex (solving_string , present_letters ):
47
+ regex = ""
48
+ for letter in range (len (solving_string )):
49
+ if solving_string [letter ] == "*" :
50
+ regex += "[a-z]"
51
+ elif solving_string [letter ] == "_" :
52
+ regex += \
53
+ "[^" + str (list (present_letters )).replace ("'" , "" ).replace ("," , "" ).replace ("[" , "" ).replace (" " , "" )
54
+ else :
55
+ regex += "[" + solving_string [letter ] + "]"
56
+ return regex
57
+
58
+
46
59
# Check word length
47
60
def check_word_length (word ):
48
61
if len (word ) != 5 :
@@ -77,53 +90,59 @@ def get_list_of_words():
77
90
# letters_not_in_response, is a list which keeps track of the allowed letters
78
91
# letter_not_in_position, is a list which keeps track of the letters in bad position
79
92
# For exemple, "A_A_*A", letters_not_in_response = ['B'], letter_not_in_position = ['K'].
80
- def solving_algorithm (word , res ):
93
+ def solving_algorithm (word , res , list_of_words , present_letters , absent_letters ):
81
94
print ("solving_algorithm start" )
82
95
83
- list_of_words = get_list_of_words ()
84
- absent_letters = set ([])
85
- present_letters = set ([])
86
-
87
- solution = "tbest" # developpement solution
88
96
solving_string = "*****"
89
97
90
98
for letter in range (len (word )):
91
99
print ("letter : " , word [letter ])
92
100
if res [letter ] == 1 : # Case when the status of the letter is "correct"
93
- print ("letters in the right position : " , solution [letter ])
94
- print ("GREATOOOOO" )
101
+ print ("the letter is correct" )
95
102
solving_string = solving_string [:letter ] + word [letter ] + solving_string [letter + 1 :]
96
- elif res [letter ] == 0 : # status is present
103
+ if word [letter ] in present_letters :
104
+ present_letters .remove (word [letter ])
105
+ elif res [letter ] == 0 : # Case when the status of the letter is "present" (present but at the wrong position)
97
106
print ("the letter is present" )
98
107
solving_string = solving_string [:letter ] + "_" + solving_string [letter + 1 :]
99
108
present_letters .add (word [letter ])
100
- else : # status is absent
109
+ else : # Case when the status of the letter is " absent"
101
110
print ("the letter is absent" )
102
- absent_letters .add (word [letter ]) # Case when the status of the letter is 'absent'
103
- solving_string = solving_string [:letter ] + "*" + solving_string [letter + 1 :]
111
+ if word [letter ] not in present_letters :
112
+ absent_letters .add (word [letter ])
113
+ solving_string = solving_string [:letter ] + "*" + solving_string [letter + 1 :]
104
114
105
- print ("Update list of word " )
115
+ print ("Update list of words " )
106
116
print ("length of list" , len (list_of_words ))
107
117
108
118
# Update list of words
109
- buffer_list = []
110
-
111
119
for absent in absent_letters :
112
120
print (absent )
113
- list_of_words = list (filter (check_letter_in_word (absent ), list_of_words ))
121
+ list_of_words = list (filter (lambda x_word : not check_letter_in_word (absent , x_word ), list_of_words ))
122
+ for present in present_letters :
123
+ print (present )
124
+ list_of_words = list (filter (lambda x_word : check_letter_in_word (present , x_word ), list_of_words ))
114
125
115
126
print ("letter not in the right position : " , present_letters )
127
+ print (create_regex (solving_string , present_letters ))
116
128
print ("Letters with absent status" , absent_letters )
117
129
print ("solving string :" , solving_string )
118
- # print(list_of_words)
130
+ print ("list of words : " , list_of_words )
119
131
print ("length of list" , len (list_of_words ))
120
132
133
+ return list_of_words
134
+
121
135
122
136
def main ():
123
137
# Start the browser
124
138
browser = webdriver .Firefox (service = FirefoxService (GeckoDriverManager ().install ()))
125
139
browser .get ("https://www.nytimes.com/games/wordle/index.html" )
126
140
141
+ list_of_words = get_list_of_words ()
142
+ absent_letters = set ([])
143
+ present_letters = set ([])
144
+ guesses_left = 2
145
+
127
146
# Wait for start
128
147
with keyboard .Listener (on_release = on_release , suppress = True ) as listener :
129
148
print ("Starting" )
@@ -139,13 +158,16 @@ def main():
139
158
first_string = "tests"
140
159
enter_word (first_string )
141
160
res = get_row_results (game_rows [0 ])
142
- # solving_algorithm(first_string, res)
161
+ list_of_words = solving_algorithm (first_string , res , list_of_words , present_letters , absent_letters )
162
+ guesses_left -= 1
143
163
144
164
time .sleep (1 )
145
165
146
- second_string = "trees"
147
- enter_word (second_string )
148
- get_row_results (game_rows [1 ])
166
+ for i in range (guesses_left , 0 , - 1 ):
167
+ enter_word (list_of_words [0 ])
168
+ res = get_row_results (game_rows [i ])
169
+ solving_algorithm (list_of_words [0 ], res , list_of_words , present_letters , absent_letters )
170
+ time .sleep (1 )
149
171
150
172
151
173
if __name__ == "__main__" :
0 commit comments