haive.games.fox_and_geese.agent =============================== .. py:module:: haive.games.fox_and_geese.agent .. autoapi-nested-parse:: 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 ------- .. autoapisummary:: haive.games.fox_and_geese.agent.FoxAndGeeseAgent Functions --------- .. autoapisummary:: haive.games.fox_and_geese.agent.ensure_game_state Module Contents --------------- .. py:class:: FoxAndGeeseAgent(config = FoxAndGeeseConfig()) Bases: :py:obj:`haive.games.framework.base.agent.GameAgent`\ [\ :py:obj:`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. :param config: The configuration for the Fox and Geese game. :type config: FoxAndGeeseConfig .. py:method:: analyze_fox_position(state) Analyze the current position from the Fox's perspective. :param state: Current game state :returns: LangGraph command with fox analysis updates :rtype: Command .. py:method:: analyze_geese_position(state) Analyze the current position from the Geese's perspective. :param state: Current game state :returns: LangGraph command with geese analysis updates :rtype: Command .. py:method:: analyze_player1(state) Analyze position for player 1 (fox). :param state: Current game state :returns: State updates with analysis :rtype: Dict[str, Any] .. py:method:: analyze_player2(state) Analyze position for player 2 (geese). :param state: Current game state :returns: State updates with analysis :rtype: Dict[str, Any] .. py:method:: extract_move(response, piece_type = 'fox') Extract move from engine response. :param response: Response from the engine :param piece_type: Type of piece making the move ('fox' or 'goose') :returns: Parsed move object :rtype: FoxAndGeeseMove .. py:method:: initialize_game(state) Initialize a new Fox and Geese game. :param state: Input state (ignored for initialization) :returns: State updates for the new game :rtype: Dict[str, Any] .. py:method:: make_fox_move(state) Make a move for the fox. :param state: Current game state :returns: Updated game state after the move :rtype: FoxAndGeeseState .. py:method:: make_geese_move(state) Make a move for the geese. :param state: Current game state :returns: Updated game state after the move :rtype: FoxAndGeeseState .. py:method:: make_player1_move(state) Make a move for player 1 (fox). :param state: Current game state :returns: State updates after the move :rtype: Dict[str, Any] .. py:method:: make_player2_move(state) Make a move for player 2 (geese). :param state: Current game state :returns: State updates after the move :rtype: Dict[str, Any] .. py:method:: prepare_analysis_context(state, player) Prepare context for position analysis. :param state: Current game state :param player: The player for whom to prepare the analysis context :returns: The context dictionary for position analysis :rtype: Dict[str, Any] .. py:method:: prepare_move_context(state, player) Prepare context for move generation. :param state: Current game state :param player: The player making the move ('fox' or 'geese') :returns: Context dictionary for move generation :rtype: Dict[str, Any] .. py:method:: run(input_data = None, **kwargs) Run the Fox and Geese game. :param input_data: Optional input data for the game (state dict or FoxAndGeeseState) :param \*\*kwargs: Additional arguments (e.g., thread_id) :returns: The final game state as a dictionary .. py:method:: run_game(visualize = True) Run the full Fox and Geese game, optionally visualizing each step. :param visualize: Whether to visualize the game state :returns: Final game state after completion :rtype: FoxAndGeeseState .. py:method:: run_game_with_ui(delay = 2.0) Run the full Fox and Geese game with UI visualization. :param delay: Delay between moves in seconds :returns: Final game state after completion :rtype: FoxAndGeeseState .. py:method:: 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. .. py:method:: should_continue_game(state) Determine if the game should continue. :param state: Current game state (dict or FoxAndGeeseState) :returns: True if the game should continue, False otherwise :rtype: bool .. py:function:: ensure_game_state(state_input) Ensure input is converted to FoxAndGeeseState. :param state_input: State input as dict or FoxAndGeeseState :returns: FoxAndGeeseState instance