Wordle

Implement Wordle game.

__version__ = ‘0.1’ __author__ = ‘Adnan Haque’

class wordle_game.wordle.WordList

Manage dictionary of possible words.

Dictionary of acceptable guesses and potential answers are both managed within this class.

acceptable_guesses

List of acceptable guesses in alphabetical order.

Type

List[str]

answers

List of potential answers in alphabetical order.

Type

List[str]

random_target() str

Pick random target from list of possible answers.

valid_guess(word) bool

Assess whether or not a guess is acceptable.

word_index(lookup: str) int

Lookup index of word in acceptable guesses.

class wordle_game.wordle.WordleGame(wordlist: wordle_game.wordle.WordList = <wordle_game.wordle.WordList object>, target=None)

Play Wordle game.

Implementation of mechanics of Wordle game.

Parameters
  • wordlist (WordList, optional (default=WordList())) – Acceptable answers and guesses.

  • target (str or None, optional (default=None)) – Target word, if unspecified will be instantiated randomly.

wordlist

Acceptable answers and guesses.

Type

WordList

state

Array reflecting current game state. Each row is a guess and each column reflects whether or not the letter is grey, yellow, or green.

Type

np.ndarray

guesses

List of guesses throughout the gameplay.

Type

List[str]

round

Current round of the game. The initial round is 1.

Type

int

add_state(guess, state_str: str) None

Update game with current state, designed for external play.

Parameters
  • guess (str, required) – Guess made for this round.

  • state_str (str, required) –

    Five digit string reflecting the response to the guess. ‘B’ - Letter does not exist in target word or if there are repeated letters,

    in the guess there are fewer of this letter in the target word.

    ’G’ - Letter does exist in target word and is in the right location. ‘Y’ - Letter does exist in target word but is not in the right location. e.g. BBGGY

complete() int

Determine if game is complete.

Returns

complete – IN_PROGRESS - game in progress. WIN - player has won by guessing the word. LOSE - player has lost by exceeding maximum guesses.

Return type

int

guess(word: str) bool

Increment game by guessing a word.

wordle_game.wordle.generate_state(target, word)

Generate state of guess.

Examples

>>> np.all(generate_state("raise", "paire") == np.array([GREY, GREEN, GREEN, YELLOW, GREEN]))
True
>>> np.all(generate_state("boils", "loops") == np.array([YELLOW, GREEN, GREY, GREY, GREEN]))
True
>>> np.all(generate_state("flute", "belle") == np.array([GREY, GREY, YELLOW, GREY, GREEN]))
True
wordle_game.wordle.load_dict(path: str) List[str]

Load dictionary of words from file.

wordle_game.wordle.valid_state(input: str) bool

Return if string representation of state is valid.