Exemple #1
0
    public void MutateTo(Genes otherParent, Genes child)
    {
        child.sightDistance = Random.Range(0, 100) > 50 ? this.sightDistance : otherParent.sightDistance;
        child.eatingSpeed   = Random.Range(0, 100) > 50 ? this.eatingSpeed : otherParent.eatingSpeed;
        child.maxHealth     = Random.Range(0, 100) > 50 ? this.maxHealth : otherParent.maxHealth;
        child.forwardSpeed  = Random.Range(0, 100) > 50 ? this.forwardSpeed : otherParent.forwardSpeed;
        child.turnSpeed     = Random.Range(0, 100) > 50 ? this.turnSpeed : otherParent.turnSpeed;

        int mutate = Random.Range(0, 5);

        switch (mutate)
        {
        case 0: child.sightDistance = this.mutateVar(child.sightDistance); break;

        case 1: child.eatingSpeed = mutateVar(child.eatingSpeed); break;

        case 2: child.maxHealth = (int)mutateVar(child.maxHealth); break;

        case 3: child.forwardSpeed = mutateVar(child.forwardSpeed); break;

        case 4: child.turnSpeed = mutateVar(child.turnSpeed); break;
        }
        child.Setup();
    }