API: Classes
- class wordle_boss.Solver(word_list: list[str], guess_list: list[str] | None = None)
Python object type providing much of Wordle Boss’s functionality.
See Basic Usage for example of usage.
- Parameters:
word_list (list[str]) – List containing all the words that the
Solverinstance will consider to be possible target words.guess_list (list[str] or None) – (Optional) List containing all the words that the
Solverinstance will consider to be legal guesses. If it isNoneor not provided,word_listwill be used for the list of guesses.
Neither of these two word lists can be changed after the object is created.
- Raises:
ValueError – if either of the provided lists contains an element other than a valid word, or is provided but empty.
- add_guess(guess: str, feedback: Sequence[int], /) None
Add a guess to
self.This guess, and the provided feedback for it, will be taken into account in all future calls to any of
self’s methods unless it is removed usingremove_guess().- Parameters:
guess (str) – String to add as guess.
feedback (Sequence[int]) – Sequence of
Nfeedback values.
- Raises:
ValueError – if
guessis not a valid word, or iffeedbackis not of the correct type.RuntimeError – if
guesshas already been added toself.
- best_guess(hard_mode: bool = False, absurdle_target: str | None = None) str
Get the best possible next guess according to the MINIMAX Algorithm.
- Parameters:
hard_mode (bool) – If
True, the returned guess will be consistent with all the guesses and feedback added so far toself. DefaultFalse. See Wordle Hard Mode.absurdle_target (str or None) – (Optional) Desired target word in Absurdle Challenge Mode. Must be a possible target word. If not
None, the returned guess will be “safe”; it will not eliminateabsurdle_targetif guessed.
- Returns:
Best guess according to the MINIMAX Algorithm that follows the restrictions of the two parameters. Exception: if there is only one target word remaining according to
get_possibilities(), that word will be returned regardless of the parameter values. Otherwise, the returned word is always an element of the guess list used when creatingself.- Return type:
- Raises:
ValueError – if
absurdle_targetis provided but is not a valid word, or is not one of the words returned byget_possibilities().RuntimeError – if there are no possible target words remaining.
RuntimeError – if
hard_modeisTruebut all the elements ofself’s guess list are eliminated by guesses.RuntimeError – if
absurdle_targetis provided but all possible guesses would eliminate it.
- get_guesses() list[tuple[str, list[int]]]
Return all the guesses added so far to
self.Each element of the returned list is a 2-tuple containing a guess that has been added to
selfand the feedback for that guess.Guesses are returned in the order in which they were added.
Example:
>>> s.add_guess("STARE", [0, 0, 0, 1, 1]) >>> s.add_guess("DOING", [0, 0, 0, 0, 0]) >>> s.get_guesses() [('STARE', [0, 0, 0, 1, 1]), ('DOING', [0, 0, 0, 0, 0])]
- get_min_feedback(guess: str, /) tuple[list[int], int]
Get the most “disappointing” possible feedback for the given guess.
That is, find the feedback for the guess that would eliminate the fewest possible words from the list of possibilities (the list that would be returned by
get_possibilities().) See Absurdle. Return this and the number of possible target words that the feedback would leave.- Parameters:
guess (str) – Word to analyze.
- Returns:
Tuple containing a list of integers (feedback values) representing the most disappointing possible feedback for
guess, and the number of possibilities that the feedback would leave.- Return type:
- Raises:
ValueError – if
guessis not a valid word.RuntimeError – if there are no possible target words remaining.
Note
This method uses a special algorithm to break ties between two or more responses that would leave the same number of target words. To be as useful as possible for playing Absurdle, it attempts to break ties exactly the way Absurdle does; however, it is not clear exactly what method Absurdle uses. This method generally approximates it fairly well, but may fail sometimes.
- is_word_possible(word: str, /) bool
Determine if a word could be the target word for
self.- Parameters:
word (str) – Word to test against
self’s guesses.- Returns:
Trueifwordis consistent with the guesses and feedback added toself, otherwiseFalse.- Return type:
- Raises:
ValueError – if
wordis not a valid word.
- remove_guess(guess: str | None = None, /) None
Remove a guess, or all guesses, previously added to
self.Removed guesses are no longer taken into account in any calls to
self’s methods.- Parameters:
guess (str or None) – (Optional) Guess to remove from
self. If it isNoneor not provided, all guesses will be removed.- Raises:
ValueError – if
guessis provided but is not a valid word, or has not been added toself.