games.mastermind.demo¶
Standalone demo for the Mastermind game with Rich UI.
This script demonstrates the Mastermind game without requiring the full Haive framework.
Classes¶
Color code for Mastermind game. |
|
Feedback for a guess in Mastermind. |
|
State for the Mastermind game. |
|
Rich terminal UI for the Mastermind game. |
Functions¶
|
Calculate feedback for a guess. |
|
Run the Mastermind game. |
Module Contents¶
- class games.mastermind.demo.ColorCode(/, **data)¶
Bases:
pydantic.BaseModel
Color code for Mastermind game.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class games.mastermind.demo.Feedback(/, **data)¶
Bases:
pydantic.BaseModel
Feedback for a guess in Mastermind.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class games.mastermind.demo.MastermindState(/, **data)¶
Bases:
pydantic.BaseModel
State for the Mastermind game.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod initialize(secret_code=None, max_turns=10)¶
Initialize a new game state.
- Parameters:
- Return type:
- class games.mastermind.demo.MastermindUI¶
Rich terminal UI for the Mastermind game.
Initialize the UI.
- create_guesses_table(state)¶
Create table of guesses and feedback.
- Parameters:
state (MastermindState)
- Return type:
rich.table.Table
- create_header(state)¶
Create header panel with game info.
- Parameters:
state (MastermindState)
- Return type:
rich.panel.Panel
- create_layout(state, show_secret=False)¶
Create complete layout for the game.
- Parameters:
state (MastermindState)
show_secret (bool)
- Return type:
rich.layout.Layout
- create_secret_panel(state, show_secret=False)¶
Create panel showing the secret code (or hidden).
- Parameters:
state (MastermindState)
show_secret (bool)
- Return type:
rich.panel.Panel
- display_game_state(state, show_secret=False)¶
Display the current game state.
- Parameters:
state (MastermindState)
show_secret (bool)
- input_guess(available_colors)¶
Get guess input from user.
- show_result(state)¶
Show the game result.
- Parameters:
state (MastermindState)
- games.mastermind.demo.calculate_feedback(secret_code, guess)¶
Calculate feedback for a guess.
- games.mastermind.demo.main()¶
Run the Mastermind game.