Skip to content

Instantly share code, notes, and snippets.

@carefish
Created June 7, 2021 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carefish/2672de6e8f98a6640ab726c93c3b0b87 to your computer and use it in GitHub Desktop.
Save carefish/2672de6e8f98a6640ab726c93c3b0b87 to your computer and use it in GitHub Desktop.
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