haive.games.mastermind.demo =========================== .. py:module:: haive.games.mastermind.demo .. autoapi-nested-parse:: Standalone demo for the Mastermind game with Rich UI. This script demonstrates the Mastermind game without requiring the full Haive framework. Classes ------- .. autoapisummary:: haive.games.mastermind.demo.ColorCode haive.games.mastermind.demo.Feedback haive.games.mastermind.demo.MastermindState haive.games.mastermind.demo.MastermindUI Functions --------- .. autoapisummary:: haive.games.mastermind.demo.calculate_feedback haive.games.mastermind.demo.main Module Contents --------------- .. py:class:: ColorCode(/, **data) Bases: :py:obj:`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. .. py:class:: Feedback(/, **data) Bases: :py:obj:`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. .. py:class:: MastermindState(/, **data) Bases: :py:obj:`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. .. py:method:: initialize(secret_code = None, max_turns = 10) :classmethod: Initialize a new game state. .. py:method:: is_game_over() Check if the game is over. .. py:method:: make_guess(guess) Make a guess and get feedback. .. py:class:: MastermindUI Rich terminal UI for the Mastermind game. Initialize the UI. .. py:method:: color_to_emoji(color) Convert color name to emoji. .. py:method:: create_guesses_table(state) Create table of guesses and feedback. .. py:method:: create_header(state) Create header panel with game info. .. py:method:: create_layout(state, show_secret = False) Create complete layout for the game. .. py:method:: create_secret_panel(state, show_secret = False) Create panel showing the secret code (or hidden). .. py:method:: display_game_state(state, show_secret = False) Display the current game state. .. py:method:: input_guess(available_colors) Get guess input from user. .. py:method:: show_result(state) Show the game result. .. py:function:: calculate_feedback(secret_code, guess) Calculate feedback for a guess. .. py:function:: main() Run the Mastermind game.