Beispiel #1
0
 def reproduce(self, idxs, to_idxs, consume_health=True):
     unique_idxs = np.unique(idxs)
     to_idxs = to_idxs[:len(unique_idxs)]
     if len(unique_idxs) == 0:
         return 0
     parents = self[unique_idxs]
     new_chromosomes = VectorAgentChromosome(len(unique_idxs))
     new_chromosomes[:] = self.chromosomes[unique_idxs]
     new_chromosomes.mutate(to_idxs)
     self.develop_from_chromosomes(new_chromosomes, to_idxs)
     self.x[to_idxs] = parents.x
     self.y[to_idxs] = parents.y
     self.rotate(np.random.random(len(unique_idxs)) * (math.pi*2), to_idxs)
     # отодвинуть потомство, чтобы не топтаться по нему
     self.x[to_idxs] += self.ax[to_idxs] * settings.ATTACK_RADIUS
     self.y[to_idxs] += self.ay[to_idxs] * settings.ATTACK_RADIUS
     self.gencount[to_idxs] = parents.gencount + 1
     self.health[to_idxs] = parents.birth_health
     if consume_health:
         self.consume_energy(parents.birth_health / settings.BIRTH_KPD, unique_idxs)
     return len(unique_idxs)
Beispiel #2
0
 def random(cls, number):
     population = cls(number)
     cromosomes = VectorAgentChromosome.random(number)
     agents = VectorAgent.from_chromosomes(cromosomes)
     population._agents = agents
     return population
Beispiel #3
0
 def make_new_random(self, to_random_num, idxs):
     assert to_random_num >= 0
     new_chromosomes = VectorAgentChromosome.random(to_random_num)
     self.replace_from_chromosomes(idxs, new_chromosomes)
     self._agents.health[idxs] = MIN_HEALTH
     self.env.add_new_agents(idxs)