def draw_domino(self, player: Player): """ Draw a domino for the specified player. :param player: the player to add the domino to. :return: the domino that was drawn and given to the player. """ if len(self.dominoes) == 0: return False domino = self.dominoes.pop() player.give_domino(domino) return domino
def draw_domino_and_check_for_start(self, player: Player, starting_domino: Domino) -> bool: """ Helper function when determine the first player. Draws a domino for tha player, then checks to see if it is the required domino for going first. :param player: the player to add the domino to. :param starting_domino: the required starting Domino :return: True if the starting_domino was drawn. """ if len(self.dominoes) == 0: raise RuntimeError( 'Ran out of dominoes while trying to find the starting player. Did we miss the starting tile? ' + str(starting_domino)) d = self.dominoes.pop() if d == starting_domino: if len(self.dominoes) > 0: player.give_domino(self.dominoes.pop()) return True player.dominoes.append(d) return False
def test_give_domino(self): p = Player(1, TestBot()) d = Domino(2, 3) p.give_domino(d) self.assertTrue(p.dominoes.__contains__(d))