zttt Module Reference
Module zttt
The module contains 2 main classes Both the classes inherit from the ZTBaseBoard class.
PvP: The class for the PvP game
PvC: The class for the PvC game
The module also contains the submodule zt_errors which contain the following errors
ZTError: The base class for all ZTErrors
ZTBadFunctionCall: The error raised when a function is called with the wrong arguments. Mostly used for debugging
ZTGameException: The error raised when a function call crashes the game
ZTInvalidInput: The error raised when the input provided is not valid
- class zttt.PvP
Bases:
ZTBaseBoardPlayer vs Player Tic Tac Toe game
This class provides a simple interface for a two-player Tic Tac Toe game. Players alternate turns, with Player 1 (X) going first.
- Example:
>>> game = PvP() >>> game.play(0) # Player 1 plays top-left >>> game.play(4) # Player 2 plays center >>> print(game.board)
- play(pos: int) None
Plays the current player’s move at the position specified
- Parameters:
pos (int) – The position to play (0-8, row-major order from top-left)
- Returns:
None
- Raise:
ZTGameException if the game is not in progress
- Raise:
ZTInvalidInput if the move is invalid
- class zttt.PvC(_engine_first: bool = True)
Bases:
objectPlayer vs Computer Tic Tac Toe game
This class provides an interface for playing against an AI opponent. The AI uses a near-perfect strategy to play the game.
- Example:
>>> game = PvC(engine_first=False) # Player goes first >>> game.play(4) # Player plays center >>> print(game.board) # AI has already responded
- play(pos: int) None
Plays the player’s move and triggers the AI’s response
- Parameters:
pos (int) – The position to play (0-8, row-major order from top-left)
- Returns:
None
- Raise:
ZTGameException if the game is not in progress
- Raise:
ZTInvalidInput if the move is invalid
- class zttt.CellValue(value)
Bases:
IntEnumEnum for cell values on the board
- EMPTY = 0
- PLAYER2 = 1
- PLAYER1 = 4
- class zttt.Player(value)
Bases:
IntEnumEnum for player numbers
- DRAW = 0
- PLAYER1 = 1
- PLAYER2 = 2
- class zttt._zt_core.ZTBaseBoard
Bases:
objectThis is the base class which is inherited by all the classes which are used in the module
- classmethod set_indicators(_player1: str = 'X', _player2: str = 'O', _space: str = ' ') None
Sets the indicators, a class method
- Parameters:
_player1 (str) – Indicator for player 1
_player2 (str) – Indicator for player 2
_space (str) – Indicator for empty position
- Returns:
None
- property board_list: list[int]
List containing the status of the board (Row Major Order)
- Returns:
A (duplicate) list of the board list
- Return type:
List[int]
- property status: bool
Whether the game is in progress or not
- Returns:
The status of the game
- Return type:
bool
- property move: int
The current move that is to be performed
- Returns:
Current Move Number
- Return type:
int
- property turn: int
The player whose turn it is to play
- Returns:
Player Number
- Return type:
int
- property winner: int | None
The winner of the game
- Returns:
Winner if the game is over, 0 is draw, None if no winner yet
- Return type:
Optional[int]
- property history: list[int]
Returns the history of the game
- Returns:
A (duplicate) list of the history
- Return type:
List[int]
- property empty_positions: list[int]
Returns the list of empty positions
- Returns:
A (duplicate) list (in row major order from 0) of the empty positions
- Return type:
List[int]
- property empty_corners: list[int]
Returns the list of empty corners
- Returns:
List of the empty corners
- Return type:
List[int]
- property empty_edges: list[int]
Returns the list of empty edges
- Returns:
List of the empty edges
- Return type:
List[int]
- property highlighted: list[int]
Returns the highlighted positions of the board when there is a winner, empty list otherwise
- Returns:
A (duplicate) list of highlighted positions
- Return type:
List[int]
- property board: str
Returns the string representation of the board
- Returns:
board string
- Return type:
str
- property on_move: Callable[[int, int], None]
Returns the on_move event trigger
- Returns:
on_move event trigger
- Return type:
Callable[[int, int], None]
- property on_finish: Callable[[int], None]
Returns the on_move event trigger
- Returns:
_on_finish event trigger
- Return type:
Callable[[int], None]
Module zttt.zt_errors
The module contains the errors that can be raised by the zttt package.
- exception zttt.zt_errors.ZTError
Bases:
ExceptionBase class for all zt_errors.
- exception zttt.zt_errors.ZTBadFunctionCall
Bases:
AttributeError,ZTErrorRaised when a function is called with the wrong arguments. Mostly used for debugging.
- exception zttt.zt_errors.ZTGameException
Bases:
ZTErrorRaised when some invalid function call crashes the game.
- exception zttt.zt_errors.ZTInvalidInput
Bases:
ValueError,ZTGameExceptionRaised when the input provided is not valid.