• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python species.Species类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Species类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:27,代码来源:player.py


示例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)
开发者ID:mathiasmch,项目名称:Argon,代码行数:32,代码来源:test_reaction.py


示例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())
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:7,代码来源:species_tests.py


示例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()
开发者ID:skirklin,项目名称:modopt,代码行数:10,代码来源:tests.py


示例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]
开发者ID:ajdcolcord,项目名称:Evolution,代码行数:11,代码来源:player.py


示例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()
开发者ID:skirklin,项目名称:modopt,代码行数:12,代码来源:tests.py


示例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
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:12,代码来源:convert.py


示例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]
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:13,代码来源:species_tests.py


示例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
开发者ID:ajdcolcord,项目名称:Evolution,代码行数:14,代码来源:player.py


示例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"]
开发者ID:mahaalkhairy,项目名称:Evolution,代码行数:48,代码来源:test_validation.py


示例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]
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:7,代码来源:player.py


示例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)
开发者ID:a1ultima,项目名称:pycogent,代码行数:26,代码来源:name.py


示例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)
开发者ID:mahaalkhairy,项目名称:Evolution,代码行数:59,代码来源:test_dealer.py


示例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
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:18,代码来源:player.py


示例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]
开发者ID:lydiaauch,项目名称:software-dev-2016,代码行数:10,代码来源:player.py


示例16: from_json_state

 def from_json_state(json_state):
     """
     Takes in a json 'state' of a Player, converting it into a new PlayerState object
     :param json_state: JSON List -  [Natural, [Species+, ..., Species+], Cards]
     :return: PlayerState - the new PlayerState object created from the json representation
     """
     food_bag = json_state[0]
     species_list = [Species.convertSpecies(species) for species in json_state[1]]
     trait_cards = [TraitCard.from_json(trait) for trait in json_state[2]]
     return PlayerState(bag=food_bag, speciesList=species_list, trait_cards=trait_cards)
开发者ID:ajdcolcord,项目名称:Evolution,代码行数:10,代码来源:playerState.py


示例17: parse_species

def parse_species(species_json):
	"""
	converts from a json representation of species to a species representation
	:param species_json: Species+
	:return: Species
	"""
	try:
		if (len(species_json) == 5):
			[[f, food], [b, body], [p, population], [t, lot], [fb, fat_food]] = species_json
			if (f == "food" and b == "body" and p == "population" and t == "traits" and fb == "fat-food"):
				species = Species(food, body, population, parse_lot(lot))
				if fat_food == 0:
					return species
				species.setFatFood(fat_food)
				return species
		else:
			[[f, food], [b, body], [p, population], [t, lot]] = species_json
			if (f == "food" and b == "body" and p == "population" and t == "traits"):
				return Species(food, body, population, parse_lot(lot))
	except ValueError:
		raise ValueError("invalid species")
开发者ID:mahaalkhairy,项目名称:Evolution,代码行数:21,代码来源:parse_json.py


示例18: from_json_gamestate

 def from_json_gamestate(json_state):
     """
     Takes in a json game state, converting it into a list that contains the PlayerState, WateringHole, and other species
     :param json_state: JSON List - [Natural, [Species+, ..., Species+], Cards, Natural+, LOB]
     :return: [PlayerState, Nat, List of Species]
     """
     ps = PlayerState.from_json_state(json_state[:3])
     watering_hole = json_state[3]
     all_species = []
     for species_list in json_state[4]:
         all_species.append([Species.convertSpecies(species) for species in species_list])
     return [ps, watering_hole, all_species]
开发者ID:ajdcolcord,项目名称:Evolution,代码行数:12,代码来源:playerState.py


示例19: speciate

    def speciate(self):
        comporg = None
        counter = 0

        #//Step through all existing organisms
        for curorg in self.organisms:
            
            #//For each organism, search for a species it is compatible to
            cur_species_i = 0
            found = False
            while (cur_species_i < len(self.species)) and (not found):
                comporg = self.species[cur_species_i].first()
                if comporg is None:
                    #//Keep searching for a matching species
                    cur_species_i += 1
                elif curorg.gnome.compatibility(comporg.gnome) < neat.compat_threshold:
                    #//Found compatible species, so add this organism to it
                    self.species[cur_species_i].add_Organism(curorg)
                    curorg.species = self.species[cur_species_i]
                    found = True
                else:
                    #//Keep searching for a matching species
                    cur_species_i += 1

            #//If we didn't find a match, create a new species
            if not found:
                newspecies = Species()
                counter += 1
                newspecies.SetFromId(counter)
                self.species.append(newspecies)
                newspecies.add_Organism(curorg)
                curorg.species = newspecies
            # end species search conditions

        # end organism loop
        self.last_species = counter
        return True
开发者ID:fractal13,项目名称:python-neat,代码行数:37,代码来源:population.py


示例20: is_larger_attack_option

    def is_larger_attack_option(self, defend_player, def_spec_index, attacker, largest_def_species):
        """
        Checks if the attacker -> def_species_index is a larger attack option than attacker -> largest_def_species
        :param defend_player: PlayerState - the defending playerState containing the defending species to compare
        :param def_spec_index: Nat - the index of the species to compare against largest_def_species
        :param attacker: Species - the attacking species
        :param largest_def_species: Species - the current largest defending species to compare against
        :return: One of: - Tuple(Nat, Species) - the new larger option found
                         - False (if not a larger option)
        """
        lNeighbor, rNeighbor = defend_player.get_neighbors(def_spec_index)

        def_species = defend_player.species[def_spec_index]

        if Species.isAttackable(def_species, attacker, lNeighbor, rNeighbor) and def_species.isLarger(largest_def_species):
            return def_spec_index, defend_player.species[def_spec_index]
        return False
开发者ID:ajdcolcord,项目名称:Evolution,代码行数:17,代码来源:player.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python speck.SpeckCipher类代码示例发布时间:2022-05-27
下一篇:
Python species.GenericCombinatorialSpecies类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap