games.framework.base.template_generator

Template generator for game agents (EXPERIMENTAL).

This experimental module provides a template generator for creating new game implementations. It automates the creation of boilerplate code and ensures consistency across different game implementations.

Warning

This module is experimental and its API may change without notice. Use with caution in production environments.

Example

>>> # Create templates for a new chess game
>>> generator = GameTemplateGenerator(
...     game_name="Chess",
...     player1_name="white",
...     player2_name="black",
...     enable_analysis=True
... )
>>> generator.generate_templates()
Typical usage:
  • Initialize the generator with game details

  • Generate all template files at once

  • Customize the generated code for your specific game

Classes

GameTemplateGenerator

Experimental template generator for new board game implementations.

Module Contents

class games.framework.base.template_generator.GameTemplateGenerator(game_name, player1_name='player1', player2_name='player2', enable_analysis=True)

Experimental template generator for new board game implementations.

This class automates the creation of boilerplate code for implementing new board games within the framework. It generates a complete set of files with proper structure, documentation, and type hints.

Warning

This class is experimental and its API may change without notice. Generated code may need manual adjustments for specific games.

game_name

The name of the game (used for class names).

Type:

str

player1_name

Name for player 1.

Type:

str

player2_name

Name for player 2.

Type:

str

enable_analysis

Whether to include analysis in templates.

Type:

bool

game_slug

Slugified version of the game name for file paths.

Type:

str

game_class_name

CamelCase version of game name for class names.

Type:

str

base_dir

Base directory for generated files.

Type:

str

Example

>>> generator = GameTemplateGenerator("Tic Tac Toe")
>>> generator.generate_templates()
✅ Generated template files for Tic Tac Toe in src/haive/agents/agent_games/tic_tac_toe

Initialize the template generator.

Parameters:
  • game_name (str) – The name of the game (used for class names).

  • player1_name (str, optional) – Name for player 1. Defaults to “player1”.

  • player2_name (str, optional) – Name for player 2. Defaults to “player2”.

  • enable_analysis (bool, optional) – Whether to include analysis in templates. Defaults to True.

Example

>>> generator = GameTemplateGenerator(
...     game_name="Chess",
...     player1_name="white",
...     player2_name="black"
... )
generate_templates(output_dir=None)

Generate all template files for the game.

This method creates a complete set of files needed for a new game implementation, including models, state management, configuration, and example usage.

Parameters:

output_dir (str, optional) – Optional directory to write files to. If not provided, uses the standard package structure.

Return type:

None

Example

>>> generator = GameTemplateGenerator("Chess")
>>> # Generate in default location
>>> generator.generate_templates()
>>> # Generate in custom location
>>> generator.generate_templates("my_games/chess")