当前位置: 首页>>代码示例>>Python>>正文


Python Species.sort_lex方法代码示例

本文整理汇总了Python中species.Species.sort_lex方法的典型用法代码示例。如果您正苦于以下问题:Python Species.sort_lex方法的具体用法?Python Species.sort_lex怎么用?Python Species.sort_lex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在species.Species的用法示例。


在下文中一共展示了Species.sort_lex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: feed_carnivore

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import sort_lex [as 别名]
    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
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:29,代码来源:player.py

示例2: feed_herbivores

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import sort_lex [as 别名]
 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]
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:9,代码来源:player.py

示例3: feed_carnivore

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import sort_lex [as 别名]
    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
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:20,代码来源:player.py

示例4: test_sort_lex

# 需要导入模块: from species import Species [as 别名]
# 或者: from species.Species import sort_lex [as 别名]
 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)
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:6,代码来源:species_tests.py


注:本文中的species.Species.sort_lex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。