games.multi_player.state_manager¶

State management interface for multi-player games.

This module provides the base state manager interface for multi-player games, defining the core operations that game-specific state managers must implement. The state manager handles:

  • Game initialization

  • Move application and validation

  • Legal move generation

  • Game status updates

  • Phase transitions

  • Information hiding

Example

>>> from typing import List, Dict, Any
>>> from haive.agents.agent_games.framework.multi_player.state_manager import MultiPlayerGameStateManager
>>>
>>> class MyGameStateManager(MultiPlayerGameStateManager[MyGameState]):
...     @classmethod
...     def initialize(cls, player_names: List[str], **kwargs) -> MyGameState:
...         return MyGameState(players=player_names)

Classes¶

MultiPlayerGameStateManager

Manager for multi-player game states.

Module Contents¶

class games.multi_player.state_manager.MultiPlayerGameStateManager¶

Bases: Generic[T]

Manager for multi-player game states.

This abstract base class defines the interface for managing game states in multi-player games. Game-specific implementations must inherit from this class and implement all abstract methods.

Type Parameters:

T: The game state type, must be a Pydantic BaseModel.

Example

>>> class ChessStateManager(MultiPlayerGameStateManager[ChessState]):
...     @classmethod
...     def initialize(cls, player_names: List[str], **kwargs) -> ChessState:
...         return ChessState(
...             players=player_names,
...             board=cls.create_initial_board()
...         )
classmethod advance_phase(state)¶
Abstractmethod:

Parameters:

state (T)

Return type:

T

Advance the game to the next phase.

This method should handle phase transitions, including any necessary state updates or cleanup between phases.

Parameters:

state (T) – Current game state.

Returns:

Updated game state in the new phase.

Return type:

T

Raises:

NotImplementedError – Must be implemented by subclass.

classmethod apply_move(state, player_id, move)¶
Abstractmethod:

Parameters:
  • state (T)

  • player_id (str)

  • move (Any)

Return type:

T

Apply a move by a specific player.

Parameters:
  • state (T) – Current game state.

  • player_id (str) – ID of the player making the move.

  • move (Any) – The move to apply.

Returns:

New game state after applying the move.

Return type:

T

Raises:

NotImplementedError – Must be implemented by subclass.

classmethod check_game_status(state)¶
Abstractmethod:

Parameters:

state (T)

Return type:

T

Check and update game status.

This method should check for win conditions, draws, or other game-ending conditions and update the state accordingly.

Parameters:

state (T) – Current game state.

Returns:

Updated game state with current status.

Return type:

T

Raises:

NotImplementedError – Must be implemented by subclass.

classmethod filter_state_for_player(state, player_id)¶
Abstractmethod:

Parameters:
  • state (T)

  • player_id (str)

Return type:

dict[str, Any]

Filter the state to include only information visible to a specific player.

This method should implement information hiding, ensuring players only see game information they should have access to.

Parameters:
  • state (T) – Current game state.

  • player_id (str) – ID of the player to filter for.

Returns:

Filtered game state with only visible information.

Return type:

Dict[str, Any]

Raises:

NotImplementedError – Must be implemented by subclass.

Abstractmethod:

Parameters:
  • state (T)

  • player_id (str)

Return type:

list[Any]

Get legal moves for a specific player.

Parameters:
  • state (T) – Current game state.

  • player_id (str) – ID of the player to get moves for.

Returns:

List of legal moves for the player.

Return type:

List[Any]

Raises:

NotImplementedError – Must be implemented by subclass.

classmethod initialize(player_names, **kwargs)¶
Abstractmethod:

Parameters:

player_names (list[str])

Return type:

T

Initialize a new game state with multiple players.

Parameters:
  • player_names (List[str]) – List of player names/IDs.

  • **kwargs – Additional game-specific initialization parameters.

Returns:

A new game state instance.

Return type:

T

Raises:

NotImplementedError – Must be implemented by subclass.