API Reference#

wordle_cheater.cheater#

Utilities for generating solutions to Wordle given previous guesses.

exception wordle_cheater.cheater.InvalidWordleLetters(message, wordle_letters)#

Exception for when invalid letters are passed to WordleGuesses.

Attributes
invalid_letterslist of WordleLetter objects

The relevant letters that were found to be invalid given previously entered guesses.

class wordle_cheater.cheater.WordleGuesses(wordle_letters=None)#

Class representing all current guesses and their colors.

Parameters
wordle_letterslist of WordleLetters, optional

The initial words to add. Length must be an integer multiple of five.

Attributes
wordle_letterslist of WordleLetters

All the letters that have been entered so far.

blackslength-5 list of lists

A list of lowercase letters that are not in the word. For example, if our guesses have the letter ‘A’ marked black at the second character, blacks = [[], [‘A’], [], [], []].

yellowslength-5 list of lists

Lowercase letters that are in the word, but not in the correct location. For example, if our guesses tell us that the letter ‘A’ was in the word, but it was not the third letter, yellows = [[], [], [‘a’], [], []].

greenslength-5 list

Lowercase letters that are in the word and in the correct location. For example, if our guesses tell us that the letter ‘A’ is the fourth letter of the word, greens = [None, None, None, ‘a’, None].

countsdict

Counts of letters that should appear in the solution. For letters that are in blacks, this is interpreted as the exact number of times the letter must appear in the solution, and defaults to zero. For letters that are in yellows and/or greens, this is interpreted as the minimum number of times the letter must appear in the solution, and defaults to one. For example, if a previous guess was ‘array’ with the two ‘r’s colored, then we would know the solution must have at least two ‘r’s and so counts = {‘r’: 2}. If a previous guess was ‘array’, with one ‘r’ marked black and one colored, then we know the solution must have exactly one ‘r’ and so counts = {‘r’: 1}.

add_word(word)#

Update current guesses.

This method appends to self.wordle_letters and updates self.blacks, self.yellows, self.greens, and self.counts.

Parameters
wordlength-5 list of WordleLetters

The word to add to the current guesses.

Raises
InvalidWordleLetters

If word contains WordleLetters that are impossible given previous guesses.

get_invalid_letters(word)#

Get which of letters in word (if any) are invalid given current guesses.

Parameters
wordlength-5 list of WordleLetters

The word to check.

Returns
list of WordleLetters

The invalid letters of wordle_letters, an empty list if there were none.

class wordle_cheater.cheater.WordleLetter(letter: str, color: str, index: int)#

Class describing a single letter in a Wordle guess.

Parameters
letterstr

The letter in question. Should be lower case.

color{“black”, “yellow”, “green”}

The color Wordle marked the letter.

index{0, 1, 2, 3, 4}

The location in the word where the letter appeared.

wordle_cheater.cheater.cheat(wordle_letters)#

Given a list of WordleLetter objects, return possible solutions.

Parameters
wordle_letterslist of WordleLetter

The previous guesses. Every five WordleLetters are interpreted as one word.

Returns
possible_wordslist of str

A list of the possible solutions given wordle_letters, in random order.

wordle_cheater.cheater.check_word(word, guesses, check_dict=True)#

Check if word is a possible solution given previous guesses.

All inputs must be lowercase as we don’t bother to cast them to lowercase to save a bit of time.

Parameters
wordlength-5 string

The word to check.

guessesWordleGuesses

The previous guesses to check against.

check_dictbool, optional

Whether or not to check if word is a real five letter english word.

Returns
validbool

Whether or not word is a possible solution given blacks, yellows, and greens.

wordle_cheater.cheater.easy_cheat(letters, colors)#

Given previous guesses on Wordle, return a list of possible solutions.

Parameters
lettersstr

The previous guesses. Whitespace will be ignored.

colorsstr

The colors corresponding to each letter. Each character in this string must be one of ‘b’, ‘y’, or ‘g’, which correspond to ‘black’, ‘yellow’, or ‘green’, respectively. Whitespace will be ignored.

Returns
possible_wordslist of str

A list of the possible solutions in random order.

wordle_cheater.cheater.find_words(guesses)#

Find all possible words that are consistent with guesses.

Parameters
guessesWordleGuesses

The guesses to check against.

Returns
possible_wordslist

List of possible solutions that match the given guesses.

wordle_cheater.cheater.get_wordle_letters(letters, colors)#

Create a list of WordleLetter objects.

Parameters
lettersstr

The previous guesses. Whitespace will be ignored.

