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¶

ColorCode

Color code for Mastermind game.

Feedback

Feedback for a guess in Mastermind.

MastermindState

State for the Mastermind game.

MastermindUI

Rich terminal UI for the Mastermind game.

Functions¶

calculate_feedback(secret_code, guess)

Calculate feedback for a guess.

main()

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:

MastermindState

is_game_over()¶

Check if the game is over.

Return type:

bool

make_guess(guess)¶

Make a guess and get feedback.

Parameters:

guess (list[str])

Return type:

Feedback

class games.mastermind.demo.MastermindUI¶

Rich terminal UI for the Mastermind game.

Initialize the UI.

color_to_emoji(color)¶

Convert color name to emoji.

Parameters:

color (str)

Return type:

str

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:
Return type:

rich.layout.Layout

create_secret_panel(state, show_secret=False)¶

Create panel showing the secret code (or hidden).

Parameters:
Return type:

rich.panel.Panel

display_game_state(state, show_secret=False)¶

Display the current game state.

Parameters:
input_guess(available_colors)¶

Get guess input from user.

Parameters:

available_colors (list[str])

Return type:

list[str]

show_result(state)¶

Show the game result.

Parameters:

state (MastermindState)

games.mastermind.demo.calculate_feedback(secret_code, guess)¶

Calculate feedback for a guess.

Parameters:
Return type:

dict[str, int]

games.mastermind.demo.main()¶

Run the Mastermind game.