-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordleEntry.py
59 lines (51 loc) · 2.42 KB
/
WordleEntry.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
from words import possible_words
all_letters_list = list("abcdefghijklmnopqrstuvwxyz")
def check_if_word_fits(possible_word: str, row_letter_matrix: list):
for index, letter in enumerate(possible_word):
if letter not in row_letter_matrix[index]:
return False
return True
class WordleEntry:
def __init__(self, word_of_the_day_matrix, emoji_matrix):
self.word_of_the_day_matrix = word_of_the_day_matrix
self.emoji_matrix = emoji_matrix
self.entry_matrix = None
self.possible_first_words = self.get_possible_first_words()
def get_list_of_possible_yellow_letters(self, index: int) -> list:
possible_letters = self.word_of_the_day_matrix.copy()
corresponding_letter = self.word_of_the_day_matrix[index]
possible_letters.remove(corresponding_letter)
return possible_letters
def get_possible_letter_matrix(self) -> list:
possible_letter_matrix = []
letter_list = []
for row in self.emoji_matrix:
for letter_index, emoji in enumerate(row):
if emoji == "🟩":
corresponding_letter_of_the_day = [self.word_of_the_day_matrix[letter_index]]
letter_list.append(corresponding_letter_of_the_day)
elif emoji == "🟨":
possible_letters = self.get_list_of_possible_yellow_letters(letter_index)
letter_list.append(possible_letters)
elif emoji == "⬛":
possible_letters = all_letters_list.copy()
for letter in self.word_of_the_day_matrix: # since the emoji is black, we know none of the letters in the word of the day can be in these slots
if letter in possible_letters:
possible_letters.remove(letter)
letter_list.append(possible_letters)
possible_letter_matrix.append(letter_list)
letter_list = []
return possible_letter_matrix
def find_possible_words(self, row_letter_matrix: list):
"""
Builds a list of possible words based on the row_letter_matrix
Example: if we know the first letter can only be ['n', 'y'], then all words that don't match this are removed from possible_words
"""
good_possible_words = []
for possible_word in possible_words: # loop over each possible word to see if it fits the criteria of the row_letter_matrix
if check_if_word_fits(possible_word=possible_word, row_letter_matrix=row_letter_matrix) == True:
good_possible_words.append(possible_word)
return good_possible_words
def get_possible_first_words(self):
possible_letter_matrix = self.get_possible_letter_matrix()
return self.find_possible_words(possible_letter_matrix[0])