using System; using System.Linq; namespace Unity.MLAgents.Actuators { /// /// A structure that wraps the s for a particular and is /// used when is called. /// internal readonly struct ActionBuffers { /// /// An empty action buffer. /// public static ActionBuffers Empty = new ActionBuffers(ActionSegment.Empty, ActionSegment.Empty); /// /// Holds the Continuous to be used by an . /// public ActionSegment ContinuousActions { get; } /// /// Holds the Discrete to be used by an . /// public ActionSegment DiscreteActions { get; } /// /// Construct an instance with the continuous and discrete actions that will /// be used. /// /// The continuous actions to send to an . /// The discrete actions to send to an . public ActionBuffers(ActionSegment continuousActions, ActionSegment discreteActions) { ContinuousActions = continuousActions; DiscreteActions = discreteActions; } /// public override bool Equals(object obj) { if (!(obj is ActionBuffers)) { return false; } var ab = (ActionBuffers)obj; return ab.ContinuousActions.SequenceEqual(ContinuousActions) && ab.DiscreteActions.SequenceEqual(DiscreteActions); } /// public override int GetHashCode() { unchecked { return (ContinuousActions.GetHashCode() * 397) ^ DiscreteActions.GetHashCode(); } } } /// /// An interface that describes an object that can receive actions from a Reinforcement Learning network. /// internal interface IActionReceiver { /// /// The specification of the Action space for this IActionReceiver. /// /// ActionSpec ActionSpec { get; } /// /// Method called in order too allow object to execute actions based on the /// contents. The structure of the contents in the /// are defined by the . /// /// The data structure containing the action buffers for this object. void OnActionReceived(ActionBuffers actionBuffers); /// /// Implement `WriteDiscreteActionMask()` to modify the masks for discrete /// actions. When using discrete actions, the agent will not perform the masked /// action. /// /// /// The action mask for the agent. /// /// /// When using Discrete Control, you can prevent the Agent from using a certain /// action by masking it with . /// /// See [Agents - Actions] for more information on masking actions. /// /// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_4_docs/docs/Learning-Environment-Design-Agents.md#actions /// /// void WriteDiscreteActionMask(IDiscreteActionMask actionMask); } }