-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBrain.jack
54 lines (45 loc) · 1.07 KB
/
Brain.jack
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
/**
* The Brain module, used to tell dots how to move
*/
class Brain {
field Array directions;
field int step;
static int brainSize;
function void config(int _brainSize) {
let brainSize = _brainSize;
}
function int getBrainSize() {
return brainSize;
}
constructor Brain new() {
var int i;
let step = -1;
let directions = Array.new(brainSize);
while (i < brainSize) {
let directions[i] = AccelerationVectorPair.random();
let i = i + 1;
}
return this;
}
constructor Brain newWithDirections(Array _directions) {
let step = -1;
let directions = _directions;
return this;
}
method void instantiate() {
let step = -1;
}
method Array getDirections() {
return directions;
}
method void incStep() {
let step = step + 1;
}
method int getStep() {
return step + 1;
}
method int getNextDirection() {
let step = step + 1;
return directions[step];
}
}