toetactic package¶
Submodules¶
toetactic.board module¶
Board model and move parsing for toetactic.
- class toetactic.board.Board(dimension: int = 3)[source]¶
Bases:
objectRepresent an N x N Tic Tac Toe board.
- Variables:
dimension (int) – Number of rows/columns on the board.
cells (list[list[str]]) –
dimensionxdimensiongrid of cell marks, where each cell holds" "(empty),"X", or"O".
- available_moves() list[tuple[int, int]][source]¶
Return all currently available board coordinates.
- Returns:
List of zero-based
(row, col)tuples for every empty cell, in row-major order.
- has_winner(mark: str) bool[source]¶
Return True when a mark completes a row, column, or diagonal.
- Parameters:
mark – Single-character mark to check for, e.g.
"X"or"O".- Returns:
True if every cell in at least one row, column, or diagonal holds
mark, False otherwise.
- is_cell_empty(row: int, col: int) bool[source]¶
Return True if a board cell is empty.
- Parameters:
row – Zero-based row index.
col – Zero-based column index.
- Returns:
True if the cell holds no mark, False otherwise.
- is_full() bool[source]¶
Return True when no moves are left.
- Returns:
True if every cell on the board is occupied, False otherwise.
- move_to_label(row: int, col: int) str[source]¶
Convert board coordinates to a label like ‘A1’.
- Parameters:
row – Zero-based row index.
col – Zero-based column index.
- Returns:
Chess-like move label, e.g.
"A1".
- parse_move(move: str) tuple[int, int][source]¶
Parse a move like ‘A1’ into (row_index, col_index).
- Parameters:
move – Chess-like move label, e.g.
"A1"or"c3". Leading/trailing whitespace and letter case are ignored.- Returns:
Zero-based
(row, col)coordinates for the move.- Raises:
ValueError – If
moveis not in the<letter><number>format, or if it refers to a cell outside the board.
toetactic.game module¶
Game session orchestration for toetactic CLI.
- toetactic.game.BANNER = '\n _____ _____ _____ _\n|_ _|__ __|_ _|_ _ __|_ _(_) ___\n | |/ _ \\ / _ \\| |/ _` |/ __|| | | |/ __|\n | | (_) | __/| | (_| | (__ | | | | (__\n |_|\\___/ \\___||_|\\__,_|\\___||_| |_|\\___|\n'¶
ASCII art title shown when the game is loaded, before setup prompts.
- class toetactic.game.Game[source]¶
Bases:
objectRepresent a single CLI Tic Tac Toe game session.
- Variables:
board (toetactic.board.Board) – Board being played on.
human (HumanPlayer) – The human player, always marked
"X".opponent (toetactic.player.Player) – The AI opponent, always marked
"O".
- class toetactic.game.HumanPlayer(name: str, mark: str)[source]¶
Bases:
PlayerRepresent the human player.
- choose_move(board: Board, opponent_mark: str) tuple[int, int][source]¶
Human move is provided by prompt in Game; this method is not used.
- Parameters:
board – Current board state. Unused.
opponent_mark – Mark used by the opposing player. Unused.
- Raises:
NotImplementedError – Always. Human moves are collected via
Game._prompt_human_move()instead.
- toetactic.game.OPPONENTS: dict[str, type[Player]] = {'dikembe': <class 'toetactic.player.Dikembe'>, 'eleanor': <class 'toetactic.player.Eleanor'>, 'godzilla': <class 'toetactic.player.Godzilla'>, 'noober': <class 'toetactic.player.Noober'>}¶
Map of opponent selection keywords (as entered at the setup prompt) to the
Playersubclass that implements them.
toetactic.logger module¶
toetactic.player module¶
Players and AI strategies for toetactic.
- class toetactic.player.Dikembe(name: str, mark: str)[source]¶
Bases:
PlayerDefensive opponent that prioritizes preventing player wins.
- choose_move(board: Board, opponent_mark: str) tuple[int, int][source]¶
Choose a move by blocking first, then choosing safe central options.
- Parameters:
board – Current board state.
opponent_mark – Mark used by the opposing player.
- Returns:
Zero-based
(row, col)coordinates of the chosen move: a block of the opponent’s immediate winning line if one exists, otherwise the center, otherwise a corner, otherwise the first available cell.
- class toetactic.player.Eleanor(name: str, mark: str)[source]¶
Bases:
PlayerOpponent that builds rows and columns, avoiding diagonals if possible.
- choose_move(board: Board, opponent_mark: str) tuple[int, int][source]¶
Choose a move by favouring row/column lines over diagonals.
Restricts itself to non-diagonal cells whenever any remain: among those, it takes an immediate win, then blocks an immediate opponent win, then advances whichever open row or column line it has already made the most progress on. Diagonal cells are only used once no non-diagonal cell is available.
- Parameters:
board – Current board state.
opponent_mark – Mark used by the opposing player.
- Returns:
Zero-based
(row, col)coordinates of the chosen move.
- class toetactic.player.Godzilla(name: str, mark: str)[source]¶
Bases:
PlayerAttacking opponent that seeks immediate wins each turn.
- choose_move(board: Board, opponent_mark: str) tuple[int, int][source]¶
Choose a move by winning first, then taking strong positional moves.
- Parameters:
board – Current board state.
opponent_mark – Mark used by the opposing player.
- Returns:
Zero-based
(row, col)coordinates of the chosen move: an immediate winning move if one exists, otherwise the center, otherwise a corner, otherwise the first available cell.
- class toetactic.player.Noober(name: str, mark: str)[source]¶
Bases:
PlayerOpponent that picks any legal move at random, hoping for luck.
- choose_move(board: Board, opponent_mark: str) tuple[int, int][source]¶
Choose a uniformly random move among all legal moves.
- Parameters:
board – Current board state.
opponent_mark – Mark used by the opposing player. Unused, since Noober’s choice does not depend on board strategy.
- Returns:
Zero-based
(row, col)coordinates of a randomly chosen, currently empty cell.
Module contents¶
CLI entrypoint for toetactic.