コード例 #1
0
    public void HookUpFitnessComponents()
    {
        // Implementing Fitness Later Differently

        for (int i = 0; i < fitnessComponentEvaluationGroup.fitCompList.Count; i++)
        {
            int populationIndex = 0;                  // defaults to player1
            if (currentEvalTicket.focusPopIndex != 0) // if environment is not the focus Pop, set correct playerIndex:
            {
                populationIndex = currentEvalTicket.focusPopIndex - 1;
            }
            switch (fitnessComponentEvaluationGroup.fitCompList[i].sourceDefinition.type)
            {
            case FitnessComponentType.DistanceToEnemy:
                FitCompDistanceToEnemy fitCompDistToTargetSquared = (FitCompDistanceToEnemy)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompDistanceToEnemy;
                fitCompDistToTargetSquared.ownPos   = currentAgentsArray[populationIndex].transform.localPosition;
                fitCompDistToTargetSquared.enemyPos = currentAgentsArray[populationIndex].testModule.enemyTestModule.ownRigidBody2D.transform.localPosition;
                break;

            case FitnessComponentType.Random:
                // handled fully within the FitCompRandom class
                break;

            case FitnessComponentType.WinLoss:
                FitCompWinLoss fitCompWinLoss = (FitCompWinLoss)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompWinLoss;
                fitCompWinLoss.score = agentGameScoresArray[populationIndex];
                break;

            default:
                Debug.LogError("ERROR!!! Fitness Type not found!!! " + fitnessComponentEvaluationGroup.fitCompList[i].sourceDefinition.type.ToString());
                break;
            }
        }
    }
コード例 #2
0
    public void CreateFitnessComponentEvaluationGroup(FitnessManager fitnessManager, int genomeIndex)
    {
        for (int i = 0; i < fitnessManager.fitnessComponentDefinitions.Count; i++)
        {
            switch (fitnessManager.fitnessComponentDefinitions[i].type)
            {
            case FitnessComponentType.DistanceToEnemy:
                FitCompDistanceToEnemy fitCompDistanceToTargetSquared = new FitCompDistanceToEnemy(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompDistanceToTargetSquared);
                break;

            case FitnessComponentType.Random:
                FitCompRandom fitCompRandom = new FitCompRandom(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompRandom);
                break;

            case FitnessComponentType.WinLoss:
                FitCompWinLoss fitCompWinLoss = new FitCompWinLoss(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompWinLoss);
                break;

            default:
                Debug.LogError("No such component type! (" + fitnessManager.fitnessComponentDefinitions[i].type.ToString() + ")");
                break;
            }
        }

        fitnessManager.AddNewFitCompEvalGroup(this, genomeIndex);
    }
コード例 #3
0
    public void CreateFitnessComponentEvaluationGroup(FitnessManager fitnessManager, int genomeIndex)
    {
        for (int i = 0; i < fitnessManager.fitnessComponentDefinitions.Count; i++)
        {
            switch (fitnessManager.fitnessComponentDefinitions[i].type)
            {
            case FitnessComponentType.DistanceToTargetSquared:
                FitCompDistanceToTargetSquared fitCompDistanceToTargetSquared = new FitCompDistanceToTargetSquared(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompDistanceToTargetSquared);
                break;

            case FitnessComponentType.Velocity:
                FitCompVelocity fitCompVelocity = new FitCompVelocity(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompVelocity);
                break;

            case FitnessComponentType.ContactHazard:
                FitCompContactHazard fitCompContactHazard = new FitCompContactHazard(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompContactHazard);
                break;

            case FitnessComponentType.DamageInflicted:
                FitCompDamageInflicted fitCompDamageInflicted = new FitCompDamageInflicted(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompDamageInflicted);
                break;

            case FitnessComponentType.Health:
                FitCompHealth fitCompHealth = new FitCompHealth(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompHealth);
                break;

            case FitnessComponentType.Random:
                FitCompRandom fitCompRandom = new FitCompRandom(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompRandom);
                break;

            case FitnessComponentType.WinLoss:
                FitCompWinLoss fitCompWinLoss = new FitCompWinLoss(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompWinLoss);
                break;

            case FitnessComponentType.DistToOrigin:
                FitCompDistFromOrigin fitCompDistFromOrigin = new FitCompDistFromOrigin(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompDistFromOrigin);
                break;

            case FitnessComponentType.Altitude:
                FitCompAltitude fitCompAltitude = new FitCompAltitude(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompAltitude);
                break;

            case FitnessComponentType.Custom:
                FitCompCustom fitCompCustom = new FitCompCustom(fitnessManager.fitnessComponentDefinitions[i]);
                fitCompList.Add(fitCompCustom);
                break;

            default:
                Debug.LogError("No such component type! (" + fitnessManager.fitnessComponentDefinitions[i].type.ToString() + ")");
                break;
            }
        }

        fitnessManager.AddNewFitCompEvalGroup(this, genomeIndex);
    }
