[docs]classGameParameter(ValidatedClass):""" Represents the state of the Mastermind game. Args: 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". """def__init__(self,number_of_colors:int,number_of_dots:int,maximum_attempts:int,game_mode:str,)->None:self.MAXIMUM_ATTEMPTS=maximum_attemptsself.GAME_MODE=game_modeself.game_started=TrueFuse(False)# validation enforced by ValidatedClassself._board=GameBoard(number_of_colors,number_of_dots)self._win_status=None
[docs]defcheck_and_update_win_status(self)->bool|None:""" Checks the game state and updates the win status. Returns: bool | None: The win status, or None if the game is still in progress. """iflen(self)==0:self._win_status=Nonereturnself._win_statusifself._last_guess_is_secret()orself._last_feedback_is_perfect():self._win_status=Trueelifself._reached_maximum_attempts():self._win_status=Falseelse:self._win_status=Nonereturnself._win_status
@propertydefnumber_of_colors(self)->int:returnself._board.NUMBER_OF_COLORS@propertydefnumber_of_dots(self)->int:returnself._board.NUMBER_OF_DOTS@propertydefwin_status(self)->bool|None:returnself._win_statusdef__len__(self)->int:returnlen(self._board)def_last_guess_is_secret(self)->bool:""" Checks if the last guess made on the game board matches the secret code. """return(hasattr(self,"SECRET_CODE")andself._board.last_guess()==self.SECRET_CODE)def_last_feedback_is_perfect(self)->bool:""" Checks if the feedback for the last guess is perfect (all dots in the correct position). """returnself._board.last_feedback()==(self.number_of_dots,0)def_reached_maximum_attempts(self)->bool:""" Checks if the maximum number of attempts has been reached. """returnlen(self._board)==self.MAXIMUM_ATTEMPTS