// Start is called before the first frame update void Start() { for (int i = 0; i < 303; i++) { Generation gen = SaveSys.LoadGeneration(i); float aux = 0; for (int j = 0; j < gen.population.Length; j++) { aux += gen.population[j].score; } aux = aux / gen.population.Length; SaveSys.SaveToDataFrame(gen.generation, aux); } }
//Evaluate fitness and choose next generation public void Draw() { this.undergoingDraw = true; Individual bestOfGen = new Individual(shotQuantity); //Sorting the array.... Array.Sort(population, delegate(Individual x, Individual y){ return(x.score.CompareTo(y.score)); }); bestOfGen = GetBestIndividual(population);//REDUNDANT bool isCurrentGenBetter = false; if (bestOfBest.score < bestOfGen.score) { predationCounter = 0; SaveSys.SaveToDataFrame(currentGeneration, bestOfGen.score, mutationChance); isCurrentGenBetter = true; mutationChance = initital_mutationChance; bestOfBest = bestOfGen; } else { predationCounter++; SaveSys.SaveToDataFrame(currentGeneration, bestOfBest.score, mutationChance); Debug.Log("Last Generation was better"); mutationChance += mutationIncreaseRate; //keep multiplying by 2, until it finds a better gen } SaveStatus(isCurrentGenBetter, currentGeneration);//Saving the result of this iteration NextGeneration(bestOfBest); this.undergoingDraw = false; }