haive.games.mancala.state¶

State for the Mancala game.

This module defines the state for the Mancala game, which includes the board, turn, game status, move history, free turn, winner, and player analyses.

Classes¶

MancalaState

State for a Mancala game.

Functions¶

extract_analysis_from_message(analysis)

Extract analysis data from an AIMessage object.

Module Contents¶

class haive.games.mancala.state.MancalaState(/, **data)[source]¶

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

State for a Mancala game.

This class defines the structure of the Mancala game state, which includes the board, turn, game status, move history, free turn, winner, and player analyses.

Parameters:

data (Any)

board¶

List of 14 integers representing the game board.

turn¶

The current player’s turn.

game_status¶

The status of the game.

move_history¶

List of moves made in the game.

free_turn¶

Whether the current player gets a free turn.

winner¶

The winner of the game, if any.

player1_analysis¶

Analysis data for player 1.

player2_analysis¶

Analysis data for player 2.

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.

determine_winner()[source]¶

Determine the winner of the game.

Returns:

The winner of the game or ‘draw’ if tied.

Return type:

Literal[‘player1’, ‘player2’, ‘draw’]

display_board()[source]¶

Display the board in a human-readable format.

Returns:

A string representation of the current board state.

Return type:

str

get_scores()[source]¶

Get the current scores for both players.

Returns:

Dictionary with player1 and player2 scores.

Return type:

dict[str, int]

get_valid_moves(player)[source]¶

Get valid moves for the specified player.

Parameters:

player (Literal['player1', 'player2']) – The player to get valid moves for.

Returns:

List of valid pit indices the player can choose from.

Return type:

list[int]

classmethod handle_analysis_data(data)[source]¶

Handle conversion of analysis data to proper types.

Parameters:

data (Any)

Return type:

Any

classmethod handle_initialization_data(data)[source]¶

Handle special initialization patterns from the framework.

Parameters:

data (Any)

Return type:

Any

classmethod initialize(**kwargs)[source]¶

Initialize the Mancala game state.

Parameters:

**kwargs – Optional parameters including stones_per_pit.

Returns:

A fully initialized Mancala game state.

Return type:

MancalaState

is_game_over()[source]¶

Check if the game is over.

Returns:

True if the game is over, False otherwise.

Return type:

bool

classmethod validate_board(v)[source]¶

Validate that the board has exactly 14 positions.

Parameters:

v (list[int]) – The board to validate.

Returns:

The validated board.

Raises:

ValueError – If board doesn’t have exactly 14 positions.

Return type:

list[int]

haive.games.mancala.state.extract_analysis_from_message(analysis)[source]¶

Extract analysis data from an AIMessage object.

Parameters:

analysis (Any) – The analysis object to extract from.

Returns:

Extracted analysis data or None if extraction fails.

Return type:

dict[str, Any] | None