-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXGridState.java
More file actions
78 lines (52 loc) · 1.39 KB
/
EXGridState.java
File metadata and controls
78 lines (52 loc) · 1.39 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
package myProj;
import burlap.mdp.core.state.MutableState;
import burlap.mdp.core.state.StateUtilities;
import burlap.mdp.core.state.UnknownKeyException;
import burlap.mdp.core.state.annotations.DeepCopyState;
import java.util.Arrays;
import java.util.List;
import static myProj.ExampleGridWorld.VAR_X;
import static myProj.ExampleGridWorld.VAR_Y;
@DeepCopyState
public class EXGridState implements MutableState {
public int x;
public int y;
private final static List<Object> keys = Arrays.<Object>asList(VAR_X, VAR_Y);
public EXGridState() {
}
public EXGridState(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public MutableState set(Object variableKey, Object value) {
if (variableKey.equals(VAR_X)) {
this.x = StateUtilities.stringOrNumber(value).intValue();
} else if (variableKey.equals(VAR_Y)) {
this.y = StateUtilities.stringOrNumber(value).intValue();
} else {
throw new UnknownKeyException(variableKey);
}
return this;
}
public List<Object> variableKeys() {
return keys;
}
@Override
public Object get(Object variableKey) {
if (variableKey.equals(VAR_X)) {
return x;
} else if (variableKey.equals(VAR_Y)) {
return y;
}
throw new UnknownKeyException(variableKey);
}
@Override
public EXGridState copy() {
return new EXGridState(x, y);
}
@Override
public String toString() {
return StateUtilities.stateToString(this);
}
}