haive.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¶
State manager for Texas Hold'em poker games. |
Module Contents¶
- class haive.games.hold_em.state_manager.HoldemGameStateManager[source]¶
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)[source]¶
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:
- static apply_player_action(state, player_index, action, amount=0)[source]¶
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:
- static award_pot(state)[source]¶
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:
- static check_game_end(state)[source]¶
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:
- static create_initial_state(players, small_blind=10, big_blind=20, starting_chips=1000, game_id=None)[source]¶
Create an initial game state for a new poker game.
- Parameters:
- Returns:
A new HoldemState instance ready for the first hand
- Return type:
- static deal_community_cards(state, num_cards, phase)[source]¶
Deal community cards (flop, turn, or river).
- Parameters:
state (haive.games.hold_em.state.HoldemState) – Current game state
num_cards (int) – Number of cards to deal
phase (haive.games.hold_em.state.GamePhase) – New game phase
- Returns:
Updated state with community cards dealt
- Return type:
- static deal_hole_cards(state)[source]¶
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:
- static evaluate_showdown(state)[source]¶
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:
- static post_blinds(state)[source]¶
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:
- static setup_new_hand(state)[source]¶
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: