games.mancala.state_manager¶

State manager for the Mancala game.

This module defines the state manager for the Mancala game, which manages the state of the game and provides methods for initializing, updating, and analyzing the game state.

Classes¶

MancalaStateManager

Manager for Mancala game state.

Module Contents¶

class games.mancala.state_manager.MancalaStateManager¶

Bases: haive.games.framework.base.state_manager.GameStateManager[haive.games.mancala.state.MancalaState]

Manager for Mancala game state.

This class provides methods for initializing, updating, and analyzing the game state.

classmethod add_analysis(state, player, analysis)¶

Add an analysis to the state.

Parameters:
Returns:

Updated state with the analysis added.

Return type:

MancalaState

classmethod apply_move(state, move)¶

Apply a move to the current state according to Mancala rules.

This method distributes stones from the selected pit, handles captures, checks for free turns, and updates the game status.

Parameters:
Returns:

A new game state after applying the move.

Return type:

MancalaState

Raises:

ValueError – If the move is invalid (wrong player’s turn, empty pit, etc.).

Game Rules Implemented:
  1. Stones are distributed counterclockwise, one per pit.

  2. Player’s own store is included; opponent’s store is skipped.

  3. If the last stone lands in the player’s store, they get another turn.

  4. If the last stone lands in an empty pit on the player’s side, they capture that stone and all stones in the opposite pit.

  5. Game ends when all pits on one side are empty.

classmethod check_game_status(state)¶

Check and update the game status.

Parameters:

state (haive.games.mancala.state.MancalaState) – The current game state.

Returns:

The game state with updated status.

Return type:

MancalaState

Get all legal moves for the current player in the given state.

Parameters:

state (haive.games.mancala.state.MancalaState) – The current game state.

Returns:

A list of all legal moves for the current player. Each move is represented as a MancalaMove object with pit_index (0-5) and player fields.

Return type:

List[MancalaMove]

Note

Pit indices are always 0-5 for both players, representing the six pits on their side of the board (not including their store).

classmethod get_winner(state)¶

Get the winner of the game, if any.

Parameters:

state (haive.games.mancala.state.MancalaState) – The current game state.

Returns:

The winner, or None if the game is ongoing or a draw.

Return type:

Optional[str]

classmethod initialize(**kwargs)¶

Initialize a new Mancala game with a fresh board and default settings.

Parameters:

**kwargs – Keyword arguments for game initialization. stones_per_pit: Number of stones per pit initially. Defaults to 4. Other keyword arguments are passed to the MancalaState constructor.

Returns:

A new Mancala game state ready to play.

Return type:

MancalaState

Note

The board is initialized with the following layout: - Indices 0-5: Player 1’s pits (bottom row, left to right) - Index 6: Player 1’s store (right) - Indices 7-12: Player 2’s pits (top row, right to left) - Index 13: Player 2’s store (left)