haive.games.fox_and_geese.agent¶
Fox and Geese game agent with fixed state handling and UI integration.
This module defines the Fox and Geese game agent, which uses language models to generate moves and analyze positions in the game.
Classes¶
Agent for playing Fox and Geese. |
Functions¶
|
Ensure input is converted to FoxAndGeeseState. |
Module Contents¶
- class haive.games.fox_and_geese.agent.FoxAndGeeseAgent(config=FoxAndGeeseConfig())[source]¶
Bases:
haive.games.framework.base.agent.GameAgent
[haive.games.fox_and_geese.config.FoxAndGeeseConfig
]Agent for playing Fox and Geese.
This class implements the Fox and Geese game agent, which uses language models to generate moves and analyze positions in the game.
Initialize the Fox and Geese agent.
- Parameters:
config (FoxAndGeeseConfig) – The configuration for the Fox and Geese game.
- analyze_fox_position(state)[source]¶
Analyze the current position from the Fox’s perspective.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
LangGraph command with fox analysis updates
- Return type:
Command
- analyze_geese_position(state)[source]¶
Analyze the current position from the Geese’s perspective.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
LangGraph command with geese analysis updates
- Return type:
Command
- analyze_player1(state)[source]¶
Analyze position for player 1 (fox).
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
State updates with analysis
- Return type:
Dict[str, Any]
- analyze_player2(state)[source]¶
Analyze position for player 2 (geese).
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
State updates with analysis
- Return type:
Dict[str, Any]
- extract_move(response, piece_type='fox')[source]¶
Extract move from engine response.
- Parameters:
response (Any) – Response from the engine
piece_type (str) – Type of piece making the move (‘fox’ or ‘goose’)
- Returns:
Parsed move object
- Return type:
- initialize_game(state)[source]¶
Initialize a new Fox and Geese game.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Input state (ignored for initialization)
- Returns:
State updates for the new game
- Return type:
Dict[str, Any]
- make_fox_move(state)[source]¶
Make a move for the fox.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
Updated game state after the move
- Return type:
- make_geese_move(state)[source]¶
Make a move for the geese.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
Updated game state after the move
- Return type:
- make_player1_move(state)[source]¶
Make a move for player 1 (fox).
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
State updates after the move
- Return type:
Dict[str, Any]
- make_player2_move(state)[source]¶
Make a move for player 2 (geese).
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
State updates after the move
- Return type:
Dict[str, Any]
- prepare_analysis_context(state, player)[source]¶
Prepare context for position analysis.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
player (str) – The player for whom to prepare the analysis context
- Returns:
The context dictionary for position analysis
- Return type:
Dict[str, Any]
- prepare_move_context(state, player)[source]¶
Prepare context for move generation.
- Parameters:
state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
player (str) – The player making the move (‘fox’ or ‘geese’)
- Returns:
Context dictionary for move generation
- Return type:
Dict[str, Any]
- run(input_data=None, **kwargs)[source]¶
Run the Fox and Geese game.
- Parameters:
input_data (dict[str, Any] | haive.games.fox_and_geese.state.FoxAndGeeseState | None) – Optional input data for the game (state dict or FoxAndGeeseState)
**kwargs – Additional arguments (e.g., thread_id)
- Returns:
The final game state as a dictionary
- Return type:
- run_game(visualize=True)[source]¶
Run the full Fox and Geese game, optionally visualizing each step.
- Parameters:
visualize (bool) – Whether to visualize the game state
- Returns:
Final game state after completion
- Return type:
- run_game_with_ui(delay=2.0)[source]¶
Run the full Fox and Geese game with UI visualization.
- Parameters:
delay (float) – Delay between moves in seconds
- Returns:
Final game state after completion
- Return type:
- setup_workflow()[source]¶
Set up the game workflow.
Creates a dynamic graph with nodes for game initialization, move making, and analysis. Uses the base GameAgent workflow pattern.
- Return type:
None
- should_continue_game(state)[source]¶
Determine if the game should continue.
- Parameters:
state (dict | haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state (dict or FoxAndGeeseState)
- Returns:
True if the game should continue, False otherwise
- Return type:
- haive.games.fox_and_geese.agent.ensure_game_state(state_input)[source]¶
Ensure input is converted to FoxAndGeeseState.
- Parameters:
state_input (dict[str, Any] | haive.games.fox_and_geese.state.FoxAndGeeseState) – State input as dict or FoxAndGeeseState
- Returns:
FoxAndGeeseState instance
- Return type: