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

CheckersUI

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

colors

Color schemes for different UI elements

Type:

dict

pieces

Unicode symbols for different piece types

Type:

dict

game_log

Log of game events

Type:

List[str]

move_count

Counter for moves

Type:

int

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
show_thinking(player)

Show thinking animation.

Displays a spinner animation while a player is thinking about a move.

Parameters:

player (str) – Player who is thinking (“red” or “black”)

Examples

>>> ui = CheckersUI()
>>> ui.show_thinking("red")  # Shows a spinner for red's thinking