def move_players_chip(self, player: Player, steps: int) -> Player or None: """ Moves player chip by given amount of steps :param player: who is making this turn :param steps: number of steps to do :return: Player, if he wins the game during this action, None in other case """ rabbit = player.get_active_rabbit() # handle rare case when player had dropped last own rabbit on this turn if rabbit is None: return None destination_cell = self._rabbit_map[rabbit] while (steps > 0) and (not destination_cell.is_winning_cell): destination_cell = destination_cell.next if not self.is_busy(destination_cell): steps -= 1 if destination_cell != self._rabbit_map[rabbit]: self._rabbit_map[rabbit] = destination_cell print(f'Rabbit #{player.id}.{rabbit.number} moves to cell #{destination_cell.number}') if destination_cell.is_winning_cell: return player if destination_cell.is_hole: player.drop_active_rabbit() self._rabbit_map[rabbit] = None
def test_player_out_of_the_game(self): player = Player(player_id=1, rabbits=0) self.assertFalse(player.is_active) self.assertEqual(player.get_active_rabbit(), None)