Beispiel #1
0
    void GameOver()
    {
        carRigid.velocity = new Vector3(0, 0, 0);
        currentGenome.setScore((int)distanceTraveled);

        if (distanceTraveled > bestFitness)
        {
            bestFitness          = (int)distanceTraveled;
            bestFitnessText.text = "Best Fitness: " + bestFitness;
        }

        distanceTraveled = 0;
        currentGenomeIndex++;

        if (currentGenomeIndex == NeuroEvolution.population)
        {
            currentGeneration = neuro.nextGeneration();
            currentGenomes    = currentGeneration.getGenomes();

            currentGenomeIndex = 0;

            generationNumber++;
        }

        currentGenome = currentGenomes[currentGenomeIndex];

        updateCanvasText();
    }
Beispiel #2
0
    // Use this for initialization

    void Awake()
    {
        neuro = new NeuroEvolution(13, new int[] { 8 }, 2);

        NeuroEvolution.elitism         = elitism;
        NeuroEvolution.mutationRate    = mutationRate;
        NeuroEvolution.randomBehaviour = randomBehaviour;

        Generation nextGeneration = neuro.nextGeneration();

        currentGeneration = nextGeneration;
        List <Genome> genomes = nextGeneration.getGenomes();

        currentGenomes = genomes;
        currentGenome  = genomes[currentGenomeIndex];

        genomeText.text     = "Genome 1";
        generationText.text = "Generation 1";
        diversityText.text  = "Diversity: " + currentGeneration.diversity;

        listener = new UnityAction(GameOver);
    }