haive.games.dominoes.state¶
Comprehensive state management system for Dominoes gameplay and strategic analysis.
This module provides sophisticated state models for Dominoes games with complete support for tile tracking, board management, strategic analysis, and game flow control. The state system maintains both traditional dominoes mechanics and advanced strategic context for AI decision-making.
The state system supports: - Complete tile tracking with hand and boneyard management - Strategic analysis history for multiplayer gameplay - Board state validation and move legality checking - Game progression tracking with pass and block detection - Performance metrics and statistical analysis - Multiple game variants and scoring systems
Examples
Creating a new game state:
state = DominoesState.initialize(
player_names=["player1", "player2"],
tiles_per_hand=7
)
assert state.turn in ["player1", "player2"]
assert state.game_status == "ongoing"
Accessing game information:
# Check board state
left_open = state.left_value
right_open = state.right_value
board_display = state.board_string
# Check hand sizes
hand_sizes = state.hand_sizes
tiles_remaining = state.boneyard_size
Tracking strategic analysis:
analysis = DominoesAnalysis(
hand_strength="Strong high-value tiles",
blocking_opportunities=["Block 5-5 connection"],
optimal_plays=["Play 6-4 on right end"],
endgame_strategy="Hold doubles for scoring"
)
state.add_analysis(analysis, "player1")
Game state queries:
# Check game completion
if state.is_game_over():
winner = state.winner
final_scores = state.scores
# Strategic position analysis
playable_tiles = state.get_playable_tiles("player1")
board_control = state.board_control_analysis
Note
All state models use Pydantic for validation and support both JSON serialization and integration with LangGraph for distributed gameplay.
Classes¶
Comprehensive state management for Dominoes gameplay with strategic analysis. |
Module Contents¶
- class haive.games.dominoes.state.DominoesState(/, **data)[source]¶
Bases:
haive.games.framework.base.state.GameState
Comprehensive state management for Dominoes gameplay with strategic analysis. support.
This class provides complete state management for Dominoes games, supporting both traditional dominoes mechanics and strategic analysis. The state system maintains tile tracking, board management, strategic context, and performance metrics for advanced AI decision-making and game analysis.
The state system supports: - Complete tile tracking with hand and boneyard management - Strategic analysis history for multiplayer gameplay with learning capability - Board state validation and move legality checking - Game progression tracking with pass and block detection - Performance metrics and statistical analysis for gameplay optimization - Multiple game variants and scoring systems
The game follows traditional dominoes rules: - Each player starts with 7 tiles (configurable) - Players take turns placing tiles that match board ends - Game ends when a player plays all tiles or board is blocked - Scoring typically based on remaining tiles in opponents’ hands
- Parameters:
data (Any)
- players¶
List of player names in turn order. Maintains consistent ordering for gameplay flow.
- Type:
List[str]
- hands¶
Current tiles in each player’s hand. Private information tracked for game management.
- Type:
Dict[str, List[DominoTile]]
- board¶
Tiles currently placed on the board. Represents the train/line of connected dominoes.
- Type:
List[DominoTile]
- boneyard¶
Undealt tiles available for drawing. Used when players cannot play and must draw.
- Type:
List[DominoTile]
- turn¶
Current player’s turn identifier. Cycles through players list for turn management.
- Type:
- game_status¶
Current game state with completion detection. Tracks ongoing play, wins, and draw conditions.
- Type:
Literal
- move_history¶
Complete move history. Includes both tile placements and pass actions.
- Type:
List[Union[DominoMove, Literal[“pass”]]]
- last_passes¶
Count of consecutive passes for block detection. Used to determine when board is blocked.
- Type:
- scores¶
Current scores for each player. Updated based on game variant scoring rules.
- winner¶
Winner identifier if game completed. Set when victory conditions are met.
- Type:
Optional[str]
- player1_analysis¶
Strategic analysis history for player1. Tracks reasoning and decision-making patterns.
- Type:
List[DominoesAnalysis]
- player2_analysis¶
Strategic analysis history for player2. Tracks reasoning and decision-making patterns.
- Type:
List[DominoesAnalysis]
Examples
Creating a new game state:
state = DominoesState.initialize( player_names=["Alice", "Bob"], tiles_per_hand=7 ) assert state.turn in ["Alice", "Bob"] assert len(state.players) == 2 assert all(len(hand) == 7 for hand in state.hands.values())
Accessing game information:
# Check board state left_open = state.left_value # Value that can be matched on left right_open = state.right_value # Value that can be matched on right board_display = state.board_string # Human-readable board # Check hand and boneyard sizes hand_sizes = state.hand_sizes tiles_remaining = state.boneyard_size total_tiles = state.total_tiles_in_play
Managing strategic analysis:
analysis = DominoesAnalysis( hand_strength="Strong concentration of 5s and 6s", blocking_opportunities=["Block opponent's 3-3 double"], optimal_plays=["Play 5-2 on left end for control"], endgame_strategy="Hold 6-6 double for final scoring" ) state.add_analysis(analysis, "Alice") # Access latest strategic insights latest_analysis = state.get_latest_analysis("Alice")
Game state queries:
# Check game completion if state.is_game_over(): winner = state.winner final_scores = state.scores game_summary = state.game_summary # Strategic position analysis playable_tiles = state.get_playable_tiles("Alice") board_control = state.board_control_analysis tile_distribution = state.tile_distribution_analysis
Advanced game analysis:
# Performance metrics stats = state.game_statistics print(f"Moves played: {stats['total_moves']}") print(f"Pass rate: {stats['pass_percentage']:.1f}%") # Strategic evaluation position_eval = state.position_evaluation print(f"Board control: {position_eval['board_control']}") print(f"Hand strength: {position_eval['hand_strength_analysis']}")
Note
The state uses Pydantic for validation and supports both JSON serialization and integration with LangGraph for distributed game systems. All tile operations maintain game rule consistency and strategic context.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- add_analysis(analysis, player)[source]¶
Add strategic analysis for a player.
- Parameters:
analysis (haive.games.dominoes.models.DominoesAnalysis)
player (str)
- Return type:
None
- get_latest_analysis(player)[source]¶
Get the latest analysis for a player.
- Parameters:
player (str)
- Return type:
- get_playable_tiles(player)[source]¶
Get tiles that a player can currently play.
- Parameters:
player (str)
- Return type:
- classmethod initialize(player_names=None, tiles_per_hand=7)[source]¶
Initialize a new dominoes game with proper tile distribution.
- Parameters:
- Returns:
A new game state ready to play.
- Return type:
- property board_string: str¶
Get a human-readable string representation of the board.
- Returns:
Visual representation of the domino train with connecting lines.
- Return type:
- property left_value: int | None¶
Get the value on the left end of the board that can be matched.
- Returns:
Value that can be matched on left end, None if board empty.
- Return type:
Optional[int]
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property position_evaluation: dict[str, str | int | float]¶
Generate strategic position evaluation.