Ejemplo n.º 1
0
        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
                {
                }
            }
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
 protected abstract void ActionOnNewGeneration(ref BaseGenable genable, int index);
Ejemplo n.º 4
0
 protected abstract void ActionOnSpawn(ref BaseGenable genable, int index);