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¶

DominoesRichUI

Enhanced Rich UI for Dominoes game visualization.

Module Contents¶

class games.dominoes.rich_ui.DominoesRichUI(console=None)¶

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

colors¶

Color schemes for different UI elements

Type:

dict

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)¶

Animate a move being made.

Shows a smooth transition between the before and after states with visual indicators of what changed.

Parameters:
Returns:

None

Return type:

None

create_analysis_panel(game_state)¶

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)¶

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)¶

Create ASCII art representation of a domino tile.

Parameters:
Returns:

Rich Text object with tile representation

Return type:

rich.text.Text

create_game_info_panel(game_state)¶

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)¶

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)¶

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)¶

Create a panel showing a player’s hand.

Parameters:
Returns:

Rich panel with player’s hand

Return type:

rich.panel.Panel

display_final_results(final_state)¶

Display final game results.

Parameters:

final_state (Any) – Final game state

Return type:

None

display_game_with_animation(state_sequence, delay=1.0)¶

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:
Returns:

None

Return type:

None

display_state(state_data)¶

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:

bool

display_welcome()¶

Display welcome message.

Return type:

None

extract_game_state(state_data)¶

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:

haive.games.dominoes.state.DominoesState | None

run_game_with_ui(agent, delay=1.0)¶

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:

haive.games.dominoes.state.DominoesState

show_move(move, player)¶

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

show_thinking(player, message='Thinking...')¶

Display a thinking animation for the current player.

Shows a spinner animation with player-colored text to indicate that the player is thinking about their move.

Parameters:
  • player (str) – Current player (“player1” or “player2”)

  • message (str, optional) – Custom message to display. Defaults to “Thinking…”.

Returns:

None

Return type:

None