colorsstr

The colors corresponding to each letter. Each character in this string must be one of ‘b’, ‘y’, or ‘g’, which correspond to ‘black’, ‘yellow’, or ‘green’, respectively. Whitespace will be ignored.

Returns
wordle_letterslist of WordleLetter

The WordleLetter objects corresponding to the input letters and colors.

wordle_cheater.cli#

Command-line interface for wordle-cheater.

wordle_cheater.interface_base#

Base class & utilities for interfaces.

class wordle_cheater.interface_base.WordleCheaterUI#

Base class for handling logic of interface, independent of output method.

Attributes
guesseslist of WordleLetter objects

The currently entered guesses.

entering_lettersbool

Whether or not we are currently entering guesses.

enter_letters(x0=0, y0=0)#

Enter previous guesses with a wordle-like interface.

This method both returns and sets self.guesses.

Parameters
x0int, optional

The horizontal position of the upper-left corner of the words to enter.

y0int, optional

The vertical position of the upper-left corner of the words to enter.

Returns
guesseslist of WordleLetter objects
get_key()#

Get a key press.

Returns
keystr

The key that was pressed.

# noqaDAR202
get_results_string(max_rows=10, max_cols=8, sep='     ')#

Get possible solutions formatted into columns.

Parameters
max_rowsint, optional

The maximum number of rows to display. If the full string would require more than max_rows rows, show an ellipsis and the number of missing words on the last line instead.

max_colsint, optional

The number of words per row.

sepstr, optional

The character(s) to put in between each column. Defaults to ‘ ‘ (five spaces) so the space in between each column is the same as the width of each column.

Returns
out_strstr

The possible solutions formatted into a single string of rows and columns.

is_backspace(key)#

Check if key is the backspace/delete key.

Parameters
keystr

The key to check.

Returns
is_backspacebool

True if key is the backspace or delete key, False otherwise.

# noqaDAR202
is_enter(key)#

Check if key is the enter/return key.

Parameters
keystr

The key to check.

Returns
is_enterbool

True if key is the enter or return key, False otherwise.

# noqaDAR202
main()#

Run the interface.

Main entry point; called by the CLI.

move_cursor(x, y)#

Move cursor to position x, y.

Parameters
xint

Desired horizontal position of cursor.

yint

Desired vertical position of cursor.

print(x, y, string, c=None)#

Print a string at coordinates x, y.

Parameters
xint

Horizontal position at which to print the string.

yint

Height at which to print the string.

stringstr

The string to print.

cstr, {None, ‘black’, ‘yellow’, ‘green’, ‘red’}

The color in which to print. Must be one of [‘black’, ‘yellow’, ‘green’, ‘red’] or None. If c is None, it should print in the default color pair.

print_results()#

Print possible solutions given guesses.

print_title()#

Print title and instructions.

set_cursor_visibility(visible)#

Set cursor visibility.

Parameters
visiblebool

Whether or not the cursor is visible.

sleep(ms)#

Temporarily suspend execution.

Parameters
msint

Number of miliseconds before execution resumes.

wordle_cheater.interface_base.format_words(words, max_rows=10, max_cols=8, sep='     ')#

Format a list of strings into columns.

If len(words) > max_rows * max_cols, then the last line of the output string will instead indicate how many words are not included. Note that this line counts against the row limit.

Parameters
wordslist of str

The words to be formatted.

max_rowsint, optional

The maximum number of rows to display. If the full string would require more than max_rows rows, show an ellipsis and the number of missing words on the last line instead.

max_colsint, optional

The number of words per row.

sepstr, optional

The character(s) to put in between each column. Defaults to ‘ ‘ (five spaces) so the space in between each column is the same as the width of each column.

Returns
out_strstr

words formatted into a single string of rows and columns.

wordle_cheater.interface#

Interfaces for interactively entering guesses.

class wordle_cheater.interface.ClickInterface(max_rows=10, max_cols=8, x0=4, y0=4, esc='\x1b')#

Interface for using Click alone to enter letters and see solutions.

Parameters
max_rowsint, optional

The maximum rows of possible solutions to print.

max_colsint, optional

The maximum columns of possible solutions to print.

x0int, optional

The leftmost position where guesses will be entered.

y0int, optional

The topmost position where guesses will be entered.

escstr, optional

The ANSI escape code for the terminal.

Attributes
guesseslist of WordleLetter

The currently entered guesses.

entering_lettersbool

Whether or not we are currently entering guesses.

max_rowsint, optional

The maximum rows of possible solutions to print.

