haive.games.mastermind.state_manager¶

State manager for the Mastermind game.

This module defines the state manager for the Mastermind game, which manages the state of the game and provides methods for initializing, updating, and analyzing the game state.

Classes¶

MastermindStateManager

Manager for Mastermind game state.

Module Contents¶

class haive.games.mastermind.state_manager.MastermindStateManager[source]¶

Bases: haive.games.framework.base.state_manager.GameStateManager[haive.games.mastermind.state.MastermindState]

Manager for Mastermind game state.

This class provides methods for initializing, updating, and analyzing the game state.

classmethod add_analysis(state, player, analysis)[source]¶

Add an analysis to the state.

Parameters:
Returns:

Updated state with the analysis added.

Return type:

MastermindState

classmethod apply_move(state, move)[source]¶

Apply a guess to the current state and return the new state.

Parameters:
Returns:

A new game state after applying the guess.

Return type:

MastermindState

Raises:

ValueError – If the move is invalid.

classmethod check_game_status(state)[source]¶

Check and update the game status.

For Mastermind, this is handled in apply_move, so this method just returns the state.

Parameters:

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

Returns:

The game state (unchanged).

Return type:

MastermindState

Get all legal moves for the current state.

For Mastermind, this is impractical to enumerate all possible color combinations, so this method returns an empty list. The agent will generate guesses based on analysis.

Parameters:

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

Returns:

An empty list (agent should generate its own guesses).

Return type:

List[MastermindGuess]

classmethod get_possible_codes(state)[source]¶

Get all possible secret codes that are consistent with all guesses and. feedback so far.

This is computationally expensive for a full game, so it’s limited to use for analysis.

Parameters:

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

Returns:

Set of possible codes as tuples.

Return type:

Set[Tuple[str, …]]

classmethod get_winner(state)[source]¶

Get the winner of the game, if any.

Parameters:

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

Returns:

The winner, or None if the game is ongoing.

Return type:

Optional[str]

classmethod initialize(**kwargs)[source]¶

Initialize a new Mastermind game.

Parameters:

**kwargs – Keyword arguments for game initialization. codemaker: Player who creates the code (player1 or player2). Default is player1. colors: List of valid colors. Default is standard 6 colors. code_length: Length of the secret code. Default is 4. max_turns: Maximum number of turns. Default is 10. secret_code: Optional predetermined secret code (List[str] or ColorCode).

Returns:

A new Mastermind game state.

Return type:

MastermindState