本文整理汇总了Python中animal.Animal.init_genes_class方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.init_genes_class方法的具体用法?Python Animal.init_genes_class怎么用?Python Animal.init_genes_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.init_genes_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: action_callback
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import init_genes_class [as 别名]
#!/bin/python
"""
Test some hypothesis about empathy
"""
import random
from generation_manager import GenerationManager
from animal import Animal
from genes.empathetic_gene import EmpatheticGene
from genes.punisher_gene import PunisherGene
PunisherGene.type_of_punishment = "no empathy"
Animal.init_genes_class([EmpatheticGene, PunisherGene])
def action_callback(animal, animals):
""" What happen in the environnement """
assert isinstance(animal, Animal)
teammate = random.randint(0, len(animals)-1)
gain = random.uniform(-15, 5)
teammate_gain = random.uniform(-15, 5)
teammate_empathy = animals[teammate].genes["empathetic gene"].value
choice_input = {"gain":gain,
"teammate_gain":teammate_gain,
"teammate_empathy":teammate_empathy}
choice_output = animal.choose(choice_input)
if choice_output["accept_cooperation"]:
animal.reproductive_capacity += gain
animals[teammate].reproductive_capacity += teammate_gain
示例2: action_callback
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import init_genes_class [as 别名]
#!/bin/python
"""
Test some hypothesis about fairness
"""
import random
from generation_manager import GenerationManager
from animal import Animal
from genes.compromise_gene import CompromiseGene
Animal.init_genes_class([CompromiseGene])
def action_callback(animal, animals):
""" What happen in the environnement """
assert isinstance(animal, Animal)
teammate = random.randint(0, len(animals)-1)
teammate_compromise = animals[teammate].genes["compromise gene"].value
choice_input = {"teammate_compromise":teammate_compromise}
choice_output = animal.choose(choice_input)
if choice_output["accept_cooperation"]:
rate = choice_output["rate"]
animal.reproductive_capacity += 2*rate
animals[teammate].reproductive_capacity += 5*(1-rate)
else:
animal.reproductive_capacity += -10
animals[teammate].reproductive_capacity += -10
return True