haive.games.dominoes.rich_ui¶
Enhanced Rich UI module for Dominoes game visualization.
This module provides an enhanced rich console UI for visualizing the Dominoes game, with better styling, clearer representation of dominoes, and improved game animations.
Classes¶
Enhanced Rich UI for Dominoes game visualization. |
Module Contents¶
- class haive.games.dominoes.rich_ui.DominoesRichUI(console=None)[source]¶
Enhanced Rich UI for Dominoes game visualization.
This class provides a visually appealing terminal UI for Dominoes games, with styled components, animations, and comprehensive game information.
- Features:
Beautiful domino tile visualization with ASCII art
Game board with clear indication of playable ends
Player hands with pip count and tile organization
Game information and score tracking
Move history and player analysis
Thinking animations and move visualizations
- console¶
Rich console for output
- Type:
Console
- layout¶
Layout manager for UI components
- Type:
Layout
Examples
>>> ui = DominoesRichUI() >>> state = DominoesState.initialize() >>> ui.display_state(state) # Display the initial game state
Initialize the UI.
- Parameters:
console (rich.console.Console | None) – Optional Rich console instance
- animate_move(state_before, state_after, delay=0.5)[source]¶
Animate a move being made.
Shows a smooth transition between the before and after states with visual indicators of what changed.
- Parameters:
state_before (haive.games.dominoes.state.DominoesState) – Game state before the move
state_after (haive.games.dominoes.state.DominoesState) – Game state after the move
delay (float) – Delay in seconds for the animation
- Returns:
None
- Return type:
None
- create_analysis_panel(game_state)[source]¶
Create a panel showing the latest analysis.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
- Returns:
Rich panel with analysis info
- Return type:
rich.panel.Panel
- create_board_panel(game_state)[source]¶
Create a visual representation of the dominoes board.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
- Returns:
Rich panel representing the board
- Return type:
rich.panel.Panel
- create_domino_tile_art(tile, open_end=False)[source]¶
Create ASCII art representation of a domino tile.
- Parameters:
tile (haive.games.dominoes.models.DominoTile) – The domino tile to represent
open_end (bool) – Whether this tile is at an open end of the board
- Returns:
Rich Text object with tile representation
- Return type:
rich.text.Text
- create_game_info_panel(game_state)[source]¶
Create a panel with game information.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
- Returns:
Rich panel with game info
- Return type:
rich.panel.Panel
- create_layout(game_state)[source]¶
Create the complete rich UI layout.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
- Returns:
Complete rich layout
- Return type:
rich.layout.Layout
- create_move_history_panel(game_state)[source]¶
Create a panel showing move history.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
- Returns:
Rich panel with move history
- Return type:
rich.panel.Panel
- create_player_hand_panel(game_state, player)[source]¶
Create a panel showing a player’s hand.
- Parameters:
game_state (haive.games.dominoes.state.DominoesState) – Current game state
player (str) – Player whose hand to display
- Returns:
Rich panel with player’s hand
- Return type:
rich.panel.Panel
- display_final_results(final_state)[source]¶
Display final game results.
- Parameters:
final_state (Any) – Final game state
- Return type:
None
- display_game_with_animation(state_sequence, delay=1.0)[source]¶
Display a sequence of game states with smooth transitions.
This is useful for replaying a game or showing a sequence of moves with visual transitions between states.
- Parameters:
state_sequence (list[haive.games.dominoes.state.DominoesState]) – List of game states in sequence
delay (float) – Delay in seconds between states
- Returns:
None
- Return type:
None
- display_state(state_data)[source]¶
Display the game state using rich UI.
- Parameters:
state_data (Any) – State data in various formats
- Returns:
True if display was successful, False otherwise
- Return type:
- extract_game_state(state_data)[source]¶
Extract DominoesState from various input formats.
- Parameters:
state_data (Any) – State data in various formats
- Returns:
DominoesState instance or None if extraction fails
- Return type:
- run_game_with_ui(agent, delay=1.0)[source]¶
Run a complete game with UI visualization.
This method handles the entire game flow, including initialization, move animation, and final results display.
- Parameters:
agent – The game agent that manages the game logic
delay (float) – Delay in seconds between game states
- Returns:
Final game state
- Return type:
- show_move(move, player)[source]¶
Display a move being made.
Shows a formatted message indicating which player made which move, whether it’s playing a tile or passing.
- Parameters:
move (Union[DominoMove, str]) – The move being made (“pass” or DominoMove)
player (str) – Player making the move (“player1” or “player2”)
- Returns:
None
- Return type:
None