private void Evolve() { float maxFitness = landers[0].GetFitness(); List <Chromosome> chromList = new List <Chromosome>(); for (int i = 0; i < landers.Count; i++) { Chromosome c = new Chromosome(); c.fitness = landers[i].GetFitness(); if (maxFitness < c.fitness) { maxFitness = c.fitness; } c.weights = landers[i].GetWeights(); chromList.Add(c); } Debug.Log("Gen " + generation.ToString() + " max Fitness: " + maxFitness.ToString("F0")); chromList = ga.Evolv(chromList); landerPos = new Vector3(Random.Range(-16, 17), 0, Random.Range(10, 16)); for (int i = 0; i < landers.Count; i++) { landers[i].transform.position = landerPos; } for (int i = 0; i < landers.Count; i++) { landers[i].SetWeights(chromList[i].weights); } plataform.transform.position = new Vector3(Random.Range(-17, 18), 0, Random.Range(-15, -9)); timer = 0.0f; generation++; }
private void Evolve() { float maxFitness = agents[0].GetFitness(); List <Chromosome> chromList = new List <Chromosome>(); for (int i = 0; i < agents.Count; i++) { Chromosome c = new Chromosome(); c.fitness = agents[i].GetFitness(); if (maxFitness < c.fitness) { maxFitness = c.fitness; } c.weights = agents[i].GetWeights(); chromList.Add(c); } Debug.Log("Gen " + generation.ToString() + " max Fitness: " + maxFitness.ToString("F0")); chromList = ga.Evolv(chromList); for (int i = 0; i < agents.Count; i++) { agents[i].SetWeights(chromList[i].weights); } for (int i = 0; i < agents.Count; i++) { agents[i].transform.position = new Vector3(Random.Range(1 - (float)maxWidth, (float)maxWidth) - 1, 0, Random.Range(1 - (float)maxHeight, (float)maxHeight - 1)); agents[i].transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0); } timer = 0.0f; generation++; }