Example #1
0
    private void Start()
    {
        int seed = Random.Range(0, 10000);

        Random.InitState(seed);
        Debug.Log("Seed: " + seed);
        CPPN cppn1 = new CPPN(3, 2, neuronIA, connectionIA);

        cppn1.printGenome();
        CPPN cppn2 = new CPPN(3, 2, neuronIA, connectionIA);

        cppn2.printGenome();
        CPPN.Genome genome = CPPNLib.Crossover(cppn1.genome, cppn2.genome);
        genome.mutate(neuronIA, connectionIA);
        cppn = new CPPN(genome, neuronIA, connectionIA);
        cppn.printGenome();
        Debug.Log("fitness: " + Fitness(cppn, 100));
        rb = GetComponent <Rigidbody>();
    }
Example #2
0
    private CPPN createFromWinnerAndGetWinner(CPPN cppn, int amount, int evaluationIterations)
    {
        CPPN  winner      = cppn;
        float winnerScore = fitness(cppn, evaluationIterations);

        for (int i = 0; i < amount; i++)
        {
            CPPN.Genome genome = cppn.genome.copy();
            genome.mutate(neuronIA, connectionIA);
            CPPN  newCppn = new CPPN(genome, neuronIA, connectionIA);
            float score   = fitness(newCppn, evaluationIterations);
            if (score > winnerScore)
            {
                winner      = newCppn;
                winnerScore = score;
            }
        }
        Debug.Log("Won with " + winnerScore);
        return(winner);
    }