예제 #1
0
    def replicate(self, mutation_chance=None):
        """Create a new gene with a mutation_chance to flip one bit"""
        if mutation_chance is None:
            mutation_chance = self.default_mutation_chance

        new_value = self.value
        if chance_allowed(mutation_chance):
            mutating_bit = get_random_positive_int(self.gene_size)
            new_value = flip_bit(self.value, mutating_bit)

        return SimpleRandomGene(new_value)
예제 #2
0
 def chance_replicate(self):
     if chance_allowed(self.replication_chance):
         return ProtoLifeForm(self.replication_chance, self.genes)
예제 #3
0
 def chance_die(self):
     if chance_allowed(self.death_chance):
         return True
     return False
예제 #4
0
 def chance_create_new():
     if chance_allowed(ProtoLifeForm.formation_chance):
         return ProtoLifeForm()
예제 #5
0
 def advance(self):
     self.environment.update()
     for area in self.environment.fuzzy_iter(10):
         if chance_allowed(self.creature_spawn_chance):
             self._create_creature(area.random_location(), Creature())