本文整理汇总了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
示例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]
示例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
示例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)