-
Notifications
You must be signed in to change notification settings - Fork 2
/
codeCell.js
96 lines (76 loc) · 2.43 KB
/
codeCell.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import program from 'program';
import core from 'core';
let codeCells = {
/**
Conveyor
Moves execution UP to the next cell
Makes no changes to the tape
*/
Conveyor: function Conveyor(head) {
return [false, null, program.directions.UP];
},
/**
CrossConveyor
Moves execution UP if the previous facing was UP or DOWN
Moves execution RIGHT if the previous facing was RIGHT or LEFT
Makes no changes to the tape
(This cell, like conveyor, will handle orientation implicitly by letting the default orientation be ^>)
*/
CrossConveyor: function CrossConveyor(head, previousFacing) {
if (previousFacing.equals(program.directions.UP) || previousFacing.equals(program.directions.DOWN)) {
return [false, null, program.directions.UP];
} else if (previousFacing.equals(program.directions.LEFT) || previousFacing.equals(program.directions.RIGHT)) {
return [false, null, program.directions.RIGHT];
}
},
/**
BranchBR
If head is RED, pop tape and move LEFT
If head is BLUE, pop tape and move RIGHT
Otherwise, don't pop and move UP
*/
BranchBR: function BranchBR(head) {
if (head === core.RED) {
return [true, null, program.directions.LEFT];
}
if (head === core.BLUE) {
return [true, null, program.directions.RIGHT];
}
return [false, null, program.directions.UP];
},
/**
BranchGY
If head is GREEN, pop tape and move LEFT
If head is YELLOW, pop tape and move RIGHT
Otherwise, don't pop and move UP
*/
BranchGY: function BranchGY(head) {
if (head === core.GREEN) {
return [true, null, program.directions.LEFT];
}
if (head === core.YELLOW) {
return [true, null, program.directions.RIGHT];
}
return [false, null, program.directions.UP];
},
/**
Writers
Append <color>
Move UP
*/
WriteB: function WriteB(head) {
return [false, core.BLUE, program.directions.UP];
},
WriteR: function WriteR(head) {
return [false, core.RED, program.directions.UP];
},
WriteG: function WriteG(head) {
return [false, core.GREEN, program.directions.UP];
},
WriteY: function WriteY(head) {
return [false, core.YELLOW, program.directions.UP];
}
};
export default {
codeCells: codeCells
};