-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.asl
281 lines (241 loc) · 5.45 KB
/
collector.asl
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
--Collector ant
--the goal of this ant is to gather food
function main() {
while(Sense Here Home) { turnMoveCell() }
while(!Sense Here Home) {explore()}
while(!Sense Here Home) {exploreWithoutMarking()}
}
function explore() {
if(noMarkHere()) {Mark 0}
if(Sense Ahead Food && !Sense Ahead Home && Move) { if(noMarkHere()) {Mark 1}
collect() }
else { if(Move){ if(noMarkHere()) {Mark 1}
if(Sense Ahead Food && !Sense Ahead Home && Move) { if(noMarkHere()) {Mark 2}
collect() }
else { if(Move){ if(noMarkHere()) {Mark 2}
if(Sense Ahead Food && !Sense Ahead Home && Move) { if(noMarkHere()) {Mark 0}
collect() }
else{ if(Move){}
else {break}
}
}
else {break}
}
}
else {break}
}
}
function exploreWithoutMarking() {
while(!Sense Here Food && !Sense Here Marker(3) && !Sense Here Home){moveCell()}
if(Sense Here Food){collect()}
else { if(Sense Here Marker(3)){followRoute(0,1,2)}
}
}
function collect() {
PickUp
turnaround()
while(!Sense Here Home){goHomeAndMark()}
while(!Sense Here Home){goHome()}
Drop
turnaround()
break
}
function goHomeAndMark() {
if(Sense Here Marker(0)){
if(Sense Ahead Marker(2)) { Mark 3
moveCell()}
else{
Turn Left
times(a,5){if(!Sense Ahead Marker(2)){Turn Left}}
if(Sense Ahead Marker(2)) { Mark 3
moveCell()}
else{break}
}
}
else {
if(Sense Here Marker(1)){
if(Sense Ahead Marker(0)) { Mark 3
moveCell()}
else{
Turn Left
times(a,5){if(!Sense Ahead Marker(0)&& !Sense Ahead Marker(3)){Turn Left}}
if(Sense Ahead Marker(0)) { Mark 3
moveCell()}
else{break}
}
}
else {
if(Sense Here Marker(2)){
if(Sense Ahead Marker(1)) { Mark 3
moveCell()}
else{
Turn Left
times(a,5){if(!Sense Ahead Marker(1)){Turn Left}}
if(Sense Ahead Marker(1)) { Mark 3
moveCell()}
else{break}
}
}
else {
moveCell()
break}
}
}
}
function goHome() {
if(Sense Here Marker(0)||Sense Here Marker(3)){senseALRH(2)}
else { if(Sense Here Marker(1)){
if( Sense Ahead Marker(0)||Sense Ahead Marker(3)) {moveCell()}
else {
Turn Left
times(a,5){if(!Sense Ahead Marker(0) && !Sense Ahead Marker(3)){Turn Left}}
moveCell()
}
}
else {
if(Sense Here Marker(2)){senseALR(1)}
else {
moveCell()
while(noMarkHere()){moveCell()}
}
}
}
}
function senseALR(i) {
if(Sense Ahead Marker(i)) {moveCell()}
else {
if(Sense LeftAhead Marker(i)){ Turn Left
moveCell()}
else{
if(Sense RightAhead Marker(i)){ Turn Right
moveCell()}
else{
turnaround()
if( Sense Ahead Marker(i)) {moveCell()}
else {
if(Sense LeftAhead Marker(i)){ Turn Left
moveCell()}
else {
if(Sense RightAhead Marker(i)){ Turn Right
moveCell()}
else{ turnaround()
moveCell()}
}
}
}
}
}
}
function senseALRH(i) {
if(Sense Ahead Marker(i)||Sense Ahead Home) {moveCell()}
else {
if(Sense LeftAhead Marker(i)||Sense Ahead Home){Turn Left
moveCell()}
else{
if(Sense RightAhead Marker(i)||Sense Ahead Home){ Turn Right
moveCell()}
else{
turnaround()
if( Sense Ahead Marker(i)||Sense Ahead Home) {moveCell()}
else {
if(Sense LeftAhead Marker(i)||Sense Ahead Home){Turn Left
moveCell()}
else {
if(Sense RightAhead Marker(i)||Sense Ahead Home){ Turn Right
moveCell()}
else{ turnaround()
moveCell()}
}
}
}
}
}
}
function followRoute(a,b,c) {
if(Sense Here Marker(3)){
if(Sense Here Marker(a)){
senseALR(b)
}
else {
if(Sense Here Marker(c)){
senseALR(a)
}
else {
if(Sense Here Marker(b)){
senseALR(c)
}
else {
if(Sense Here Food){collect()}
else {
lookAroundForFood()
}
}
}
}
}
else{ lookAroundForFood()}
}
function lookAroundForFood() {
if(Sense Ahead Food) {moveCell()
collect()}
else {
if(Sense LeftAhead Food){
Turn Left
moveCell()
collect()}
else{
if(Sense RightAhead Food){ Turn Right
moveCell()
collect()}
else{
turnaround()
if( Sense Ahead Food) {moveCell()
collect()}
else {
if(Sense LeftAhead Food){ Turn Left
moveCell()
collect()}
else {
if(Sense RightAhead Food){ Turn Right
moveCell()
collect()}
else{ destroyPath() }
}
}
}
}
}
}
function destroyPath() {
while(!Sense Here Home){ senseALRH(3)
Unmark 3}
}
function noMarkHere() {
!Sense Here Marker(0)&& !Sense Here Marker(1)&& !Sense Here Marker(2)&& !Sense Here Marker(3)
}
function noFoodMarkHere() {
!Sense Here Marker(3)
}
function moveCell() {
-- When a move is not possible randomly turn left or right
-- until a move is possible
while (!Move) {
if (Flip 2) {
Turn Right
} else {
Turn Left
}
}
}
function turnMoveCell() {
if (Flip 2) {
while (!Move) {Turn Right}
} else {
while (!Move) {Turn Left}
}
}
function turnaround() {
Turn Left
Turn Left
Turn Left
}