Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def test_player_drop_rabbit(self):
     player = Player(player_id=1,
                     rabbits=2,
                     active_rabbits=1,
                     lost_rabbits=1)
     player.drop_active_rabbit()
     self.assertEqual(len(player.lost_rabbits), 2)
     self.assertEqual(len(player.active_rabbits), 0)
     self.assertEqual(len(player.ready_rabbits), 0)