namespace Unity.MLAgents.Actuators
{
///
/// IActuator implementation that forwards to an .
///
internal class VectorActuator : IActuator
{
IActionReceiver m_ActionReceiver;
ActionBuffers m_ActionBuffers;
internal ActionBuffers ActionBuffers
{
get => m_ActionBuffers;
private set => m_ActionBuffers = value;
}
///
/// Create a VectorActuator that forwards to the provided IActionReceiver.
///
/// The used for OnActionReceived and WriteDiscreteActionMask.
///
///
public VectorActuator(IActionReceiver actionReceiver,
ActionSpec actionSpec,
string name = "VectorActuator")
{
m_ActionReceiver = actionReceiver;
ActionSpec = actionSpec;
string suffix;
if (actionSpec.NumContinuousActions == 0)
{
suffix = "-Discrete";
}
else if (actionSpec.NumDiscreteActions == 0)
{
suffix = "-Continuous";
}
else
{
suffix = $"-Continuous-{actionSpec.NumContinuousActions}-Discrete-{actionSpec.NumDiscreteActions}";
}
Name = name + suffix;
}
///
public void ResetData()
{
m_ActionBuffers = ActionBuffers.Empty;
}
///
public void OnActionReceived(ActionBuffers actionBuffers)
{
ActionBuffers = actionBuffers;
m_ActionReceiver.OnActionReceived(ActionBuffers);
}
///
public void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{
m_ActionReceiver.WriteDiscreteActionMask(actionMask);
}
///
public ActionSpec ActionSpec { get; }
///
public string Name { get; }
}
}