private IEnumerator GeneticCoroutine() { float timeStart = Time.time; while (true) { yield return(new WaitForSeconds(Settings.PopulationTime)); if (isSimulated) { Time.timeScale = 0; GenableList.Sort((x, y) => { return((int)(y.Value - x.Value)); }); Debug.Log("Best:" + GenableList[0].Value); for (int i = Settings.SampleCount; i < GenableList.Count; i++) { GenableList[i].Brain.MutateFrom(GenableList[Random.Range(0, Settings.SampleCount)].Brain, Settings.MutationValue.Evaluate(Time.time - timeStart)); } for (int i = 0; i < GenableList.Count; i++) { BaseGenable genable = GenableList[i]; ActionOnNewGeneration(ref genable, i); } yield return(new WaitForSecondsRealtime(1)); Time.timeScale = 1; } else { } } }
private void Start() { for (int i = 0; i < Settings.PopulationCount; i++) { BaseGenable genable = Instantiate(Prefab, transform); GenableList.Add(genable); ActionOnSpawn(ref genable, i); } geneticCoroutine = StartCoroutine(GeneticCoroutine()); }
protected abstract void ActionOnNewGeneration(ref BaseGenable genable, int index);
protected abstract void ActionOnSpawn(ref BaseGenable genable, int index);