Example #1
0
 def is_valid_play(self, domino: Domino, player: Player) -> bool:
     """
     Assert if the player is allowed to place the specified domino on this train.
     :param domino: the Domino to be placed.
     :param player: the Player attempting to place it.
     :return: True if play is allowed, False otherwise.
     """
     return self.can_player_add(player) and domino.contains(self.requires)
Example #2
0
 def play(self, domino: Domino) -> bool:
     """
     Add a domino to the current train, updating internal state as necessary.
     :param domino: the Domino to add
     :return: a boolean indicating if the domino was added successfully
     """
     if not domino.contains(self.requires):
         return False
     self.cars.append(domino)
     self.requires = domino.get_other_number(self.requires)
     self.demands_satisfaction = domino.is_double
     return True