tictactoe_policy package¶
Submodules¶
tictactoe_policy.cli module¶
tictactoe_policy.dataset module¶
tictactoe_policy.evaluation module¶
tictactoe_policy.game module¶
Board configuration and rules for configurable Tic-Tac-Toe.
- class tictactoe_policy.game.GameConfig(board_size: int = 3, win_length: int | None = None)[source]¶
Bases:
objectImmutable game dimensions.
- Parameters:
board_size – Board width and height, from 3 through 8.
win_length – Consecutive marks required to win. Defaults to the board size when omitted.
- Raises:
ValueError – If either dimension is outside its valid range.
- Variables:
board_size – Configured board width and height.
win_length – Configured number of consecutive marks needed to win.
- board_size: int = 3¶
Board width and height.
- property cell_count: int¶
Return the total number of board cells.
- Returns:
board_sizesquared.
- win_length: int | None = None¶
Consecutive marks required to win.
- tictactoe_policy.game.MAX_BOARD_SIZE = 8¶
Largest supported board width and height.
- tictactoe_policy.game.MIN_BOARD_SIZE = 3¶
Smallest supported board width and height.
- class tictactoe_policy.game.TicTacToeGame(config: GameConfig | None = None)[source]¶
Bases:
objectValidate boards and implement configurable Tic-Tac-Toe rules.
- Parameters:
config – Game dimensions. Standard 3x3 rules are used when omitted.
- Variables:
config – Dimensions used by this game.
lines – Every winning line expressed as row-major cell indices.
- static apply_move(board: Sequence[int], move: int, player: int) tuple[int, ...][source]¶
Apply one legal move without modifying the input board.
- Parameters:
board – Board cells in row-major order.
move – Index of the empty cell to occupy.
player – Player mark, either
1or-1.
- Returns:
A new immutable board containing the move.
- Raises:
ValueError – If the player or move is invalid.
- infer_player(board: Sequence[int]) int[source]¶
Infer whose turn follows an X-first reachable board.
- Parameters:
board – Non-terminal board cells in row-major order.
- Returns:
1when X moves next or-1when O moves next.- Raises:
ValueError – If the board is invalid or terminal.
- is_terminal(board: Sequence[int]) bool[source]¶
Determine whether a board is won or full.
- Parameters:
board – Board cells in row-major order.
- Returns:
True when play cannot continue.
- legal_moves(board: Sequence[int]) list[int][source]¶
List the unoccupied cells on a board.
- Parameters:
board – Board cells in row-major order.
- Returns:
Legal move indices in ascending order.
- validate_board(board: Sequence[int], check_reachable: bool = True) tuple[int, ...][source]¶
Validate a board and return an immutable representation.
- Parameters:
board – Board cells in row-major order, using
1for X,-1for O, and0for an empty cell.check_reachable – Validate turn counts and winner consistency.
- Returns:
The validated board as a tuple.
- Raises:
ValueError – If the dimensions, cells, turn counts, or winners are invalid.