haive.games.go.agent¶

Go game agent implementation.

This module provides a Go game agent that supports:
  • Standard Go game rules and mechanics

  • Black and white player moves

  • Optional position analysis

  • Game state tracking and visualization

  • SGF format support via sente library

Example

>>> from haive.games.go import GoAgent, GoAgentConfig
>>>
>>> # Create a Go agent with analysis enabled
>>> config = GoAgentConfig(include_analysis=True)
>>> agent = GoAgent(config)
>>>
>>> # Run a game
>>> run_go_game(agent)

Classes¶

GoAgent

Go game agent implementation.

Functions¶

run_go_game(agent)

Run a Go game with visualization and structured output.

Module Contents¶

class haive.games.go.agent.GoAgent(config)[source]¶

Bases: haive.core.engine.agent.agent.Agent[haive.games.go.config.GoAgentConfig]

Go game agent implementation.

This class provides the core functionality for playing Go games, including:
  • Move generation for both black and white players

  • Position analysis and evaluation

  • Game state management and validation

  • Workflow control for game progression

config¶

Configuration for the Go agent

Type:

GoAgentConfig

engines¶

LLM engines for players and analysis

Type:

Dict[str, Any]

graph¶

Game workflow graph

Type:

StateGraph

Example

>>> config = GoAgentConfig(
...     include_analysis=True,
...     board_size=19
... )
>>> agent = GoAgent(config)
>>> run_go_game(agent)

Initialize the Go agent.

Parameters:

config (GoAgentConfig) – Configuration for the Go agent.

analyze_black_position(state)[source]¶

Analyze black’s position if analysis is enabled.

Parameters:

state (GoGameState) – Current game state.

Returns:

Command to update the game state with black’s analysis.

Return type:

Command

analyze_position(state, color)[source]¶

Analyze the current position for a player.

Parameters:
  • state (GoGameState) – Current game state.

  • color (str) – Player color (“black” or “white”).

Returns:

Command to update the game state with the analysis.

Return type:

Command

Raises:

ValueError – If no LLM engine is found for analysis.

Notes

  • Maintains a history of the last 4 analyses

  • Provides territory evaluation and strategic advice

  • Identifies strong and weak positions

analyze_white_position(state)[source]¶

Analyze white’s position if analysis is enabled.

Parameters:

state (GoGameState) – Current game state.

Returns:

Command to update the game state with white’s analysis.

Return type:

Command

check_game_status(state)[source]¶

Check and update the Go game status.

Parameters:

state (GoGameState) – Current game state.

Returns:

Command to update the game status.

Return type:

Command

Notes

  • Uses sente library to validate game state

  • Detects game end conditions (resignation, passes)

  • Updates status to “ended” when game is complete

initialize_game(state=None)[source]¶

Initialize a new game of Go.

Parameters:

state (Optional[GoGameState]) – Optional initial state. If None, creates a new game with standard settings.

Returns:

Command to update the game state with initial settings.

Return type:

Command

make_black_move(state)[source]¶

Handle black’s move in the game.

Parameters:

state (GoGameState) – Current game state.

Returns:

Command to update the game state with black’s move.

Return type:

Command

make_move(state, color)[source]¶

Execute a move for the given player.

Parameters:
  • state (GoGameState) – Current game state.

  • color (str) – Player color (“black” or “white”).

Returns:

Command to update the game state with the new move.

Return type:

Command

Raises:

ValueError – If no LLM engine is found for the player.

Notes

  • Provides the last 5 moves as context to the LLM

  • Includes recent position analysis if available

  • Validates moves through the state manager

make_white_move(state)[source]¶

Handle white’s move in the game.

Parameters:

state (GoGameState) – Current game state.

Returns:

Command to update the game state with white’s move.

Return type:

Command

setup_workflow()[source]¶

Define the Go game workflow.

Sets up the game flow graph with nodes for:
  • Game initialization

  • Black and white moves

  • Position analysis (if enabled)

  • Game status checks

The workflow supports two main paths:
  1. Basic: Initialize -> Black Move -> White Move -> Repeat

  2. With Analysis: Initialize -> Black Move -> Black Analysis -> White Move -> White Analysis -> Repeat

Return type:

None

should_continue_game(state)[source]¶

Determine if the game should continue.

Parameters:

state (GoGameState) – Current game state.

Returns:

True if game is ongoing, False otherwise.

Return type:

bool

haive.games.go.agent.run_go_game(agent)[source]¶

Run a Go game with visualization and structured output.

This function manages the game loop and provides rich visualization of the game state, including:

  • Board visualization using ASCII art

  • Move history tracking

  • Position analysis display

  • Captured stones counting

  • Game status updates

Parameters:

agent (GoAgent) – The Go agent to run the game with.

Return type:

None

Example

>>> agent = GoAgent(GoAgentConfig(include_analysis=True))
>>> run_go_game(agent)

🔷 Current Board Position: … … … … … … . . + … + . . … … … … . + … . … … … . . + … + . . … … … … … …

🎮 Current Player: Black 📌 Game Status: ongoing ————————————————–