mirror of
https://github.com/ltcptgeneral/cse151b-final-project.git
synced 2025-09-09 16:57:21 +00:00
still doesnt train
This commit is contained in:
15
wordle_gym/envs/strategies/base.py
Normal file
15
wordle_gym/envs/strategies/base.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from enum import Enum
|
||||
|
||||
from typing import List
|
||||
|
||||
class StrategyType(Enum):
|
||||
RANDOM = 1
|
||||
ELIMINATION = 2
|
||||
PROBABILITY = 3
|
||||
|
||||
class Strategy:
|
||||
def __init__(self, type: StrategyType):
|
||||
self.type = type
|
||||
|
||||
def get_best_word(self, guesses: List[List[str]], state: List[List[int]]):
|
||||
raise NotImplementedError("Strategy.get_best_word() not implemented")
|
2
wordle_gym/envs/strategies/elimination.py
Normal file
2
wordle_gym/envs/strategies/elimination.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def get_best_word(state):
|
||||
|
20
wordle_gym/envs/strategies/probabilistic.py
Normal file
20
wordle_gym/envs/strategies/probabilistic.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from random import sample
|
||||
from typing import List
|
||||
|
||||
from base import Strategy
|
||||
from base import StrategyType
|
||||
|
||||
from utils import freq
|
||||
|
||||
class Random(Strategy):
|
||||
def __init__(self):
|
||||
self.words = freq.get_5_letter_word_freqs()
|
||||
super().__init__(StrategyType.RANDOM)
|
||||
|
||||
def get_best_word(self, state: List[List[int]]):
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
r = Random()
|
||||
print(r.get_best_word([]))
|
29
wordle_gym/envs/strategies/rand.py
Normal file
29
wordle_gym/envs/strategies/rand.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from random import sample
|
||||
from typing import List
|
||||
|
||||
from base import Strategy
|
||||
from base import StrategyType
|
||||
|
||||
from utils import freq
|
||||
|
||||
class Random(Strategy):
|
||||
def __init__(self):
|
||||
self.words = freq.get_5_letter_word_freqs()
|
||||
super().__init__(StrategyType.RANDOM)
|
||||
|
||||
def get_best_word(self, guesses: List[List[str]], state: List[List[int]]):
|
||||
correct_letters = []
|
||||
regex = ""
|
||||
for g, s in zip(guesses, state):
|
||||
for c, s in zip(g, s):
|
||||
if s == 2:
|
||||
correct_letters.append(c)
|
||||
regex += c
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
r = Random()
|
||||
print(r.get_best_word([]))
|
27
wordle_gym/envs/strategies/utils/freq.py
Normal file
27
wordle_gym/envs/strategies/utils/freq.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from os import path
|
||||
|
||||
def get_5_letter_word_freqs():
|
||||
"""
|
||||
Returns a list of words with 5 letters.
|
||||
"""
|
||||
FILEPATH = path.join(path.dirname(path.abspath(__file__)), "data/norvig.txt")
|
||||
lines = read_file(FILEPATH)
|
||||
return {k:v for k, v in get_freq(lines).items() if len(k) == 5}
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
"""
|
||||
Reads a file and returns a list of words and frequencies
|
||||
"""
|
||||
with open(filename, 'r') as f:
|
||||
return f.readlines()
|
||||
|
||||
|
||||
def get_freq(lines):
|
||||
"""
|
||||
Returns a dictionary of words and their frequencies
|
||||
"""
|
||||
freqs = {}
|
||||
for word, freq in map(lambda x: x.split("\t"), lines):
|
||||
freqs[word] = int(freq)
|
||||
return freqs
|
Reference in New Issue
Block a user