haive.games.connect4.ui¶

Connect4 rich UI visualization module.

This module provides a visually appealing terminal UI for Connect4 games, with styled components, animations, and comprehensive game information.

It uses the Rich library to create a console-based UI with:
  • Colorful board display with piece symbols

  • Move history panel

  • Game status and information

  • Position analysis display

  • Move and thinking animations

Example

>>> from haive.games.connect4.ui import Connect4UI
>>> from haive.games.connect4.state import Connect4State
>>>
>>> ui = Connect4UI()
>>> state = Connect4State.initialize()
>>> ui.display_state(state)  # Display the initial board
>>>
>>> # Show thinking animation for player move
>>> ui.show_thinking("red")
>>>
>>> # Display a move
>>> from haive.games.connect4.models import Connect4Move
>>> move = Connect4Move(column=3)
>>> ui.show_move(move, "red")

Classes¶

Connect4UI

Rich UI for beautiful Connect4 game visualization.

Module Contents¶

class haive.games.connect4.ui.Connect4UI[source]¶

Rich UI for beautiful Connect4 game visualization.

This class provides a visually appealing terminal UI for Connect4 games, with styled components, animations, and comprehensive game information.

Features:
  • Colorful board display with piece symbols

  • Move history panel

  • Game status and information

  • Position analysis display

  • Move and thinking animations

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 = Connect4UI()
>>> state = Connect4State.initialize()
>>> ui.display_state(state)  # Display the initial board

Initialize the Connect4 UI with default settings.

display_state(state)[source]¶

Display the current game state with rich formatting.

Renders the complete game state including board, game info, analysis, and move history in a formatted layout.

Parameters:

state (Union[Connect4State, dict]) – Current game state (Connect4State or dict)

Returns:

None

Return type:

None

Example

>>> ui = Connect4UI()
>>> state = Connect4State.initialize()
>>> ui.display_state(state)
show_game_over(winner=None)[source]¶

Display game over message with result.

Shows a game over panel with the winner highlighted in their color, or indicating a draw if there’s no winner.

Parameters:

winner (Optional[str], optional) – Winning player or None for a draw. Defaults to None.

Returns:

None

Return type:

None

Example

>>> ui = Connect4UI()
>>> ui.show_game_over("red")  # Red player wins
>>> ui.show_game_over(None)   # Draw
show_move(move, player)[source]¶

Display a move animation.

Shows a formatted message indicating which player made which move, with color-coded player name and piece symbol.

Parameters:
  • move (Connect4Move) – The move being made

  • player (str) – Player making the move (“red” or “yellow”)

Returns:

None

Return type:

None

Example

>>> ui = Connect4UI()
>>> move = Connect4Move(column=3)
>>> ui.show_move(move, "red")
show_thinking(player, message='Thinking...')[source]¶

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 (“red” or “yellow”)

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

Returns:

None

Return type:

None

Example

>>> ui = Connect4UI()
>>> ui.show_thinking("red", "Analyzing position...")