games.nim.ui¶

Rich UI implementation for the Nim game.

This module provides a Rich-based UI for visualizing and interacting with the Nim game. It includes a NimUI class that handles visualization of the game state, piles, and game information.

Classes¶

NimUI

Rich terminal UI for the Nim game.

Module Contents¶

class games.nim.ui.NimUI¶

Rich terminal UI for the Nim game.

This class provides methods for visualizing the Nim game state using the Rich library. It includes methods for displaying the game board, piles, game information, and analysis.

Initialize the UI with a Rich console if available.

create_analysis_panel(state)¶

Create a panel showing the latest analysis if available.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

A Rich panel containing analysis information, or None if no analysis.

Return type:

Optional[Panel]

create_header(state)¶

Create header panel with game info.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

A Rich panel containing the game header information.

Return type:

Panel

create_layout(state)¶

Create the complete layout for the game display.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

A Rich layout for the complete game display.

Return type:

Layout

create_moves_table(state)¶

Create a table showing move history.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

A Rich table containing the move history.

Return type:

Table

create_piles_panel(state)¶

Create a panel showing the piles of stones.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

A Rich panel containing visualizations of the piles.

Return type:

Panel

display_game_state(state)¶

Display the current game state using Rich UI or fallback text UI.

Parameters:

state (haive.games.nim.state.NimState | dict[str, Any]) – The current game state as a NimState object or dict.

prompt_for_move(state)¶

Prompt the user to input a move.

Parameters:

state (haive.games.nim.state.NimState) – The current game state.

Returns:

The move chosen by the user.

Return type:

NimMove