Ejemplo n.º 1
0
    /// <summary>
    /// Gives rewards to agents based on which kind of energycore hit which goal.
    /// goalHit: Which goal was hit
    /// coreType: Which type of energy core hit the goal
    /// </summary>
    public void GoalTouched(AIRobotAgent.Team goalHit, EnergyCoreController.CoreType coreType)
    {
        goalCounter++;
        var rewards = CalculateRewards(goalHit, coreType);

        foreach (var agent in m_BlueAgents)
        {
            agent.robotScript.AddReward(rewards.blueReward);
        }
        foreach (var agent in m_RedAgents)
        {
            agent.robotScript.AddReward(rewards.redReward);
        }

        var   amountOfAgents        = m_BlueAgents.Count + m_RedAgents.Count;
        float EndEpisodeOnNegReward = m_ResetParams.GetWithDefault(
            "end_episode_on_neg_reward_if_single_agent",
            m_EndEpisodeOnNegRewardIfSingleAgent == true ? 1.0f : 0.0f);

        if (amountOfAgents == 1 && EndEpisodeOnNegReward > 0)
        {
            if (m_BlueAgents.Count > 0 && rewards.blueReward < 0)
            {
                EndEpisodeForAgents();
            }
            else if (m_RedAgents.Count > 0 && rewards.redReward < 0)
            {
                EndEpisodeForAgents();
            }
        }
        // All energy cores have been put in goals. Reset arena.
        if (goalCounter >= (m_NegEnergyCores.Count + m_PosEnergyCores.Count))
        {
            EndEpisodeForAgents();
        }

        Material groundMat = null;

        if (rewards.blueReward > 0)
        {
            groundMat = m_AIRobotSettings.blueTeamSuccessMat;
        }
        else
        {
            groundMat = m_AIRobotSettings.redTeamSuccessMat;
        }
        StartCoroutine(GoalScoredSwapGroundMaterial(groundMat, 0.5f));
    }
Ejemplo n.º 2
0
    Rewards CalculateRewards(AIRobotAgent.Team goalHit, EnergyCoreController.CoreType coreType)
    {
        int redReward  = 0;
        int blueReward = 0;

        if (goalHit == AIRobotAgent.Team.Blue)
        {
            // Blue team got positive core.
            if (coreType == EnergyCoreController.CoreType.Positive)
            {
                redReward  = posECoreHitsOpponentGoalReward;
                blueReward = posECoreHitsOwnGoalReward;
            }
            // Blue team got negative core.
            else
            {
                redReward  = negECoreHitsOpponentGoalReward;
                blueReward = negECoreHitsOwnGoalReward;
            }
        }
        else
        {
            // Red team got positive core.
            if (coreType == EnergyCoreController.CoreType.Positive)
            {
                redReward  = posECoreHitsOwnGoalReward;
                blueReward = posECoreHitsOpponentGoalReward;
            }
            // Red team got negative core.
            else
            {
                redReward  = negECoreHitsOwnGoalReward;
                blueReward = negECoreHitsOpponentGoalReward;
            }
        }

        var rewards = new Rewards()
        {
            blueReward = blueReward, redReward = redReward
        };

        return(rewards);
    }