games.reversi.state¶

Reversi (Othello) game state model.

Defines board layout, current game status, turn tracking, move history, analysis storage, and rendering utilities for the Reversi agent system.

Classes¶

ReversiState

State model for a game of Reversi/Othello.

Module Contents¶

class games.reversi.state.ReversiState(/, **data)¶

Bases: haive.games.framework.base.state.GameState

State model for a game of Reversi/Othello.

Parameters:

data (Any)

board¶

8x8 grid representing the game board.

Type:

List[List[Optional[str]]]

turn¶

The current player’s turn (‘B’ or ‘W’).

Type:

str

game_status¶

Overall game status (ongoing, draw, B_win, W_win).

Type:

str

move_history¶

History of all moves made.

Type:

List[ReversiMove]

winner¶

Winner symbol (‘B’ or ‘W’), or None.

Type:

Optional[str]

player_B¶

Identifier for the player using black discs.

Type:

str

player_W¶

Identifier for the player using white discs.

Type:

str

player1_analysis¶

Analysis history by player1.

Type:

List[Dict[str, any]]

player2_analysis¶

Analysis history by player2.

Type:

List[Dict[str, any]]

skip_count¶

Number of consecutive turns skipped (used for endgame).

Type:

int

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod initialize(first_player='B', player_B='player1', player_W='player2')¶

Class-level initializer for ReversiState.

Parameters:
  • first_player (str) – ‘B’ or ‘W’. Who plays first.

  • player_B (str) – Which player controls black.

  • player_W (str) – Which player controls white.

Returns:

Initialized state.

Return type:

ReversiState

classmethod validate_board(board)¶

Validate that the board is an 8x8 grid with only valid values.

Parameters:

board (List[List[Optional[str]]]) – Input board state.

Returns:

The validated board.

Return type:

List[List[Optional[str]]]

Raises:

ValueError – If the board structure or contents are invalid.

property board_string: str¶

Get a human-readable string of the current board layout.

Returns:

Formatted board as text.

Return type:

str

property current_player_name: str¶

Get the current player’s identifier.

Returns:

Either ‘player1’ or ‘player2’.

Return type:

str

property disc_count: dict[str, int]¶

Count the number of discs of each color on the board.

Returns:

Dictionary with counts of ‘B’ and ‘W’.

Return type:

Dict[str, int]