games.hold_em.state_manager¶

Texas Hold’em game state management module.

This module provides a dedicated state manager for Texas Hold’em poker games, offering static methods for state manipulation, including:

  • Creating and initializing game states

  • Advancing game phases

  • Applying player actions

  • Handling betting rounds

  • Managing pot and chip distribution

  • Tracking hand history

The state manager serves as a central interface for manipulating the game state in a consistent manner, separating state manipulation logic from the game agent.

Example

>>> from haive.games.hold_em.state_manager import HoldemGameStateManager
>>> from haive.games.hold_em.state import HoldemState, PlayerState
>>>
>>> # Create player states
>>> players = [
>>>     PlayerState(player_id="p1", name="Alice", chips=1000, position=0),
>>>     PlayerState(player_id="p2", name="Bob", chips=1000, position=1),
>>> ]
>>>
>>> # Initialize a new game state
>>> state = HoldemGameStateManager.create_initial_state(
>>>     players=players,
>>>     small_blind=10,
>>>     big_blind=20
>>> )
>>>
>>> # Advance the game to the next phase
>>> updated_state = HoldemGameStateManager.advance_phase(state)

Classes¶

HoldemGameStateManager

State manager for Texas Hold'em poker games.

Module Contents¶

class games.hold_em.state_manager.HoldemGameStateManager¶

State manager for Texas Hold’em poker games.

This class provides static methods for manipulating the game state, separating state logic from the game agent. It handles state transitions, player actions, and game flow management in a functional manner.

All methods are static and take a state object as input, returning a new state object with the requested changes applied, following an immutable approach to state management.

static advance_phase(state)¶

Advance the game to the next phase based on current phase.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state in the next game phase

Return type:

haive.games.hold_em.state.HoldemState

static apply_player_action(state, player_index, action, amount=0)¶

Apply a player’s action to the game state.

Parameters:
  • state (haive.games.hold_em.state.HoldemState) – Current game state

  • player_index (int) – Index of the player taking the action

  • action (str) – Action to take (fold, check, call, bet, raise, all_in)

  • amount (int) – Amount for bet/raise (if applicable)

Returns:

Updated state with the action applied

Return type:

haive.games.hold_em.state.HoldemState

static award_pot(state)¶

Award the pot to the winner and record hand history.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state with pot awarded and hand recorded

Return type:

haive.games.hold_em.state.HoldemState

static check_game_end(state)¶

Check if the game should end.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Tuple of (updated state, game_over flag)

Return type:

tuple[haive.games.hold_em.state.HoldemState, bool]

static create_initial_state(players, small_blind=10, big_blind=20, starting_chips=1000, game_id=None)¶

Create an initial game state for a new poker game.

Parameters:
  • players (list[haive.games.hold_em.state.PlayerState]) – List of player states

  • small_blind (int) – Small blind amount

  • big_blind (int) – Big blind amount

  • starting_chips (int) – Starting chips for each player

  • game_id (str | None) – Optional game identifier (generated if not provided)

Returns:

A new HoldemState instance ready for the first hand

Return type:

haive.games.hold_em.state.HoldemState

static deal_community_cards(state, num_cards, phase)¶

Deal community cards (flop, turn, or river).

Parameters:
Returns:

Updated state with community cards dealt

Return type:

haive.games.hold_em.state.HoldemState

static deal_hole_cards(state)¶

Deal two hole cards to each active player.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state with hole cards dealt

Return type:

haive.games.hold_em.state.HoldemState

static evaluate_showdown(state)¶

Evaluate player hands at showdown and determine winner.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state with winner determined

Return type:

haive.games.hold_em.state.HoldemState

static post_blinds(state)¶

Post small and big blinds to start the betting.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state with blinds posted

Return type:

haive.games.hold_em.state.HoldemState

static setup_new_hand(state)¶

Set up a new poker hand with shuffled deck and reset player states.

Parameters:

state (haive.games.hold_em.state.HoldemState) – Current game state

Returns:

Updated state with new hand setup

Return type:

haive.games.hold_em.state.HoldemState