games.connect4.agent¶

Agent for playing Connect 4.

This module defines the Connect 4 agent, which uses language models to generate moves and analyze positions in the game.

Classes¶

Connect4Agent

Agent for playing Connect 4.

Module Contents¶

class games.connect4.agent.Connect4Agent(config)¶

Bases: haive.games.framework.base.agent.GameAgent[haive.games.connect4.config.Connect4AgentConfig]

Agent for playing Connect 4.

This class implements the Connect 4 agent, which uses language models to generate moves and analyze positions in the game.

Init .

Parameters:

config (haive.games.connect4.config.Connect4AgentConfig) – [TODO: Add description]

analyze_player1(state)¶

Analyze position for the red player.

This method analyzes the position for the red player in the current game state.

Parameters:

state (haive.games.connect4.state.Connect4State)

Return type:

langgraph.types.Command

analyze_player2(state)¶

Analyze position for the yellow player.

This method analyzes the position for the yellow player in the current game state.

Parameters:

state (haive.games.connect4.state.Connect4State)

Return type:

langgraph.types.Command

extract_move(response)¶

Extract move from engine response.

This method extracts the move from the engine response.

Parameters:

response (haive.games.connect4.models.Connect4PlayerDecision)

Return type:

haive.games.connect4.models.Connect4Move

make_player1_move(state)¶

Make a move for the red player.

This method makes a move for the red player in the current game state.

Parameters:

state (haive.games.connect4.state.Connect4State)

Return type:

langgraph.types.Command

make_player2_move(state)¶

Make a move for the yellow player.

This method makes a move for the yellow player in the current game state.

Parameters:

state (haive.games.connect4.state.Connect4State)

Return type:

langgraph.types.Command

prepare_analysis_context(state, player)¶

Prepare context for position analysis with correct variables.

This method prepares the context for position analysis by calculating threats and formatting the required fields.

Parameters:
Return type:

dict[str, Any]

prepare_move_context(state, player)¶

Prepare context for move generation.

This method prepares the context for move generation by formatting the legal moves and getting the player’s last analysis.

Parameters:
Return type:

dict[str, Any]

visualize_state(state)¶

Visualize the current game state with better formatting and insights.

This method visualizes the current game state with better formatting and insights. It displays the current player, game status, board, last move, and analysis from the previous turn.

Parameters:

state (dict[str, Any])

Return type:

None