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)
def chance_replicate(self): if chance_allowed(self.replication_chance): return ProtoLifeForm(self.replication_chance, self.genes)
def chance_die(self): if chance_allowed(self.death_chance): return True return False
def chance_create_new(): if chance_allowed(ProtoLifeForm.formation_chance): return ProtoLifeForm()
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())