-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordlealgorithm.py
More file actions
62 lines (48 loc) · 1.66 KB
/
wordlealgorithm.py
File metadata and controls
62 lines (48 loc) · 1.66 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
from abc import ABC, abstractmethod
from typing import List
from string import Template
from gameinfo import (
Letter,
RejectedLetter,
AcceptedLetterWrongPosition,
AcceptedLetterCorrectPosition,
filter_impossible_words,
)
import pandas as pd
class IncorrectWordError:
"Should be raised when incorrect word was"
class WordleAlgorithm(ABC):
"""
Abstract base class for an wordle algorithm.
Should be able to make a guess based on words possible and information gained.
"""
def __init__(self, possible_words: pd.DataFrame) -> None:
self.possible_words = possible_words
@abstractmethod
def guess(self, info: List[Letter]) -> str:
"Makes a guess"
pass
@abstractmethod
def rank_guesses(self, info: List[Letter]) -> pd.DataFrame:
"Ranks all possible words."
pass
class ManualAlgorithm(WordleAlgorithm):
def __init__(self, possible_words: pd.DataFrame) -> None:
super().__init__(possible_words)
self.print_instruction()
def guess(self, info: List[Letter]) -> str:
return input().strip().lower()
def rank_guesses(self, info: List[Letter]) -> pd.DataFrame:
return filter_impossible_words(self.possible_words, info)
def print_instruction(self):
with open("./player_instruction.txt") as f:
instruction = f.read()
instruction = Template(instruction).substitute(
{
"a": RejectedLetter("а"),
"b": AcceptedLetterWrongPosition("б"),
"c": AcceptedLetterCorrectPosition("в"),
}
)
print(instruction)
input("Press Enter to start!")