max_colsint, optional

The maximum columns of possible solutions to print.

x0int, optional

The leftmost position where guesses will be entered.

y0int, optional

The topmost position where guesses will be entered.

escstr, optional

The ANSI escape code for the terminal.

line_lengthslist of int

The highest x value we’ve printed to per line. For example, if we’ve printed two lines, the first one up to x=5 and the second up to x=3, then line_lengths = [5, 3].

curs_xy

Location of cursor.

property curs_xy#

Location of cursor.

get_key()#

Get a key press.

Returns
keystr

The key that was pressed.

is_backspace(key)#

Check if key is the backspace/delete key.

Parameters
keystr

The key to check.

Returns
is_backspacebool

True if key is the backspace or delete key, False otherwise.

is_enter(key)#

Check if key is the enter/return key.

Parameters
keystr

The key to check.

Returns
is_enterbool

True if key is the enter or return key, False otherwise.

main()#

Run the interface.

move_cursor(x, y)#

Move cursor to position x, y.

Parameters
xint

Desired horizontal position of cursor.

yint

Desired vertical position of cursor.

print(x, y, string, c=None, *args, **kwargs)#

Print string at coordinates x, y.

Parameters
xint

Horizontal position at which to print the string.

yint

Height at which to print the string.

stringstr

The string to print.

cstr, {None, ‘black’, ‘yellow’, ‘green’, ‘red’}

The color in which to print. Must be one of [‘black’, ‘yellow’, ‘green’, ‘red’] or None. If c is None, it should print in the default color pair.

*argstuple

Additional arguments to be passed to click.secho.

**kwargsdict, optional

Keyword arguments to be passed to click.secho.

print_results()#

Print possible solutions given guesses.

print_title()#

Print title and instructions.

set_cursor_visibility(visible)#

Set cursor visibility.

Parameters
visiblebool

Whether or not the cursor is visible.

sleep(ms)#

Temporarily suspend execution.

Parameters
msint

Number of miliseconds before execution resumes.

class wordle_cheater.interface.CursesInterface#

Interface for using the curses library to enter guesses and display solutions.

Attributes
guesseslist of WordleLetter objects

The currently entered guesses.

entering_lettersbool

Whether or not we are currently entering guesses.

center_print(y, string, *args, **kwargs)#

Print in the center of the screen.

Parameters
yint

The vertical location at which to print.

stringstr

The string to print.

*argstuple

Additional arguments to be passed to stdscr.addstr.

**kwargsdict, optional

Keyword arguments to be passed to stdscr.addstr.

get_key()#

Get a key press.

Returns
keystr

The key that was pressed.

classmethod init_and_run(*args, **kwargs)#

Instantiate and run self.main() using curses.wrapper.

Parameters
*argstuple

Positional arguments to be passed to the CursesInterface constructor.

**kwargsdict, optional

Keyword arguments to be passed to the CursesInterface constructor.

Returns
CursesInterface object

An instance of the CursesInterface class.

is_backspace(key)#

Check if key is the backspace/delete key.

Parameters
keystr

The key to check.

Returns
is_backspacebool

True if key is the backspace or delete key, False otherwise.

is_enter(key)#

Check if key is the enter/return key.

Parameters
keystr

The key to check.

Returns
is_enterbool

True if key is the enter or return key, False otherwise.

main(stdscr)#

Run the interface.

Should typically be called using curses.wrapper.

Parameters
stdscrcurses.Window object

The curses screen which the user interacts with.

move_cursor(x, y)#

Move cursor to position x, y.

Parameters
xint

Desired horizontal position of cursor.

yint

Desired vertical position of cursor.

print(x, y, string, c=None)#

Print string at coordinates x, y.

Parameters
xint

Horizontal position at which to print the string.

yint

Height at which to print the string.

stringstr

The string to print.

cstr, {None, ‘black’, ‘yellow’, ‘green’, ‘red’}

The color in which to print. Must be one of [‘black’, ‘yellow’, ‘green’, ‘red’] or None. If c is None, it should print in the default color pair.

print_results(sep='     ')#

Print possible solutions given guesses.

Parameters
sepstr, optional

The string to display between each possible solution.

print_title()#

Print title and instructions.

set_cursor_visibility(visible)#

Set cursor visibility.

Parameters
visiblebool

Whether or not the cursor is visible.

sleep(ms)#

Temporarily suspend execution.

Parameters
msint

Number of miliseconds before execution resumes.

wordle_cheater.dictionary#

Wordle dictionary and English alphabet.