Example #1
0
    def feed_carnivore(cls, hungry_carnivores, player_state, list_of_player):
        """
        Feeds the largest hungry carnivore
        :param hungry_carnivores: list of hungry carnivores
        :param player_state: the current player state
        :param list_of_player: list of all player states
        :return:
        """
        sorted_carnivores = Species.sort_lex(hungry_carnivores)
        for carnivore in sorted_carnivores:
            targets = []
            for player in list_of_player:
                if player == player_state:
                    continue
                for i in range(0, len(player.species)):
                    defender = player.species[i]
                    left_neighbor = (False if i == 0 else player.species[i - 1])
                    right_neighbor = (False if i == len(player.species) - 1 else player.species[i + 1])
                    if defender.is_attackable(carnivore, left_neighbor, right_neighbor):
                        targets.append(defender)
            if targets:
                sorted_targets = Species.sort_lex(targets)
                target = sorted_targets[0]
                target_player = next(player for player in list_of_player if target in player.species)
                return [carnivore, target_player, target]

        return False
 def feed_carnivore(cls, hungry_carnivores, player_state, list_of_player):
     """
     Feeds the largest hungry carnivore
     :param hungry_carnivores: list of hungry carnivores
     :param player_state: the current player state
     :param list_of_player: list of all player states
     :return:
     """
     sorted_carnivores = Species.sort_lex(hungry_carnivores)
     for carnivore in sorted_carnivores:
         targets = []
         for player in list_of_player:
             if player == player_state:
                 continue
             for i in range(0, len(player.species)):
                 defender = player.species[i]
                 left_neighbor = (False if i == 0 else player.species[i -
                                                                      1])
                 right_neighbor = (False if i == len(player.species) -
                                   1 else player.species[i + 1])
                 if defender.is_attackable(carnivore, left_neighbor,
                                           right_neighbor):
                     targets.append(defender)
         if targets:
             sorted_targets = Species.sort_lex(targets)
             target = sorted_targets[0]
             target_player = next(player for player in list_of_player
                                  if target in player.species)
             return [carnivore, target_player, target]
         else:
             return False
 def test_sort_lex(self):
     sorted_list = [
         self.species_2, self.species_1, self.species_3, self.species_4,
         self.species_5
     ]
     self.assertEqual(Species.sort_lex(self.species_list), sorted_list)
     self.assertNotEqual(Species.sort_lex(self.species_list),
                         self.species_list)
Example #4
0
 def feed_herbivores(cls, hungry_herbivores):
     """
     Feeds a herbivore species
     :param hungry_herbivores: list of hungry herbivores
     :return: the Species to feed
     """
     return Species.sort_lex(hungry_herbivores)[0]
 def feed_herbivores(cls, hungry_herbivores):
     """
     Feeds a herbivore species
     :param hungry_herbivores: list of hungry herbivores
     :return: the Species to feed
     """
     return Species.sort_lex(hungry_herbivores)[0]
Example #6
0
    def feed_carnivore(cls, hungry_carnivores, player, opponents):
        """
        Feeds the largest hungry carnivore
        :param hungry_carnivores: list of hungry carnivores
        :param player: the current player's state
        :param opponents: list of all other player's states
        :return:
        """
        sorted_carnivores = Species.sort_lex(hungry_carnivores)
        for carnivore in sorted_carnivores:
            targets = Dealer.carnivore_targets(carnivore, opponents)
            if targets:
                sorted_targets = Species.sort_lex(targets)
                target = sorted_targets[0]
                target_player = next(player for player in opponents if target in player.species)
                return [carnivore, target_player, target]

        return False
 def test_sort_lex(self):
     sorted_list = [self.species_2, self.species_1, self.species_3, self.species_4, self.species_5]
     self.assertEqual(Species.sort_lex(self.species_list), sorted_list)
     self.assertNotEqual(Species.sort_lex(self.species_list), self.species_list)