Example #1
0
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
    return True

generation_manager = GenerationManager(200)
generation_manager.action_callback = action_callback

generation_manager.run(20)
Example #2
0
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


generation_manager = GenerationManager(500)
generation_manager.action_callback = action_callback

generation_manager.run(10)