public void Init() { //0 - forward move, 1 - rotate left, 2 - rotate right //We need 2 genes. One for normal motion and other for the decision when a dead floor is encountered dna = new DNA_Sense(dnaLength, 3); alive = true; timeAlive = 0; timeTravelled = 0; }
public void Combine(DNA_Sense parent1, DNA_Sense parent2) { for (int i = 0; i < dnaLength; i++) { if (i < (dnaLength / 2.0f)) { Genes[i] = parent1.Genes[i]; } else { Genes[i] = parent2.Genes[i]; } } }
void Breed(DNA_Sense parent1, DNA_Sense parent2) { Vector3 randomPosition = new Vector3( spawnPoint.transform.position.x + Random.Range(-5, 5), spawnPoint.transform.position.y, spawnPoint.transform.position.z + Random.Range(-5, 5)); GameObject offspring = Instantiate(agentPrefab, randomPosition, Quaternion.identity); offspring.GetComponent <Brain_Sense>().Init(); if (Random.Range(0, 100) < 2) { offspring.GetComponent <Brain_Sense>().dna.Mutate(); } else { offspring.GetComponent <Brain_Sense>().dna.Combine(parent1, parent2); } population.Add(offspring); }