// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { graph.AddPoint(Random.Range(0f, 100f)); } }
// Update is called once per frame void Update() { float curTime = Time.time - startTime; lifeTimeText.text = "Time: " + curTime.ToString("n1") + "/" + roundTime.ToString() + "s"; if (currentMicrobe != null && curTime > roundTime) { population[chromosomeInd].Fitness = GetFitness(currentMicrobe); if (chromosomeInd == 0) { graph.AddPoint(population[chromosomeInd].Fitness); } if (population[chromosomeInd].Fitness > maxGenDist) { maxGenDist = population[chromosomeInd].Fitness; graph.ChangeLastPoint(maxGenDist); } float fitness = GetFitness(currentMicrobe); listScript.PlaceMicrobe(chromosomeInd + 1, generation + 1, fitness, population[chromosomeInd]); string[] parents = population[chromosomeInd].GetParents(); dataLogger.AddData(generation.ToString(), chromosomeInd.ToString(), fitness.ToString(), distTravelled.ToString(), population[chromosomeInd].ChromosomeString, parents[0], parents[1]); Destroy(currentMicrobe); // If we have processed the final microbe, we can start the next gen if (chromosomeInd == population.Length - 1) { graph.ChangeLastPoint(maxGenDist); maxGenDist = 0f; // exit from function and start the evolution process microbeEvolver.EvolveNextGeneration(); return; } distTravelled = 0f; StartMicrobe(); } else if (currentMicrobe == null && microbeBuilder != null) { StartMicrobe(); } if (currentMicrobe != null) { distanceText.text = "Distance: " + GetFitness(currentMicrobe).ToString("n2") + "m"; curPos = new Vector2(currentMicrobe.transform.position.x, currentMicrobe.transform.position.z); distTravelled += Vector2.Distance(prevPos, curPos); prevPos = curPos; MeshRenderer[] rends = currentMicrobe.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i < rends.Length; i++) { Color c = rends[i].material.color; c.g -= 1f / roundTime * Time.deltaTime; c.b -= 1f / roundTime * Time.deltaTime; rends[i].material.color = c; } } CheckSpeed(); }