示例#1
0
    public void MakeNewGeneration()
    {
        currentGeneration++;
        currentSize = 0;
        int poolSize = matingPool.Count;
        List <GameObject> nextGeneration = new List <GameObject>();

        for (int i = 0; i < simManager.generationSize; i++)
        {
            GameObject parent1 = matingPool[Random.Range(0, poolSize - 1)];
            GameObject parent2 = matingPool[Random.Range(0, poolSize - 1)];
            nextGeneration.Add(organisms[i]);

            if (parent1.GetComponent <Organism>().HasTopMarker)
            {
                parent2 = parent1;
            }
            else if (parent2.GetComponent <Organism>().HasTopMarker)
            {
                parent1 = parent2;
            }
            GameObject offspring = PopGen.Reproduce(parent1, parent2, currentGeneration, i);
            nextGeneration[i].GetComponent <Organism>().SetNewOrganism(offspring.GetComponent <Organism>());
            Destroy(offspring);
        }
        organisms = PopGen.SortByFitness(nextGeneration);
        organisms = PopGen.SetMatingChances(organisms, simManager.generationSize);
        UpdateBestOrganism();
        matingPool = PopGen.GenerateMatingPool(organisms);
    }
示例#2
0
 private void MakeInitPopulation()
 {
     if (currentSize < simManager.generationSize)
     {
         GameObject obj = SpawnOrganism();
         obj.AddComponent <Organism>();
         SetupOrganism(obj.GetComponent <Organism>());
         organisms.Add(obj);
         obj.GetComponent <Organism>().InitOrganism();
         currentSize++;
     }
     else if (currentSize == simManager.generationSize && !doneGenProcessing)
     {
         organisms         = PopGen.SortByFitness(organisms);
         organisms         = PopGen.SetMatingChances(organisms, simManager.generationSize);
         doneGenProcessing = true;
         UpdateBestOrganism();
         matingPool = PopGen.GenerateMatingPool(organisms);
         generationButton.SetActive(true);
         resetButton.SetActive(true);
     }
 }