void GiveFinalRewardsAndEnd(float blue_reward, float red_reward) { foreach (GameObject player in players) { CarRLAgent_1v1 script = player.GetComponent <CarRLAgent_1v1>(); if (script.GetTeam() == "Blue") { script.AddReward(blue_reward); script.EndEpisode(); } else if (script.GetTeam() == "Red") { script.AddReward(red_reward); script.EndEpisode(); } else { throw new System.Exception("UNKNOWN AGENT TAG"); } } }
public void RewardBallVelocity() { float epsilon = 4.0f; float ball_towards_red = 0.0f; float x_vel = this.gameObject.GetComponent <Rigidbody>().velocity.x; if (x_vel > epsilon) { ball_towards_red = 1; } else if (x_vel < -epsilon) { ball_towards_red = -1; } float reward = 0.2f / players[0].GetComponent <CarRLAgent_1v1>().maxStep; if (ball_towards_red != 0.0f) { foreach (GameObject player in players) { CarRLAgent_1v1 script = player.GetComponent <CarRLAgent_1v1>(); if (script.GetTeam() == "Blue") { script.AddReward(ball_towards_red * reward); } else if (script.GetTeam() == "Red") { script.AddReward(-ball_towards_red * reward); } else { throw new System.Exception("UNKNOWN AGENT TAG"); } } } }