Repository navigation
Expand file tree
/
Copy pathscript.py
More file actions
487 lines (420 loc) · 20 KB
/
Copy pathscript.py
File metadata and controls
487 lines (420 loc) · 20 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
class Story:
def __init__(self):
self.step = 0
self.node = 0
self.done = False
pass
# utility functions
def set_next_node(self, sensor_input):
if self.step == 0: # at (step=0, node=0)
if self.node == 0:
if sensor_input == 1: # center button press
self.step = 1 # go to (step=1, node=0)
print("Going to 1,0")
# otherwise, stay at (0,0) and re-read instructions
elif self.step == 1: # at (step=1, node=0)
if sensor_input != -1: # recieved input
self.step = 2 # move to next step = 2
if sensor_input == 0: # touch sensor press
self.node = 0 # go to (step=2, node=0)
elif sensor_input == 1: # center button press
self.node = 1 # go to (step=2, node=1)
elif self.step == 2:
if sensor_input != -1: # recieved input
self.step = 3 # move to next step =3
if self.node == 0: # at (step=2, node=0)
if sensor_input == 0: # input == touch sensor press
self.node = 0 # go to (step=3, node=0)
elif sensor_input == 1: # input == center button press
self.node = 1 # go to (step=3, node=1)
elif self.node == 1: # at (step=2, node=1)
if sensor_input == 0: # input == touch sensor press
self.node = 1 # go to (step=3, node=1)
elif sensor_input == 1: # input == center button press
self.node = 2 # go to (step=3, node=2)
elif self.step == 3:
if sensor_input != -1: # recieved input
self.step = 4 # move to next step = 4
elif self.node == 0: # at (step=3, node=0)
if sensor_input == 0: # input == touch sensor press
self.node = 0 # go to (step=4, node=0)
elif sensor_input == 1: # input == center button press
self.node = 1 # go to (step=4, node=1)
elif self.node == 1: # at (step=3, node=1)
if sensor_input == 0: # input == touch sensor press
self.node = 0 # go to (step=4, node=0)
elif sensor_input == 1: # input == center button press
self.node = 1 # go to (step=4, node=1)
elif self.node == 2: # at (step=3, node=2)
if sensor_input == 0: # input == touch sensor press
self.node = 2 # go to (step=4, node=2)
elif sensor_input == 1: # input == center button press
self.node = 3 # go to (step=4, node=3)
elif self.step == 4:
if sensor_input != -1:
self.step = 5 # move to next step = 5
if self.node == 0: # step 4, node 0
if sensor_input == 0: # input = touch sensor
self.node = 1 # go to step 5, node 1
elif sensor_input == 1: # input = center button
self.node = 0 # go to step 5 node 0
elif self.node == 1: # step 4, node 1
if sensor_input == 0: # input = touch sensor
self.node = 0 # go to step 5, node 0
elif sensor_input == 1: # input = center button
self.node = 1 # go to step 5 node 1
elif self.node == 2: # at step 4 node 2
if sensor_input == 0: # input = touch sensor
self.node = 2 # go to step 5 node 2
elif sensor_input == 1: # input = center button
self.mode = 3 # go to step 5 node 3
elif self.node == 3: # at step 4 node 3
if sensor_input == 0: # input = touch sensor
self.node = 2 # go to step 5 node 2
elif sensor_input == 1: # input = center button
self.node = 3
elif self.step == 5:
if sensor_input != -1:
self.step = 6 # move to next step = 6
if self.node == 0: # at step 5 node 0
if sensor_input == 0: # input = touch sensor
self.node = 0 # go to step 6 node 0
elif sensor_input == 1: # input = center button
self.node = 1 # go to step 6 node 1
elif self.node == 1: # at step 5 node 1
if sensor_input == 0: # input = touch sensor
self.node = 2 # go to step 6 node 2
elif sensor_input == 1: # input = center button
self.node = 3 # go to step 6 node 3
elif self.node == 2: # at step 5 node 2
if sensor_input == 0: # input = touch sensor
self.node = 2 # go to step 6 node 2
elif sensor_input == 1: # input = center button
self.node = 3 # go to step 6 node 3
elif self.node == 3: # at step 5 node 3
if sensor_input == 0: # input = touch sensor
self.node = 3 # go to step 6 node 3
elif sensor_input == 1: # input = center button
self.node = 2 # go to step 6 node 2
elif self.step == 6:
if sensor_input != -1:
self.step = 7 # move to next step = 6
if self.node == 0: # at step 6 node 0
if sensor_input == 0: # input = touch sensor
self.node = 0 # go to step 7 node 0
elif sensor_input == 1: # input = center button
self.node = 1 # go to step 7 node 1
elif self.node == 1: # at step 6 node 1
if sensor_input == 0: # input = touch sensor
self.node = 0 # go to step 7 node 0
elif sensor_input == 1: # input = center button
self.node = 1 # go to step 7 node 1
elif self.node == 2: # at step 6 node 2
if sensor_input == 0: # input = touch sensor
self.node = 1 # go to step 7 node 1
elif sensor_input == 1: # input = center button
self.node = 2 # go to step 7 node 2
elif self.node == 3: # at step 5 node 3
if sensor_input == 0: # input = touch sensor
self.node = 2 # go to step 7 node 2
elif sensor_input == 1: # input = center button
self.node = 3 # go to step 7 node 3
elif self.step == 7:
self.step = 8
self.node = 0
print('at (step=',self.step,', node=',self.node,')')
def get_current_step(self):
return self.step
def get_current_node_text(self, robot_form_factor):
if self.step == 0:
if self.node == 0:
return self.step_0_node_0(robot_form_factor)
if self.step == 1:
if self.node == 0:
return self.step_1_node_0(robot_form_factor)
if self.step == 2:
if self.node == 0:
return self.step_2_node_0(robot_form_factor)
if self.node == 1:
return self.step_2_node_1(robot_form_factor)
if self.step == 3:
if self.node == 0:
return self.step_3_node_0(robot_form_factor)
if self.node == 1:
return self.step_3_node_1(robot_form_factor)
if self.node == 2:
return self.step_3_node_2(robot_form_factor)
if self.node == 3:
return self.step_3_node_3(robot_form_factor)
if self.step == 4:
if self.node == 0:
return self.step_4_node_0(robot_form_factor)
if self.node == 1:
return self.step_4_node_1(robot_form_factor)
if self.node == 2:
return self.step_4_node_2(robot_form_factor)
if self.node == 3:
return self.step_4_node_3(robot_form_factor)
if self.step == 5:
if self.node == 0:
return self.step_5_node_0(robot_form_factor)
if self.node == 1:
return self.step_5_node_1(robot_form_factor)
if self.node == 2:
return self.step_5_node_2(robot_form_factor)
if self.node == 3:
return self.step_5_node_3(robot_form_factor)
if self.step == 6:
if self.node == 0:
return self.step_6_node_0(robot_form_factor)
if self.node == 1:
return self.step_6_node_1(robot_form_factor)
if self.node == 2:
return self.step_6_node_2(robot_form_factor)
if self.node == 3:
return self.step_6_node_3(robot_form_factor)
if self.step == 7:
if self.node == 0:
return self.step_7_node_0()
if self.node == 1:
return self.step_7_node_1()
if self.node == 2:
return self.step_7_node_2()
if self.node == 3:
return self.step_7_node_3()
def get_current_node_action_function_name(self):
return "step_" + str(self.step) + "_node_" + str(self.node) + "_action"
def is_current_step_end(self):
if self.step == 8:
return True
else:
return False
def get_form_specific_action(self, form):
if form == 0: # puppy
return "pat my back "
if form == 1: # gyroboy
return "hold my hand "
if form == 2: # car
return "honk the horn "
return "press the touch sensor "
# Step 0
def step_0_node_0(self, form):
instructions = (
"Welcome! Today, we are going to tell a story together. "
"At each step, I will give you two choices. "
"For one choice, you will " +
self.get_form_specific_action(form) +
"For the second choice, you will push the button at the center of the keypad. "
"If you would like to hear the instructions again, " +
self.get_form_specific_action(form) +
"If you understand, press the center button."
)
return instructions
# Step 1
def step_1_node_0(self, form):
instructions = (
"Great! I’m so excited, because I need some help delivering a top-secret letter to special agent double oh seven, "
"but I can’t remember where to find them. "
"We are in Halligan, but we can’t go out the front door. "
"Should we call a helicopter from the roof, "
"or should we sneak out through the vents? " +
self.get_form_specific_action(form) +
" to take the vents. "
"Press the center button to take the helicopter."
)
return instructions
# Step 2
def step_2_node_0(self, form):
instructions = (
"The vents are dark, and we’re at a cross-roads. "
"Which way should we check first? " +
self.get_form_specific_action(form) +
" to turn left. "
"Press the center button to turn right."
)
return instructions
def step_2_node_1(self, form):
instructions = (
"The helicopter is here and we are in the air! "
"But, I think someone spotted us, because we are being followed. "
"What should we do? " +
self.get_form_specific_action(form) +
" to parachute out of the plane. "
"Press the center button to emergency land on top of the library."
)
return instructions
def step_3_node_0(self, form):
instructions = (
"Oh no, I think we’re lost! Do you want to turn around? " +
self.get_form_specific_action(form) +
" to keep going. "
"Press the center button to turn around."
)
return instructions
def step_3_node_1(self, form):
instructions = (
"You landed on top of Dunkin Donuts. "
"Are you hungry? " +
self.get_form_specific_action(form) +
" to stop for a snack. "
"Press the center button to continue without stopping."
)
return instructions
def step_3_node_2(self, form):
instructions = (
"They’re still on our tail! Quick, we need a distraction. "
"Should we throw a banana peel or try on a silly disguise?" +
self.get_form_specific_action(form) +
" to throw the banana peel. "
"Press the center button to put on a fake mustache."
)
return instructions
def step_3_node_3(self, form):
instructions = (
"How weird, we ended up in a Dunkin Donuts. "
"Are you hungry? " +
self.get_form_specific_action(form) +
" stop for a snack. "
"Press the center button to continue without stopping."
)
return instructions
def step_4_node_0(self, form):
instructions = (
"We wound up in a Dunkin Donuts and we stopped for a donut. Yum! "
"But I think I spot someone following us outside! "
"What should we do as a distraction? " +
self.get_form_specific_action(form) +
" to sneak out the back door. "
"Press the center button to challenge them to a race."
)
return instructions
def step_4_node_1(self, form):
instructions = (
"Oh no, I think someone is following us, and they’ve spotted us. What should we do? " +
self.get_form_specific_action(form) +
" to challenge them to a race. "
"Press the center button to hide in the alley outside."
)
return instructions
def step_4_node_2(self, form):
instructions = (
"Wow, they’re so clumsy. But that was the perfect distraction to give us time to get away! "
"Now that we’re outside, where should we check? " +
self.get_form_specific_action(form) +
" to run out onto the street. "
"Press the center button to call out for help."
)
return instructions
def step_4_node_3(self, form):
instructions = (
"Wow, I can’t believe those other people don’t recognize us. "
"Now that they’re distracted, where should we check? " +
self.get_form_specific_action(form) +
" to run out onto the street. "
"Press the center button to call out for help."
)
return instructions
def step_5_node_0(self, form):
instructions = (
"There is no other choice but to face the people following us. "
"We can challenge them to a contest to see who they are and try to get information from them. "
"Let’s challenge them to an arm wrestle. " +
self.get_form_specific_action(form) +
" to use your left arm. "
"Press the center button to use your right arm."
)
return instructions
def step_5_node_1(self,form):
instructions = (
"Let’s take our chances and sneak out through the back door! "
"It looks like there’s no one there, so let's run down the street to lose them. "
"What direction should we run towards? " +
self.get_form_specific_action(form) +
" to turn towards the river. "
"Press the center button to turn towards the dining hall."
)
return instructions
def step_5_node_2(self, form):
instructions = (
"Ok, we are out on the street. "
"We could head for the river, or we could go into the dining hall. " +
self.get_form_specific_action(form) +
" to turn towards the river. "
"Press the center button to duck into the dining hall."
)
return instructions
def step_6_node_0(self, form):
instructions = (
"We best them with our strength, so they must tell us where the special agent is. "
"They give us the answer. But do we trust them? " +
self.get_form_specific_action(form) +
" if you do not trust them. "
"Press the center button if you do trust them."
)
return instructions
def step_6_node_1(self, form):
instructions = (
"We cannot overcome the strength of our opponent. "
"However, they give us some information anyways, "
"and they tell us that the special agent is hiding on the bus next to the ferry. "
"Should we trust them? " +
self.get_form_specific_action(form) +
" if you do trust them. "
"Press the center button if you do not trust them."
)
return instructions
def step_6_node_2(self, form):
instructions = (
"We run towards the river. "
"The best way to get distance from our pursuer is to hop into a boat. "
"We look over and see that there are two possible sources of transport in front of us. "
"Which one should we choose? " +
self.get_form_specific_action(form) +
" to take the ferry that is leavin the dock. "
"Press the center button to get in a row boat and enter the head of the charles. "
)
return instructions
def step_6_node_3(self, form):
instructions = (
"We run into the dining hall and hide among the crowd. "
"Since we’re here, we may as well stop for a snack! What should we eat? " +
self.get_form_specific_action(form) +
" to have get an Italian sandwich from the deli. "
"Press the center button to have a bowl of frosted mini wheats."
)
return instructions
def step_7_node_0(self):
instructions = (
"They lied to you. They sent on a wild goose chase across the country, "
"and we are never able to deliver the letter."
)
return instructions
def step_7_node_1(self):
intructions = (
"With its powerful engines, the ferry is surely the way to go. "
"We hop on, and it takes us to another port where we run onto a bus. "
"The bus travels for half an hour, and when it arrives at the final stop, secret agent 007 is there, waiting to receive the letter. "
"Good job!"
)
return instructions
def step_7_node_2(self):
instructions = (
"You find someone who is waiting there. "
"You speak to them, and they tell you they are not the recipient of the letter! "
"Unfortunately you are not in the right place, but this mysterious person can take over your mission and deliver the letter."
)
return instructions
def step_7_node_3(self):
instructions = (
"You search everywhere, but you cannot find anyone. "
"You realize that you are in the wrong place, and you will have to re-start your search for the secret agent tomorrow."
)
return instructions
# if __name__ == '__main__':
# story = Story()
# while not story.is_current_step_end():
# print(story.get_current_node_text(0))
# sensor_input = int(input("0 = touch sensor; 1 = center button: "))
# story.set_next_node(sensor_input)
# print(sensor_input)
# print(story.get_current_step())