games.checkers.ui¶
Checkers game UI module.
- This module provides a rich text-based UI for the checkers game, including:
Beautiful board visualization with colors
Game information display
Move history tracking
Captured pieces visualization
Position analysis display
Game status and winner announcements
Move and thinking animations
The UI uses the rich library to create a visually appealing terminal interface that makes the game more engaging and easier to follow.
Classes¶
Rich UI for beautiful checkers game visualization. |
Module Contents¶
- class games.checkers.ui.CheckersUI¶
Rich UI for beautiful checkers game visualization.
This class provides a visually appealing terminal UI for checkers games, with styled components, animations, and comprehensive game information.
- Features:
Colorful board display with piece symbols
Move history panel
Captured pieces tracking
Game status and information
Position analysis display
Move and thinking animations
Game over screen
- console¶
Rich console for output
- Type:
Console
- layout¶
Layout manager for UI components
- Type:
Layout
- start_time¶
Game start time
- Type:
datetime
Examples
>>> ui = CheckersUI() >>> state = CheckersState.initialize() >>> ui.display_state(state) # Display the initial board >>> >>> # Show thinking animation during move generation >>> ui.show_thinking("red") >>> >>> # Display a move >>> move = CheckersMove(from_position="a3", to_position="b4", player="red") >>> ui.show_move(move)
Initialize the checkers UI.
Sets up the console, layout, color schemes, piece symbols, and tracking variables for the UI.
- display_state(state, message='')¶
Display the complete game state.
Updates and displays all UI components with the current game state.
- Parameters:
state (CheckersState) – Current game state
message (str, optional) – Custom message for the footer. Defaults to “”.
Examples
>>> ui = CheckersUI() >>> state = CheckersState.initialize() >>> ui.display_state(state) >>> >>> # Display with a custom message >>> ui.display_state(state, "Red is thinking...")
- show_game_over(state)¶
Show game over screen.
Displays a game over message with the winner when the game ends.
- Parameters:
state (CheckersState) – Final game state
Examples
>>> ui = CheckersUI() >>> state = CheckersState(game_status="game_over", winner="red") >>> ui.show_game_over(state) # Shows "RED WINS!" message
- show_move(move)¶
Show move animation.
Displays a brief animation/message when a move is made.
- Parameters:
move (CheckersMove) – The move that was made
Examples
>>> ui = CheckersUI() >>> move = CheckersMove(from_position="a3", to_position="b4", player="red") >>> ui.show_move(move) # Shows move message