mastermind.game package¶
- class mastermind.game.board.GameBoard(number_of_colors: int, number_of_dots: int)[source]¶
Bases:
object
Represents the game board for a Mastermind game.
The GameBoard class manages the game’s guesses and feedbacks, allowing players to make guesses, retrieve past guesses and feedbacks, and clear the board.
- NUMBER_OF_COLORS¶
The number of colors available in the game.
- Type:
int
- NUMBER_OF_DOTS¶
The number of dots (or pegs) in each guess.
- Type:
int
- _number_of_guesses_made¶
The number of guesses made so far.
- Type:
int
- Raises:
EmptyBoardError – If there are no guesses to retrieve or remove.
- exception EmptyBoardError[source]¶
Bases:
Exception
Exception raised when trying to access the game board when it is empty.
- add_guess(guess: Tuple[int, ...], feedback: Tuple[int, ...]) None [source]¶
Adds a new guess and its corresponding feedback to the game board.
- Parameters:
guess (Tuple[int, ...]) – The new guess.
feedback (Tuple[int, ...]) – The feedback for the new guess.
- last_feedback() Tuple [source]¶
Returns the feedback for the last guess made on the game board.
- Returns:
A tuple representation of the last feedback.
- Return type:
Tuple
- Raises:
EmptyBoardError – If there are no guesses on the game board.
- last_guess() Tuple [source]¶
Returns the last guess made on the game board.
- Returns:
A tuple representation of the last guess.
- Return type:
Tuple
- Raises:
EmptyBoardError – If there are no guesses on the game board.
- remove_last() Tuple [source]¶
Removes the last guess and feedback from the game board.
- Returns:
The removed guess and feedback.
- Return type:
Tuple
- Raises:
EmptyBoardError – If there are no guesses on the game board.
- class mastermind.game.game.Game(number_of_colors, number_of_dots, maximum_attempts, game_mode)[source]¶
Bases:
object
The main entry point for the Mastermind game.
- Parameters:
number_of_colors (int) – The number of colors in the game.
number_of_dots (int) – The number of dots in each combination.
maximum_attempts (int) – The maximum number of attempts allowed in the game.
game_mode (str) – The game mode, such as “HvH”, “HvAI”, “AIvH”, or “AIvAI”.
- property game_mode: str¶
Returns the game mode.
- property maximum_attempts: int¶
Returns the maximum number of attempts allowed in the game.
- property number_of_colors: int¶
Returns the number of colors in the game.
- property number_of_dots: int¶
Returns the number of dots in each combination.
- class mastermind.game.game_flow.GameFlow(game_state: GameParameter, player_logic: PlayerLogic)[source]¶
Bases:
object
Manages the flow of the Mastermind game.
- Parameters:
game_state (GameState) – The state of the game.
player_logic (PlayerLogic) – The logic for the players.
- class mastermind.game.game_parameter.GameParameter(number_of_colors: int, number_of_dots: int, maximum_attempts: int, game_mode: str)[source]¶
Bases:
ValidatedClass
Represents the state of the Mastermind game.
- Parameters:
number_of_colors (int) – The number of colors in the game.
number_of_dots (int) – The number of dots in each combination.
maximum_attempts (int) – The maximum number of attempts allowed in the game.
game_mode (str) – The game mode, such as “HvH”, “HvAI”, “AIvH”, or “AIvAI”.
- check_and_update_win_status() bool | None [source]¶
Checks the game state and updates the win status.
- Returns:
The win status, or None if the game is still in progress.
- Return type:
bool | None
- property number_of_colors: int¶
- property number_of_dots: int¶
- property win_status: bool | None¶
- class mastermind.game.player_logic.PlayerLogic(game_state: GameParameter)[source]¶
Bases:
object
Manages the logic for the players in the Mastermind game.
- Parameters:
game (GameState) – The state of the game.
- property GAME_MODE: str¶
- process_player_guessing() str | None [source]¶
Processes the player’s guessing logic.
- Returns:
A command from the player, if any.
- Return type:
Optional[str]
- submit_guess(guess: Tuple[int, ...], feedback: Tuple[int, ...]) None [source]¶
Submits a guess and its corresponding feedback to the game board.
- Parameters:
guess (Tuple[int, ...]) – The guess to be submitted.
feedback (Tuple[int, ...]) – The feedback for the guess.
- Raises:
NotImplementedError – If the game has ended.