|
|
|
|
|
|
public static ActionBuffers FromDiscreteActions(float[] discreteActions) |
|
|
|
{ |
|
|
|
return new ActionBuffers(ActionSegment<float>.Empty, discreteActions == null ? ActionSegment<int>.Empty |
|
|
|
: new ActionSegment<int>(Array.ConvertAll(discreteActions, |
|
|
|
x => (int)x))); |
|
|
|
: new ActionSegment<int>(Array.ConvertAll(discreteActions, |
|
|
|
x => (int)x))); |
|
|
|
/// <summary>
|
|
|
|
/// Construct an <see cref="ActionBuffers"/> instance with the continuous and discrete actions that will
|
|
|
|
/// be used.
|
|
|
|
/// /// </summary>
|
|
|
|
/// <param name="continuousActions">The continuous actions to send to an <see cref="IActionReceiver"/>.</param>
|
|
|
|
/// <param name="discreteActions">The discrete actions to send to an <see cref="IActionReceiver"/>.</param>
|
|
|
|
public ActionBuffers(float[] continuousActions, int[] discreteActions) |
|
|
|
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) { } |
|
|
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public interface IActionReceiver |
|
|
|
{ |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The specification of the Action space for this IActionReceiver.
|
|
|
|
/// </summary>
|
|
|
|
/// <seealso cref="ActionSpec"/>
|
|
|
|
ActionSpec ActionSpec { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Method called in order too allow object to execute actions based on the
|
|
|
|
/// <see cref="ActionBuffers"/> contents. The structure of the contents in the <see cref="ActionBuffers"/>
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <seealso cref="IActionReceiver.OnActionReceived"/>
|
|
|
|
void WriteDiscreteActionMask(IDiscreteActionMask actionMask); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Helper methods to be shared by all classes that implement <see cref="IActionReceiver"/>.
|
|
|
|
/// </summary>
|
|
|
|
public static class ActionReceiverExtensions |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Returns the number of discrete branches + the number of continuous actions.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="actionReceiver"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static int TotalNumberOfActions(this IActionReceiver actionReceiver) |
|
|
|
{ |
|
|
|
return actionReceiver.ActionSpec.NumContinuousActions + actionReceiver.ActionSpec.NumDiscreteActions; |
|
|
|
} |
|
|
|
} |
|
|
|
} |