haive.games.mastermind.ui¶

Rich UI for the Mastermind game.

This module provides a rich terminal UI for the Mastermind game using the Rich library. It displays the game board, guesses, feedback, and analysis in a visually appealing way.

Classes¶

MastermindUI

Rich terminal UI for the Mastermind game.

Module Contents¶

class haive.games.mastermind.ui.MastermindUI(console=None)[source]¶

Rich terminal UI for the Mastermind game.

This class provides methods for displaying the Mastermind game state in a visually appealing way using the Rich library.

Initialize the UI with a Rich console.

Parameters:

console (rich.console.Console | None) – Optional Rich console to use. If not provided, a new one is created.

color_to_styled_text(color)[source]¶

Convert a color name to a styled text object.

Parameters:

color (str) – The name of the color.

Returns:

A Rich Text object with appropriate styling for the color.

Return type:

rich.text.Text

create_analysis_panel(state)[source]¶

Create a panel with the most recent analysis if available.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The current game state.

Returns:

A Rich Panel object containing analysis information, or None if no analysis available.

Return type:

rich.panel.Panel | None

create_guesses_table(state)[source]¶

Create a table displaying all guesses and their feedback.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The current game state.

Returns:

A Rich Table object containing the guesses and feedback.

Return type:

rich.table.Table

create_info_panel(state)[source]¶

Create a panel with game information.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The current game state.

Returns:

A Rich Panel object containing game information.

Return type:

rich.panel.Panel

create_layout(state)[source]¶

Create a complete layout for the game state.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The current game state.

Returns:

A Rich Layout object containing all game UI components.

Return type:

rich.layout.Layout

display_final_results(state)[source]¶

Display the final results of the game.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The final game state.

display_game_state(state)[source]¶

Display the current game state.

Parameters:

state (haive.games.mastermind.state.MastermindState) – The current game state.

display_welcome()[source]¶

Display a welcome message for the Mastermind game.

extract_game_state(state_dict)[source]¶

Extract a MastermindState from a state dictionary.

Parameters:

state_dict (dict[str, Any]) – The state dictionary to convert.

Returns:

A MastermindState object, or None if conversion fails.

Return type:

haive.games.mastermind.state.MastermindState | None

print_debug_info(data, label='Debug')[source]¶

Print debug information.

Parameters:
  • data (Any) – The data to print.

  • label (str) – A label for the debug panel.