コード例 #4
0
    public void HookUpFitnessComponents()
    {
        for (int i = 0; i < fitnessComponentEvaluationGroup.fitCompList.Count; i++)
        {
            int populationIndex = 0;                  // defaults to player1
            if (currentEvalTicket.focusPopIndex != 0) // if environment is not the focus Pop, set correct playerIndex:
            {
                populationIndex = currentEvalTicket.focusPopIndex - 1;
            }
            switch (fitnessComponentEvaluationGroup.fitCompList[i].sourceDefinition.type)
            {
            case FitnessComponentType.DistanceToTargetSquared:
                FitCompDistanceToTargetSquared fitCompDistToTargetSquared = (FitCompDistanceToTargetSquared)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompDistanceToTargetSquared;
                fitCompDistToTargetSquared.pointA = currentAgentsArray[populationIndex].rootObject.transform.localPosition;
                fitCompDistToTargetSquared.pointB = currentAgentsArray[populationIndex].targetSensorList[0].targetPosition.localPosition;
                break;

            case FitnessComponentType.Velocity:
                FitCompVelocity fitCompVelocity = (FitCompVelocity)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompVelocity;
                fitCompVelocity.vel = currentAgentsArray[populationIndex].rootObject.GetComponent <Rigidbody>().velocity;
                break;

            case FitnessComponentType.ContactHazard:
                FitCompContactHazard fitCompContactHazard = (FitCompContactHazard)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompContactHazard;
                //Debug.Log("NullCheck root: " + currentAgentsArray[populationIndex].rootObject.ToString());
                //Debug.Log("NullCheck component: " + currentAgentsArray[populationIndex].rootObject.GetComponent<ContactSensorComponent>().ToString());
                fitCompContactHazard.contactingHazard = currentAgentsArray[populationIndex].rootObject.GetComponent <ContactSensorComponent>().contact;
                //fitCompContactHazard
                break;

            case FitnessComponentType.DamageInflicted:
                FitCompDamageInflicted fitCompDamageInflicted = (FitCompDamageInflicted)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompDamageInflicted;
                fitCompDamageInflicted.damage = currentAgentsArray[populationIndex].weaponProjectileList[0].damageInflicted[0] + currentAgentsArray[populationIndex].weaponTazerList[0].damageInflicted[0];
                break;

            case FitnessComponentType.Health:
                FitCompHealth fitCompHealth = (FitCompHealth)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompHealth;
                fitCompHealth.health = currentAgentsArray[populationIndex].healthModuleList[0].health;
                break;

            case FitnessComponentType.Random:
                // handled fully within the FitCompRandom class
                break;

            case FitnessComponentType.WinLoss:
                FitCompWinLoss fitCompWinLoss = (FitCompWinLoss)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompWinLoss;
                fitCompWinLoss.score = agentGameScoresArray[populationIndex];
                break;

            case FitnessComponentType.DistToOrigin:
                FitCompDistFromOrigin fitCompDistFromOrigin = (FitCompDistFromOrigin)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompDistFromOrigin;
                fitCompDistFromOrigin.pointA = currentAgentsArray[populationIndex].rootObject.transform.localPosition;
                fitCompDistFromOrigin.pointB = currentEvalTicket.environmentGenome.agentStartPositionsList[populationIndex].agentStartPosition;
                break;

            case FitnessComponentType.Altitude:
                FitCompAltitude fitCompAltitude = (FitCompAltitude)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompAltitude;
                fitCompAltitude.altitude = currentAgentsArray[populationIndex].rootObject.transform.TransformPoint(currentAgentsArray[populationIndex].rootCOM).y - this.transform.position.y - Vector3.Dot(currentAgentsArray[populationIndex].rootObject.transform.up, Physics.gravity.normalized) * 1f;
                break;

            case FitnessComponentType.Custom:
                FitCompCustom fitCompCustom = (FitCompCustom)fitnessComponentEvaluationGroup.fitCompList[i] as FitCompCustom;
                fitCompCustom.custom = currentAgentsArray[populationIndex].segmentList[7].transform.TransformPoint(currentAgentsArray[populationIndex].rootCOM).y - this.transform.position.y - Vector3.Dot(currentAgentsArray[populationIndex].segmentList[7].transform.up, Physics.gravity.normalized) * 1f;;
                break;

            default:
                Debug.LogError("ERROR!!! Fitness Type found!!! " + fitnessComponentEvaluationGroup.fitCompList[i].sourceDefinition.type.ToString());
                break;
            }
        }
    }