本文整理汇总了Python中species.Species类的典型用法代码示例。如果您正苦于以下问题:Python Species类的具体用法?Python Species怎么用?Python Species使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Species类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feed_carnivore
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: TestReaction
class TestReaction(unittest.TestCase):
def setUp(self):
self._limiting = Species("Limiting", 100)
self._limiting.set_n(0.001)
self._reactant2 = Species("Reactant #1", 200)
self._reactant3 = Species("Reactant #2", 300)
self._product = Species("Product", 400)
def test_add_get_limiting_reactant(self):
reaction = Reaction()
reaction.add_limiting_reactant(self._limiting)
self.assertEqual(reaction.get_limiting_reactant().n(), 0.001)
def test_add_get_reactant(self):
reaction = Reaction()
reaction.add_limiting_reactant(self._limiting)
reaction.add_reactant(self._reactant2, 2)
reaction.add_reactant(self._reactant3, 3)
self.assertEqual(reaction.get_non_limiting_reactants()[0].n(), 0.002)
self.assertEqual(reaction.get_non_limiting_reactants()[1].n(), 0.003)
def test_add_get_product(self):
reaction = Reaction()
reaction.add_product(self._product, 0.4)
self.assertEqual(reaction.get_product().n(), 0.001)
def test_get_yield(self):
reaction = Reaction()
reaction.add_limiting_reactant(self._limiting)
reaction.add_product(self._product, 0.3)
self.assertEqual(reaction.get_yield(), 75)
示例3: test_can_eat
def test_can_eat(self):
self.assertFalse(self.species_1.can_eat())
self.assertTrue(self.species_4.can_eat())
fat_tissue = Species(4, 3, 4, [TraitCard("fat-tissue")], 3)
self.assertTrue(fat_tissue.can_eat())
fat_tissue.fat_storage = 4
self.assertFalse(fat_tissue.can_eat())
示例4: optimizer_test
def optimizer_test(self):
target = np.array([5,1,2])
def objective(a,b,c):
arr = np.array([a,b,c])
return np.average((arr - target)**2)**0.5
genome = {'a':range(10), 'b':range(10), 'c':range(1)}
genome = Genome(genome)
spec = Species(genome, objective=objective)
spec.evaluate()
spec.evolve()
示例5: parse_choice
def parse_choice(choice):
"""
Parse a choice into a [PlayerState, listOf(Species), listOf(Species]
:param choice: json list representing [playerstate, listof species, listof species]
:return: [PlayerState, listOf(Species), listOf(Species)]
"""
ps = PlayerState.convertPlayerState(choice[0])
prev_species = [Species.convertSpecies(species) for species in [prev for prev in choice[1]]]
later_species = [Species.convertSpecies(species) for species in [late for late in choice[2]]]
return [ps, prev_species, later_species]
示例6: organism_test
def organism_test(self):
genome = Genome({
'A':range(10),
'B':'abcdefg',
'C':np.linspace(0, 1, 100)})
species = Species(genome)
org1 = species.spawn_organism()
org2 = species.spawn_organism()
org3 = org1.mate(org2)
org3.mutate()
示例7: json_to_species
def json_to_species(cls, json_species):
assert(cls.validate_species_json(json_species))
species_food = json_species[0][1]
species_body = json_species[1][1]
species_pop = json_species[2][1]
species_traits = []
for trait in json_species[3][1]:
species_traits.append(cls.json_to_trait(trait))
species_obj = Species(species_pop, species_food, species_body, species_traits)
if len(json_species) == 5:
species_obj.fat_storage = json_species[4][1]
return species_obj
示例8: setUp
def setUp(self):
self.attacker = Species()
self.attacker.traits = [TraitCard("carnivore")]
self.defender = Species()
self.left_neighbor = Species()
self.right_neighbor = Species()
self.species_1 = Species(4, 4, 4)
self.species_2 = Species(4, 4, 4)
self.species_3 = Species(4, 4, 3)
self.species_4 = Species(4, 3, 3)
self.species_5 = Species(3, 3, 3)
self.species_list = [self.species_2, self.species_4, self.species_3, self.species_5, self.species_1]
示例9: parse_cj_dj
def parse_cj_dj(json_cj_dj):
"""
Parse a json cj_dj into a [listOf(listOf(Species)), listOf(listOf(Species))]
:param json_cj_dj: json list representing [listof species, listof species]
- First list of species is each specieslist of all players acting before this player
- Second list of species is each specieslist of all players who's turns come after this player
:return: (listOf(Species), listOf(Species))
"""
prev_species, later_species = [], []
for prev in json_cj_dj[0]:
prev_species.append([Species.convertSpecies(species) for species in prev])
for later in json_cj_dj[1]:
later_species.append([Species.convertSpecies(species) for species in later])
return prev_species, later_species
示例10: setUp
def setUp(self):
self.species1 = Species(0, 1, 3, [])
self.carni2 = Species(0, 2, 3, [Trait.carnivore])
self.herbavore = Species(0, 1, 1, [])
self.herbavore2 = Species(0, 1, 1, [])
self.herbavore3 = Species(1, 1, 1, [])
self.herbavore4 = Species(2, 1, 2, [])
self.fat_tissue = Species(0, 1, 1, [])
self.fat_tissue.setTraits([Trait.fat_tissue])
self.fat_tissue2 = Species(0, 3, 1, [])
self.fat_tissue2.setTraits([Trait.fat_tissue])
self.opherb = Species(0, 1, 1, [])
self.opfatherb = Species(0, 7, 1, [])
self.fertileCard = TraitCard(Trait.fertile, 2)
self.climbingCard = TraitCard(Trait.climbing, 0)
self.cooperationCard = TraitCard(Trait.cooperation, 0)
self.carnivoreCard = TraitCard(Trait.carnivore, 0)
self.longNeckCard = TraitCard(Trait.long_neck, 0)
self.ambushCard = TraitCard(Trait.ambush, 0)
self.burrowingCard = TraitCard(Trait.burrowing, 0)
self.cooperation2Card = TraitCard(Trait.cooperation, -1)
self.player1 = Player(1, [], 0)
self.player2 = Player(2, [], 0)
self.player3 = Player(3, [], 0)
self.validAction1 = [2, [[2, 6]], [[2, 3]], [[5, 4]], [[2, 0, 0]]]
self.validAction2 = [2, [[2, 0]], [[2, 1]], [[4, 3]], []]
self.validAction3 = [2, [[2, 1]], [], [[3, 0]], []]
self.validAction4 = [2, [], [], [[0, 1]], []]
self.validAction5 = [0, [], [], [], []]
self.invalidAction1 = ["hi", 1, [], "so", False]
self.invalidAction2 = ["hi", 1, []]
self.invalidAction3 = [False, [["2", 6]], [[2, 3]], [[5, 4]], [[2, 0, 0]]]
self.validFeeding1 = False
self.validFeeding2 = 1
self.validFeeding3 = [1, 9]
self.validFeeding4 = [0, 0, 1]
self.invalidFeeding1 = True
self.invalidFeeding2 = [1, 2, 3, 3, ""]
self.invalidFeeding3 = ["p", "i", "e"]
示例11: feed_herbivores
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]
示例12: __init__
def __init__(self, db_name):
"""db_name: and Emsembl database name"""
if isinstance(db_name, EnsemblDbName):
db_name = db_name.Name
self.Name = db_name
self.Type = get_dbtype_from_name(db_name)
self.Prefix = get_db_prefix(db_name)
release, build = get_version_from_name(db_name)
self.Release = release
self.GeneralRelease = self.Release
if len(build) == 1:
if self.Type != 'compara':
self.Build = build[0]
else:
self.Build = None
self.GeneralRelease = build[0]
elif build:
self.Build = build[1]
self.GeneralRelease = build[0]
else:
self.Build = None
self.Species = None
self.Species = Species.getSpeciesName(self.Prefix)
示例13: setUp
def setUp(self):
self.player1 = Player(1, [], 0, info = "j")
self.player2 = Player(2, [], 0, info = "j")
self.player3 = Player(3, [], 0, info = "j")
self.player4 = Player(4, [], 0, info = "j")
self.player5 = Player(5, [], 0, info = "j")
self.player6 = Player(6, [], 0, info = "j")
self.player7 = Player(7, [], 0, info = "j")
self.player8 = Player(8, [], 0, info = "j")
self.players = [self.player1, self.player2, self.player3]
self.players8 = [self.player1, self.player2, self.player3, self.player4, self.player5, self.player6, self.player7, self.player8]
self.species1 = Species(0, 3, 3, [])
self.species2 = Species(0, 2, 1, [])
self.speciesscavenger = Species(0, 3, 3, [Trait.scavenger])
self.speciesforaging = Species(0, 3, 3, [Trait.foraging])
self.speciescoop = Species(0, 3, 3, [Trait.cooperation])
self.speciesfull = Species(2, 2, 2, [])
self.speciesfull1 = Species(3, 2, 3, [])
self.speciesfull2 = Species(4, 2, 4, [])
self.speciesfat= Species(0, 3, 3, [Trait.fat_tissue])
self.speciesfat.setFatFood(1)
self.specieshorns = Species(0, 3, 3, [Trait.horns])
self.speciescarni = Species(0, 3, 3, [Trait.carnivore])
self.specieshorns1 = Species(0, 3, 1, [Trait.horns])
self.speciescarni1 = Species(0, 3, 1, [Trait.carnivore])
self.speciesLongFertile = Species(0, 3, 1, [Trait.long_neck, Trait.fertile])
self.speciesFertile = Species(0, 3, 1, [Trait.fertile])
self.speciesLongNeck = Species(0, 3, 1, [Trait.long_neck])
self.watering_hole = WateringHole(0)
self.dealer = Dealer(self.watering_hole, self.players)
self.warning_call_card = TraitCard(Trait.warning_call, 0)
self.warning_call_card2 = TraitCard(Trait.warning_call, 1)
self.climbing_card = TraitCard(Trait.climbing, 3)
self.carnivore_card = TraitCard(Trait.carnivore, -8)
self.fertileCard = TraitCard(Trait.fertile, 2)
self.climbingCard = TraitCard(Trait.climbing, 0)
self.cooperationCard = TraitCard(Trait.cooperation, 0)
self.carnivoreCard = TraitCard(Trait.carnivore, 0)
self.longNeckCard = TraitCard(Trait.long_neck, 0)
self.fertileCard1 = TraitCard(Trait.fertile, 2)
self.climbingCard1 = TraitCard(Trait.climbing, 1)
self.cooperationCard1 = TraitCard(Trait.cooperation, 1)
self.carnivoreCard1 = TraitCard(Trait.carnivore, 1)
self.longNeckCard1 = TraitCard(Trait.long_neck, 1)
self.ambushCard = TraitCard(Trait.ambush, 1)
self.deck = [self.warning_call_card, self.climbing_card, self.carnivore_card]
self.deck2 = deck.generateDeck()[:12]
self.dealer.setDeck(self.deck)
self.dealer.setWateringHole(20)
示例14: feed_carnivore
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
示例15: feed_fatty
def feed_fatty(cls, fat_tissue_species, food_available):
"""
Feeds a species with the fat-tissue trait
:param fat_tissue_species: species with a fat-tissue trait
:param food_available: food on the watering_hole_board
:return: list of [Species, int] where Species is the fat_tissue_species and int is the requested food
"""
fatty = Species.largest_fatty_need(fat_tissue_species)
food_requested = (fatty.body if fatty.body < food_available else food_available)
return [fatty, food_requested]