File size: 1,252 Bytes
05c9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Unity.MLAgents.Actuators;
namespace Unity.MLAgents.Tests.Actuators
{
    internal class TestActuator : IActuator
    {
        public ActionBuffers LastActionBuffer;
        public int[][] Masks;
        public bool m_HeuristicCalled;
        public int m_DiscreteBufferSize;

        public TestActuator(ActionSpec actuatorSpace, string name)
        {
            ActionSpec = actuatorSpace;

            Name = name;
        }

        public void OnActionReceived(ActionBuffers actionBuffers)
        {
            LastActionBuffer = actionBuffers;
        }

        public void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
        {
            for (var i = 0; i < Masks.Length; i++)
            {
                foreach (var actionIndex in Masks[i])
                {
                    actionMask.SetActionEnabled(i, actionIndex, false);
                }
            }
        }

        public ActionSpec ActionSpec { get; }

        public string Name { get; }

        public void ResetData()
        {
        }

        public void Heuristic(in ActionBuffers actionBuffersOut)
        {
            m_HeuristicCalled = true;
            m_DiscreteBufferSize = actionBuffersOut.DiscreteActions.Length;
        }
    }
}