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¶

FoxAndGeeseAgent

Agent for playing Fox and Geese.

Functions¶

ensure_game_state(state_input)

Ensure input is converted to FoxAndGeeseState.

Module Contents¶

class games.fox_and_geese.agent.FoxAndGeeseAgent(config=FoxAndGeeseConfig())¶

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)¶

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)¶

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)¶

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)¶

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')¶

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:

FoxAndGeeseMove

initialize_game(state)¶

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)¶

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:

FoxAndGeeseState

make_geese_move(state)¶

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:

FoxAndGeeseState

make_player1_move(state)¶

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)¶

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)¶

Prepare context for position analysis.

Parameters:
Returns:

The context dictionary for position analysis

Return type:

Dict[str, Any]

prepare_move_context(state, player)¶

Prepare context for move generation.

Parameters:
Returns:

Context dictionary for move generation

Return type:

Dict[str, Any]

run(input_data=None, **kwargs)¶

Run the Fox and Geese game.

Parameters:
Returns:

The final game state as a dictionary

Return type:

dict[str, Any]

run_game(visualize=True)¶

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:

FoxAndGeeseState

run_game_with_ui(delay=2.0)¶

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:

FoxAndGeeseState

setup_workflow()¶

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)¶

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:

bool

games.fox_and_geese.agent.ensure_game_state(state_input)¶

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:

haive.games.fox_and_geese.state.FoxAndGeeseState