API¶
- class lbsolver.Gameboard(board: Union[str, List[str]])¶
This is a class that represents a Gameboard for a solver. Takes a string representing the board.
- Parameters:
board (list or str) – A string or list of strings that represent the board.
- Raises:
ValueError – If the board is invalid (incorrect length, non-alphabet characters or repeated characters)
- property board¶
The board represented as a list of strings
- static default_board()¶
A utility method creating a default board that is known to generate results
- Returns:
A gameboard composed of ‘giyercpolahx’
- Return type:
- get_side_for_letter(letter: str) Optional[str]¶
Get the side a letter is on.
- Parameters:
letter (str) – A string of length 1 with a single letter.
- Returns:
A str representing the side or None in case where the character is not on a side.
- Return type:
str or None
- property side1¶
Get board side 1
- property side2¶
Get board side 2
- property side3¶
Get board side 3
- property side4¶
Get board side 4
- class lbsolver.LBSolver(gameboard: Gameboard, dictionary: Sequence[str])¶
This is the solver class. It requires a
lbsolver.Gameboardand a dictionary to generate a set of answers to the Letter Boxed game.- Parameters:
gameboard – A gameboard representing the letters in the Letter Boxed game
dictionary (Sequence[str]) – A backing dictionary to use to find potential answers
- Raises:
TypeError – If gameboard or dictionary is set to None
- property dictionary: Sequence[str]¶
The dictionary instance
- generate_valid_words(dictionary: Optional[Sequence[str]] = None) Iterator[str]¶
Based on the current gameboard, generate a set of valid words from dictionary. If dictionary parameter is not set, default dictionary is used.
- Parameters:
dictionary (Sequence[str]) – An dictionary to use to find valid words
- Returns:
A set of valid words
- Return type:
Iterator[str]
- get_unused_letters(my_word: str) set¶
Given a word, identify characters on the gameboard not used.
- Parameters:
my_word (str) – A word to evaluate against the gameboard.
- Raises:
ValueError – If the word contains characters not on the gameboard.
- Returns:
A set of unused characters from the gameboard.
- Return type:
set
- possible_on_board(word_sequence: str) bool¶
Check whether a sequence is possible based upon Letter Boxed rules. It does not determine whether the sequence is a word.
- Parameters:
word_sequence (str) – Check whether a potential word is possible on the board.
- Returns:
True if sequence is possible on board, false otherwise
- Return type:
bool
- solve(max_num_words: int = 3, minimum_answers: int = 1, skip: str = '') Sequence[tuple]¶
Solve the puzzle based on the current dictionary and gameboard.
- Parameters:
max_num_words (int) – The maximum number of words allowed in an answer
minimum_answers – The minimum number of answers to retrieve. Solve
will stop after finding this number of answers :type minimum_answers: int :param skip: A list of words separated by commas. Words in this list will be skipped from answers :type skip: str :raise ValueError: if max_num_words or minimum_answers is less than or equal to zero. :return: A list filled with answer tuples :rtype: Sequence[tuple]