-
-
Save carefish/2672de6e8f98a6640ab726c93c3b0b87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using Unity.MLAgents; | |
using Unity.MLAgents.Actuators; | |
using Unity.MLAgents.Sensors; | |
using UnityEngine; | |
public class AgentScript : Agent | |
{ | |
private Transform Target; | |
void Awake() | |
{ | |
} | |
void Start() | |
{ | |
Target = transform.parent.Find("PresentBoxPrefab");// end of arena transform | |
} | |
public void OnEpisodeEnd() | |
{ | |
EndEpisode(); | |
} | |
public override void CollectObservations(VectorSensor sensor) | |
{ | |
// Our position and target position are observed | |
sensor.AddObservation(transform.localPosition); | |
sensor.AddObservation(Target.localPosition); | |
} | |
public override void OnActionReceived(ActionBuffers actions) | |
{ | |
AddReward(-1f / MaxStep); | |
} | |
//public override void Heuristic(in ActionBuffers actionsOut)//do i still need to use Heuristic function when using InputActuator component? | |
//{ | |
//} | |
public void EndOfArena() | |
{ | |
AddReward(1f); | |
EndEpisode(); | |
} | |
public void AgentDied() | |
{ | |
AddReward(-0.5f); | |
EndEpisode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment