您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
56 行
1.1 KiB
56 行
1.1 KiB
using Unity.MLAgents.Sensors;
|
|
|
|
|
|
public class GoalSensorComponent : SensorComponent
|
|
{
|
|
public int observationSize;
|
|
public GoalSensor goalSensor;
|
|
/// <summary>
|
|
/// Creates a GoalSensor.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override ISensor CreateSensor()
|
|
{
|
|
goalSensor = new GoalSensor(observationSize);
|
|
return goalSensor;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override int[] GetObservationShape()
|
|
{
|
|
return new[] { observationSize };
|
|
}
|
|
|
|
public void AddGoal(float goal)
|
|
{
|
|
if (goalSensor != null)
|
|
{
|
|
goalSensor.AddObservation(goal);
|
|
}
|
|
}
|
|
|
|
public void AddOneHotGoal(int goal, int range)
|
|
{
|
|
if (goalSensor != null)
|
|
{
|
|
goalSensor.AddOneHotObservation(goal, range);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class GoalSensor : VectorSensor
|
|
{
|
|
|
|
public GoalSensor(int observationSize, string name = null) : base(observationSize)
|
|
{
|
|
if (name == null)
|
|
{
|
|
name = $"GoalSensor_size{observationSize}";
|
|
}
|
|
}
|
|
|
|
public override SensorType GetSensorType()
|
|
{
|
|
return SensorType.Goal;
|
|
}
|
|
}
|