-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequencePush.cs
More file actions
72 lines (60 loc) · 1.66 KB
/
SequencePush.cs
File metadata and controls
72 lines (60 loc) · 1.66 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Threading.Tasks;
using OneOf;
using RLMatrix;
public class SequencePushEnv : IEnvironmentAsync<float[]>
{
public int stepCounter { get; set; }
public int maxSteps { get; set; }
public bool isDone { get; set; }
public OneOf<int, (int, int)> stateSize { get; set; }
public int[] actionSize { get; set; }
float state;
float[] directions;
int direction;
Random random = new Random();
float previousStep;
public SequencePushEnv()
{
InitialiseAsync();
}
public Task<float[]> GetCurrentState()
{
if (isDone)
Reset().Wait(); // Reset if done
return Task.FromResult(new float[] { stepCounter, directions[0], directions[1], directions[2], directions[3] });
}
public void InitialiseAsync()
{
directions = new float[] { 0f, 0f, 0f, 0f };
maxSteps = 20;
isDone = false;
stateSize = 5;
actionSize = new int[] { 4 };
direction = random.Next(0, 3);
//set direction to 1 depending on index
directions[direction] = 1f;
stepCounter = 1;
}
public Task Reset()
{
InitialiseAsync();
return Task.CompletedTask;
}
public Task<(float, bool)> Step(int[] actionsIds)
{
if(isDone)
Reset().Wait(); // Reset if done
stepCounter++;
if (stepCounter > 4)
{
directions = new float[] { 0f, 0f, 0f, 0f };
}
if (stepCounter > maxSteps)
{
isDone = true;
}
float reward = actionsIds[0] == direction ? 1f : -2f;
return Task.FromResult((reward, isDone));
}
}