forked from Kinkelin/WordleCompetition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordleJudge.py
30 lines (26 loc) · 1.15 KB
/
WordleJudge.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
from WordList import WordList
allwords="data/official/combined_wordlist.txt"
shuffled_words="data/official/shuffled_real_wordles.txt"
# allwords="data/Español/cinco.txt"
# shuffled_words="data/Español/cinco_random.txt"
class WordleJudge:
"""
Helper class to take into account how common words are in the English language.
"""
def __init__(self, words=WordList(allwords).words,
common_words=WordList("data/other/common_words.txt").words):
self.common_words = common_words
self.probability = {}
for word in words:
self.probability[word] = self.__calculate_probability(word)
def __calculate_probability(self, word):
if word not in self.common_words:
return 368 / (368 + 8890)
relative_position = self.common_words.index(word) / len(self.common_words)
return 0.85 * (1 - relative_position) + 0.35 * relative_position
def is_wordle_probability(self, word):
"""
:param word: a 5 letter word
:return: the probability of the word being a wordle based on its popularity in the English language
"""
return self.probability[word]