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¶
Rich terminal UI for the Mastermind game. |
Module Contents¶
- class games.mastermind.ui.MastermindUI(console=None)¶
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)¶
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)¶
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)¶
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)¶
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)¶
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)¶
Display the final results of the game.
- Parameters:
state (haive.games.mastermind.state.MastermindState) – The final game state.
- display_game_state(state)¶
Display the current game state.
- Parameters:
state (haive.games.mastermind.state.MastermindState) – The current game state.
- display_welcome()¶
Display a welcome message for the Mastermind game.
- extract_game_state(state_dict)¶
Extract a MastermindState from a state dictionary.