예제 #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;
            }
        }
    }
    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);
    }