Exemple #1
0
        public void GenerateInitalPopulation()
        {
            population = new List <GeneticPlayer>();
            aliveCount = populationCount;

            for (int i = 0; i < populationCount; i++)
            {
                Vector3 pos = GetPos(i);

                GeneticPlayer geneticPlayer = Instantiate(geneticPlayerPrefab, pos, Quaternion.Euler(spawnRotation));

                Genom genom;

                if (geneticPlayerPrefab.mode == Mode.LoadAndTrain)
                {
                    genom = Genom.LoadFromFile(geneticPlayerPrefab.GetSavePath());

                    if (i > 0)
                    {
                        genom = Genom.MutateAll(genom, 0.01f);
                    }
                }
                else
                {
                    genom = geneticPlayer.InitGenom();
                    genom.RandomizeAll(); //случайные гены
                }

                geneticPlayer.SetGenom(genom);

                population.Add(geneticPlayer);
            }
        }
Exemple #2
0
        //генерирует популяцию того же размера, что и предедущая
        public void GenerateNextPopulation(List <Genom> parents)
        {
            aliveCount = populationCount;

            for (int i = 0; i < populationCount; i++)
            {
                Destroy(population[i].gameObject);
            }

            List <Genom> childsGenes = Genom.GetChilds(parents, populationCount, true);

            for (int i = 0; i < populationCount; i++)
            {
                Vector3 pos = GetPos(i);

                GeneticPlayer geneticPlayer = Instantiate(geneticPlayerPrefab, pos, Quaternion.Euler(spawnRotation));

                geneticPlayer.SetGenom(childsGenes[i]);

                geneticPlayer.name += " #" + i;

                population[i] = geneticPlayer;
            }
        }