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 Solver instance will consider to be possible target words.

  • guess_list (list[str] or None) – (Optional) List containing all the words that the Solver instance will consider to be legal guesses. If it is None or not provided, word_list will 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 using remove_guess().

Parameters:
Raises:
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 to self. Default False. 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 eliminate absurdle_target if 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 creating self.

Return type:

str

Raises:
  • ValueError – if absurdle_target is provided but is not a valid word, or is not one of the words returned by get_possibilities().

  • RuntimeError – if there are no possible target words remaining.

  • RuntimeError – if hard_mode is True but all the elements of self’s guess list are eliminated by guesses.

  • RuntimeError – if absurdle_target is 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 self and 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])]
Return type:

list[tuple[str, list[int]]]

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:

tuple[list[int], int]

Raises:

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.

get_possibilities() list[str]

Get all the remaining possible target words.

Returns:

List of all the elements of the word list self was created with that are not eliminated by the guesses added to self.

Return type:

list[str]

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:

True if word is consistent with the guesses and feedback added to self, otherwise False.

Return type:

bool

Raises:

ValueError – if word is 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 is None or not provided, all guesses will be removed.

Raises:

ValueError – if guess is provided but is not a valid word, or has not been added to self.