Example #1
0
    private DNA9_4 Reproduction(List <DNA9_4> pool)
    {
        // Choose a random mother and father to reproduce.
        DNA9_4 mother = pool[Random.Range(0, pool.Count)];
        DNA9_4 father = pool[Random.Range(0, pool.Count)];
        DNA9_4 child  = mother.Crossover(father);

        // Add some mutation to the child.
        child.Mutate(mutationRate);
        return(child);
    }
    private void Start()
    {
        // Gather the image components of each transform.
        // We will use these images to change the fill color,
        // and we will use the transforms to change the sizing/layout.
        faceEdgeImage = faceEdge.GetComponent <Image>();
        mouthImage    = mouth.GetComponent <Image>();
        leftEyeImage  = leftEye.GetComponent <Image>();
        rightEyeImage = rightEye.GetComponent <Image>();

        // Generate a new random DNA for this face.
        DNA = new DNA9_4();
        Draw();
    }
    public DNA9_4 Crossover(DNA9_4 partner)
    {
        DNA9_4 child = new DNA9_4();

        // Inherit some genes from each partner.
        int midpointIndex = Random.Range(0, genes.Length);

        for (int i = 0; i < genes.Length; i++)
        {
            if (i > midpointIndex)
            {
                child.genes[i] = genes[i];
            }
            else
            {
                child.genes[i] = partner.genes[i];
            }
        }

        return(child);
    }