games.fox_and_geese.rich_ui¶
Enhanced Rich UI module for Fox and Geese game visualization.
This module provides an enhanced rich console UI for visualizing the Fox and Geese game, with better styling, animated piece movements, and improved game information display.
Classes¶
Enhanced Rich UI for Fox and Geese game visualization. |
Module Contents¶
- class games.fox_and_geese.rich_ui.FoxAndGeeseRichUI(console=None)¶
Enhanced Rich UI for Fox and Geese game visualization.
This class provides a visually appealing terminal UI for Fox and Geese games, with styled components, animations, and comprehensive game information.
- Features:
Beautiful game board visualization with colored squares
Animated piece movements for fox and geese
Detailed game statistics and turn information
Move history tracking with visual indicators
Analysis visualization for both fox and geese strategies
Thinking animations and move highlights
- console¶
Rich console for output
- Type:
Console
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:
state_before (haive.games.fox_and_geese.state.FoxAndGeeseState) – Game state before the move
state_after (haive.games.fox_and_geese.state.FoxAndGeeseState) – State after the move
delay (float) – Delay in seconds for the animation
- Returns:
None
- Return type:
None
- create_analysis_panel(game_state)¶
Create an enhanced panel showing the latest analysis.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
Rich panel with detailed analysis
- Return type:
rich.panel.Panel
- create_board_table(game_state, highlight_positions=None, capture_position=None)¶
Create an enhanced visual representation of the board.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
highlight_positions (set[haive.games.fox_and_geese.models.FoxAndGeesePosition] | None) – Optional positions to highlight (for showing moves)
capture_position (haive.games.fox_and_geese.models.FoxAndGeesePosition | None) – Optional position to highlight as a capture
- Returns:
Rich table representing the board
- Return type:
rich.table.Table
- create_game_info_panel(game_state)¶
Create an enhanced panel with game information.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
Rich panel with detailed game info
- Return type:
rich.panel.Panel
- create_layout(game_state, highlight_positions=None, capture_position=None, legal_moves=None)¶
Create the enhanced complete rich UI layout.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
highlight_positions (set[haive.games.fox_and_geese.models.FoxAndGeesePosition] | None) – Optional positions to highlight
capture_position (haive.games.fox_and_geese.models.FoxAndGeesePosition | None) – Optional position being captured
legal_moves (list[haive.games.fox_and_geese.models.FoxAndGeeseMove] | None) – Optional list of legal moves
- Returns:
Complete rich layout
- Return type:
rich.layout.Layout
- create_legal_moves_panel(game_state, legal_moves=None)¶
Create a panel showing legal moves for the current player.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
legal_moves (list[haive.games.fox_and_geese.models.FoxAndGeeseMove] | None) – Optional list of legal moves
- Returns:
Rich panel with legal moves info
- Return type:
rich.panel.Panel
- create_move_history_panel(game_state)¶
Create an enhanced panel showing move history.
- Parameters:
game_state (haive.games.fox_and_geese.state.FoxAndGeeseState) – Current game state
- Returns:
Rich panel with detailed move history
- Return type:
rich.panel.Panel
- display_final_results(final_state)¶
Display enhanced 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:
state_sequence (list[haive.games.fox_and_geese.state.FoxAndGeeseState]) – List of game states in sequence
delay (float) – Delay in seconds between states
- Returns:
None
- Return type:
None
- display_state(state_data, highlight_positions=None, capture_position=None, legal_moves=None)¶
Display the game state using enhanced rich UI.
- Parameters:
state_data (Any) – State data in various formats
highlight_positions (set[haive.games.fox_and_geese.models.FoxAndGeesePosition] | None) – Optional positions to highlight
capture_position (haive.games.fox_and_geese.models.FoxAndGeesePosition | None) – Optional position being captured
legal_moves (list[haive.games.fox_and_geese.models.FoxAndGeeseMove] | None) – Optional list of legal moves
- Returns:
True if display was successful, False otherwise
- Return type:
- display_welcome()¶
Display welcome message.
- Return type:
None
- extract_game_state(state_data)¶
Extract FoxAndGeeseState from various input formats.
- Parameters:
state_data (Any) – State data in various formats
- Returns:
FoxAndGeeseState instance or None if extraction fails
- Return type:
- run_fox_and_geese_game(agent, delay=1.0)¶
Run a complete Fox and Geese 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, state_before, state_after)¶
Display an animated move being made.
Shows the move with highlighting of the relevant positions.
- Parameters:
move (haive.games.fox_and_geese.models.FoxAndGeeseMove) – The move being made
state_before (haive.games.fox_and_geese.state.FoxAndGeeseState) – State before the move
state_after (haive.games.fox_and_geese.state.FoxAndGeeseState) – State after the move
- 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.