-
Notifications
You must be signed in to change notification settings - Fork 0
/
full_quest.py
1515 lines (1163 loc) · 49.9 KB
/
full_quest.py
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import time
import random
from Radio import Radio
from collections import Counter
from copy import copy
from threading import Timer
import pygame
class MESSAGE:
BATTERY_AVALIABLE = "Универсальная батарея Попова №{id} вставлена"
BATTERY_ABSENT = "ОШИБКА: Универсальная батарея Попова №{id} отсутствует!"
ENGINE_BROKEN = "Почините двигатель"
PRESS_HERABORA = "Когда будете готовы - жмите H.E.R.A.B.O.R.A."
WINNER = "Вы выжили! \nВходная дверь открыта"
FAIL = "Ваша команда погибла! \nВходная дверь открыта"
class LedsIdTable:
FUSE = 23
ROBOT_BODY_LEFT = 12
ROBOT_BODY_RIGHT = 13
ROBOT_HEAD = 16
ENGINE_LEFT = 21
ENGINE_RIGTH = 20
BOX_1 = 8
BOX_2 = 9
BOX_3 = 10
BOX_4 = 11
CB_SLAVE_1="CB_SLAVE_1"
CB_SLAVE_2="CB_SLAVE_2"
hallwayPuzzles = "hallwayPuzzles"
class SOUNDS:
BOX_OPEN = 'coin.wav'
ROBOT_SAY_RIDDLE_FIRST_TIME = 'full_robot.wav'
ROBOT_SAY_RIDDLE_SECOND_TIME = 'robot_second_time.wav'
class ButtonsIdTable:
WIRE_CONNECTION = 11
FUSE = 6
MECHANICS_CARD = 10
ROBOT_HEAD = 8
ENGINE = 9
COMMUTATOR = 7
class AdcIdTable:
RADIO = 0
BOX_LOCK = 1
class CB_CTRL:
"""Named constant for Captain's Bridge controls"""
# Controller 1
# # Buttons
REPULSIVE_DESYNCRONISER = 0
LEVITRON = 1
DEFLECTOR = 2
BIG_RED_BUTTON = 3
KRIVOSHUP_MINUS = 4
KRIVOSHUP_PLUS = 5
SERVO_COOLING_SYSTEM = 6
ULTRAFOTON = 13
REPAIR_NANOROBOTS = 12
C3PO = 14
R2D2 = 15
TETRAGEKS = 16
# # ADC
CLUTCH_REVERSE_CYCLE = 1
SUPER_BRAIN = 0
# Controller 2
# # Buttons
TPBACH_1 = 0
TPBACH_2 = 1
DVORNIKI = 2
ECO_LAZER = 3
BATTERY_1 = 7
BATTERY_2 = 8
BATTERY_3 = 10
BATTERY_4 = 6
PROTON_LAUNCHERS_BATTERY = 4
DARK_MATTER_STABILIZER = 5
HERABORA = 12
TECHNO = 13
UGNETATEL = 14
GIPERBOLOID = 15
ZOND_JS = 16
ZOND_JC = 17
# # ADC
CHAMAEMELUM_NOBILE = 0
DIPSOMANIA_SUPERCHARGER = 1
HYPER_DRIVE_GENERATOR = 2
CONDENSER = 7
DOOR_ENTER = 1
DOOR_ENGINE = 2
DOOR_CAPTAIN = 3
class Colors:
WHITE = [0xfff, 0xfff, 0xfff]
RED = [0xfff, 0x0, 0x0]
LIGHT_RED = [0xff, 0x33, 0x33]
GREEN = [0x0, 0xffF, 0x0]
LIGHT_GREEN = [0x33, 0xff, 0x33]
BLUE = [0x0, 0x0, 0xff]
NONE = [0x0, 0x0, 0x0]
class BASIC_COLORS:
WHITE = [0xFF, 0xFF, 0xFF]
RED = [0xff, 0x0, 0x0]
LIGHT_RED = [0xff, 0x33, 0x33]
GREEN = [0x0, 0xff, 0x0]
LIGHT_GREEN = [0x33, 0xff, 0x33]
BLUE = [0x0, 0x0, 0xff]
NONE = [0x0, 0x0, 0x0]
SAND_STORM = [0xff, 0xa8, 0x12]
# GREEN
MANTIS = [0x3f, 0xff, 0x00]
# PURPLE
PSYCHEDELIC_PURPLE = [0x94, 0x00, 0xd3]
# PINK
RASPBERRY_PINK = [0xff, 0x14, 0x93]
def colorTo12Bit(color):
COLOR_MULT = 16.058
to16Bit = lambda byte: int(byte * COLOR_MULT)
return map(to16Bit, color)
class COLORS:
WHITE = colorTo12Bit(BASIC_COLORS.WHITE)
RED = colorTo12Bit(BASIC_COLORS.RED)
LIGHT_RED = colorTo12Bit(BASIC_COLORS.LIGHT_RED)
GREEN = colorTo12Bit(BASIC_COLORS.GREEN)
LIGHT_GREEN = colorTo12Bit(BASIC_COLORS.LIGHT_GREEN)
BLUE = colorTo12Bit(BASIC_COLORS.BLUE)
NONE = colorTo12Bit(BASIC_COLORS.NONE)
SAND_STORM = colorTo12Bit(BASIC_COLORS.SAND_STORM)
PSYCHEDELIC_PURPLE = colorTo12Bit(BASIC_COLORS.PSYCHEDELIC_PURPLE)
RASPBERRY_PINK = colorTo12Bit(BASIC_COLORS.RASPBERRY_PINK)
class ROOM_LEDS:
# hallwayPuzzles
ENTRANCE_TOP = 6
ENTRANCE_BOTTOM = 14
ENGINE_ROOM = 7
# captainsBridge_1
MAIN_ROOM_TOP = 2
MAIN_ROOM_BOTTOM = 1
CAPTAINTS_BRIDGE = 0
def setRoomLight(master, roomLed, color):
if roomLed in [ROOM_LEDS.ENTRANCE_TOP, ROOM_LEDS.ENTRANCE_BOTTOM, ROOM_LEDS.ENGINE_ROOM]:
slave = hallwayPuzzles
elif roomLed in [ROOM_LEDS.MAIN_ROOM_TOP, ROOM_LEDS.MAIN_ROOM_BOTTOM, ROOM_LEDS.CAPTAINTS_BRIDGE]:
slave = CB_SLAVE_1
else: return
leds = master.getSmartLeds(slave)
leds.setOneLed(roomLed, color)
def RANDOM_ROOM_LIGHT(master):
LIGHT_RANDOM = [COLORS.WHITE, COLORS.RED, COLORS.LIGHT_RED, COLORS.GREEN, COLORS.LIGHT_GREEN, COLORS.BLUE, COLORS.NONE, COLORS.SAND_STORM, COLORS.PSYCHEDELIC_PURPLE, COLORS.RASPBERRY_PINK]
lightRandomLen = len(LIGHT_RANDOM)
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, LIGHT_RANDOM[randColorId])
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, LIGHT_RANDOM[randColorId])
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, LIGHT_RANDOM[randColorId])
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, LIGHT_RANDOM[randColorId])
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, LIGHT_RANDOM[randColorId])
randColorId = random.randint(0, lightRandomLen - 1)
setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, LIGHT_RANDOM[randColorId])
def setLedValue(leds, id, color):
leds[id * 3 + 0] = color[0]
leds[id * 3 + 1] = color[1]
leds[id * 3 + 2] = color[2]
def REQ_QUEST_INIT(master, task, game_state):
# close boxes
#master.setRelays(hallwayPuzzles, [0,0,0,0])
master.setRelays(hallwayPuzzles, [1,1,1,1])
# close doors
# master.setRelays(CB_SLAVE_2, [0,0,0,0])
master.setRelays(CB_SLAVE_2, [1,1,1,1])
master.setSmartLeds(hallwayPuzzles, [0,0,0]*32)
# game_state.quest_room.current_music.play(-1)
AC_ENABLE_INIT_LIGHTS(master, task, game_state)
return True
def AC_ENABLE_INIT_LIGHTS(master, task, game_state):
# Init Lights
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [150, 0, 0])
setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, Colors.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, Colors.NONE)
setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, Colors.NONE)
def REQ_WIRE_CONNECTED(master, task, game_state):
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if wiredConnection:
return True
return False
def REQ_WIRE_CONNECTED_AGAIN(master, task, game_state):
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if wiredConnection:
return True
return False
def REQ_WIRE_DISCONNECTED(master, task, game_state):
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if not wiredConnection:
return True
return False
def AC_ENABLE_WIRE_ROOMS_COLORS(master, task, game_state):
RED = 2000
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, [RED, 0, 0])
time.sleep(2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(.2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
time.sleep(2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(.2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
time.sleep(.1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(.2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
time.sleep(.1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(.2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
time.sleep(.1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(.2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
time.sleep(.1)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
time.sleep(2)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
def AC_ENABLE_WIRE_ROOMS_LIGHT(master, task, game_state):
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.RED)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.RED)
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.RED)
def AC_DISABLE_WIRE_ROOMS_COLORS(master, task, game_state):
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [150, 0, 0])
# setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, Colors.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, Colors.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, Colors.NONE)
# setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, Colors.NONE)
def AC_ENABLE_FUSE_ROOMS_COLORS(master, task, game_state):
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if not wiredConnection:
return
time.sleep(2)
VIOLENT = [232 * 10, 100 *10, 255 * 10]
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, [2000, 2000, 2000])
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, VIOLENT)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [2000, 2000, 2000])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, VIOLENT)
def AC_ENABLE_FUSE_ROOMS_LIGHT(master, task, game_state):
""" only light """
VIOLENT = [232 * 10, 100 *10, 255 * 10]
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, [2000, 2000, 2000])
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, VIOLENT)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [2000, 2000, 2000])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, VIOLENT)
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.GREEN)
def AC_DISABLE_FUSE_ROOMS_COLORS(master, task, game_state):
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if not wiredConnection:
return
RED = 2000
time.sleep(1)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, [RED, 0, 0])
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, [RED, 0, 0])
def AC_ENABLE_ALL_LIGHT(master, task, game_state):
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, COLORS.WHITE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, COLORS.WHITE)
setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, COLORS.WHITE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, COLORS.WHITE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, COLORS.WHITE)
setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, COLORS.WHITE)
def AC_DISABLE_ALL_LIGHT(master, task, game_state):
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, COLORS.NONE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, COLORS.NONE)
setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, COLORS.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, COLORS.NONE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, COLORS.NONE)
setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, COLORS.NONE)
def AC_ENABLE_ROBOT_HEAD_ROOMS_COLORS(master, task, game_state):
VIOLENT = [232 * 10, 100 *10, 255 * 10]
time.sleep(2)
setRoomLight(master, ROOM_LEDS.ENGINE_ROOM, [0, 0, 500])
setRoomLight(master, ROOM_LEDS.CAPTAINTS_BRIDGE, VIOLENT)
def AC_ENABLE_ENGINE_ROOMS_COLORS(master, task, game_state):
WHITE = [ 3500, 3500, 3500 ]
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_BOTTOM, WHITE)
setRoomLight(master, ROOM_LEDS.MAIN_ROOM_TOP, WHITE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_BOTTOM, WHITE)
setRoomLight(master, ROOM_LEDS.ENTRANCE_TOP, WHITE)
def AC_ENABLE_FUSE_PUZZLE(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles)
# smartLeds.setOneLed(LedsIdTable.FUSE, Colors.RED)
fuseConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.FUSE]
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if not wiredConnection:
return
if fuseConnection:
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.GREEN)
else:
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.RED)
def AC_DISABLE_FUSE_PUZZLE(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.FUSE, [0x0, 0x0, 0x0])
def REQ_FUSE_PUZZLE_SOLVED(master, task, game_state):
# return True
buttons = master.getButtons(hallwayPuzzles)
fuseSolved = buttons.get()[ButtonsIdTable.FUSE]
wiredConnection = master.getButtons(hallwayPuzzles).get()[
ButtonsIdTable.WIRE_CONNECTION]
if fuseSolved and wiredConnection:
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.GREEN)
return True
return False
def REQ_FUSE_PUZZLE_SOLVED_AGAIN(master, task, game_state):
# return True
buttons = master.getButtons(hallwayPuzzles)
fuseSolved = buttons.get()[ButtonsIdTable.FUSE]
if fuseSolved:
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.FUSE, Colors.GREEN)
return True
return False
def REQ_FUSE_REMOVED(master, task, game_state):
buttons = master.getButtons(hallwayPuzzles)
fuseSolved = buttons.get()[ButtonsIdTable.FUSE]
# print("Fuse state: {}".format(fuseSolved))
if fuseSolved:
return False
# print("FUSE_REMOVED!!!!!!!!!!")
return True
def AC_ADD_RADIO_BROADCAST(master, task, game_state):
game_state.add_active_task_with_id(12)
def AC_ENABLE_RADIO(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles)
relays = master.getRelays(hallwayPuzzles).get()
if relays[0]:
smartLeds.setOneLed(LedsIdTable.BOX_1, Colors.RED)
else:
smartLeds.setOneLed(LedsIdTable.BOX_1, Colors.BLUE)
if relays[1]:
smartLeds.setOneLed(LedsIdTable.BOX_2, Colors.RED)
else:
smartLeds.setOneLed(LedsIdTable.BOX_2, Colors.BLUE)
if relays[2]:
smartLeds.setOneLed(LedsIdTable.BOX_3, Colors.RED)
else:
smartLeds.setOneLed(LedsIdTable.BOX_3, Colors.BLUE)
if relays[3]:
smartLeds.setOneLed(LedsIdTable.BOX_4, Colors.RED)
else:
smartLeds.setOneLed(LedsIdTable.BOX_4, Colors.BLUE)
RADIO_ENABLE()
radio = None
radioDisabled = False
def RADIO_ENABLE():
global radioDisabled
global radio
if radio is None:
print("========================Radio start!=======================")
radio = Radio(0.5, 0.001)
sounds = [('harp.wav',40.0,80.0), ('island_music_x.wav',120.0,160.0), ('sounds/radioSolveKey.wav',200.0,240.0)]
radio.init_sounds(sounds, 'noize.wav')
radio.start()
radioDisabled = False
def REQ_RADIO_BROADCAST(master, task, game_state):
global radioDisabled
global radio
# import pudb; pudb.set_trace() # XXX BREAKPOINT
if radioDisabled:
radio.set_target_value(0)
return
radioValue = master.getAdc(hallwayPuzzles).get()[AdcIdTable.RADIO]
#print("Radio value: {}".format(radioValue))
if radio:
radio.set_target_value(radioValue)
def AC_DISABLE_RADIO(master, task, game_state):
global radioDisabled
global radio
# radio.stop()
radioDisabled = True
if radio:
radio.set_target_value(0)
#=============== ADDING TASKS =================================================
class TaskIdTable:
WIRE_CONNECTED = 100
WIRE_CONNECTED_AGAIN = 1000
WIRE_DISCONNECTED = 1
FUSE_PUZZLE = 2
FUSE_REMOVED = 3
FUSE_PUZZLE_AGAIN = 2000
# RADIO_ENABLE =
# RADIO_DISABLE = 3
def AC_ADD_CONNECT_WIRE(master, task, game_state):
game_state.add_active_task_with_id(TaskIdTable.WIRE_CONNECTED)
def AC_ADD_CONNECT_WIRE_AGAIN(master, task, game_state):
game_state.add_active_task_with_id(TaskIdTable.WIRE_CONNECTED_AGAIN)
def AC_ADD_DISCONNECT_WIRE(master, task, game_state):
game_state.add_active_task_with_id(TaskIdTable.WIRE_DISCONNECTED)
def AC_ADD_FUSE_PUZZLE(master, task, game_state):
if not game_state.task_with_id_active(TaskIdTable.FUSE_PUZZLE):
game_state.add_active_task_with_id(TaskIdTable.FUSE_PUZZLE)
def AC_ADD_FUSE_PUZZLE_AGAIN(master, task, game_state):
if (not game_state.task_with_id_active(TaskIdTable.FUSE_PUZZLE_AGAIN)) and (not game_state.task_with_id_active(TaskIdTable.FUSE_PUZZLE)):
game_state.add_active_task_with_id(TaskIdTable.FUSE_PUZZLE_AGAIN)
def AC_ADD_FUSE_REMOVED(master, task, game_state):
if not game_state.task_with_id_active(TaskIdTable.FUSE_REMOVED):
game_state.add_active_task_with_id(TaskIdTable.FUSE_REMOVED)
# Включение и Выкл. радио выполняются в action
# def ADD_DISABLE_RADIO(master, task, game_state):
# game_state.add_active_task_with_id(3)
def AC_ADD_MECHANICS_CARD_PUZZLE(master, task, game_state):
game_state.add_active_task_with_id(5)
def AC_ADD_TUMBLER_PUZZLE(master, task, game_state):
game_state.add_active_task_with_id(6)
def AC_ADD_HIDDEN_TUMBLER_PUZZLE(master, task, game_state):
game_state.add_active_task_with_id(7)
def AC_ADD_COMMUTATOR_PUZZLE(master, task, game_state):
game_state.add_active_task_with_id(8)
def AC_ADD_SECRET(master, task, game_state):
game_state.add_active_task_with_id(9)
def AC_ADD_ROBOT_PUZZLE(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.ROBOT_BODY_LEFT, Colors.RED)
smartLeds.setOneLed(LedsIdTable.ROBOT_BODY_RIGHT, Colors.RED)
smartLeds.setOneLed(LedsIdTable.ROBOT_HEAD, Colors.WHITE)
game_state.add_active_task_with_id(10)
def AC_ADD_ROBOT_DISASSEMBLED(master, task, game_state):
game_state.add_active_task_with_id(110)
def AC_ADD_ROBOT_PUZZLE_AGAIN(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.ROBOT_BODY_LEFT, Colors.RED)
smartLeds.setOneLed(LedsIdTable.ROBOT_BODY_RIGHT, Colors.RED)
smartLeds.setOneLed(LedsIdTable.ROBOT_HEAD, Colors.WHITE)
game_state.add_active_task_with_id(111)
def AC_ADD_ENGINE_ROOM_LIGHT(master, task, game_state):
game_state.add_active_task_with_id(11)
def AC_ADD_BATTARIES_PUZZLE(master, task, game_state):
game_state.add_active_task_with_id(13)
def AC_ADD_ACTIVATE_CAPTAIN_BRIDGE(mastre, task, game_state):
game_state.add_active_task_with_id(13)
#===========================================================
def REQ_SECRET_DOORS(master, task, game_state):
return True
buttons = master.getButtons(hallwayPuzzles).get()[12:18]
if buttons[3:6] == [0, 1, 0]:
relays = buttons[0:3]
relays.insert(0, 0)
master.setRelays(CB_SLAVE_2, relays)
return False
def AC_OPEN_FIRST_BOX(master, task, game_state):
print("First box was open!")
smartLeds = master.getSmartLeds(hallwayPuzzles)
# blue, because blue and green are switched
smartLeds.setOneLed(LedsIdTable.BOX_1, Colors.BLUE)
relays = master.getRelays(hallwayPuzzles).get()
relays[0] = 0
master.setRelays(hallwayPuzzles, relays)
beep = pygame.mixer.Sound(SOUNDS.BOX_OPEN)
beep.set_volume(0.3)
beep.play()
def AC_OPEN_SECOND_BOX(master, task, game_state):
print("Second box was open!")
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_2, Colors.BLUE)
relays = master.getRelays(hallwayPuzzles).get()
relays[1] = 0
master.setRelays(hallwayPuzzles, relays)
beep = pygame.mixer.Sound(SOUNDS.BOX_OPEN)
beep.set_volume(0.3)
beep.play()
def AC_OPEN_THIRD_BOX(master, task, game_state):
print("Third box was open!")
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_3, Colors.BLUE)
relays = master.getRelays(hallwayPuzzles).get()
relays[2] = 0
master.setRelays(hallwayPuzzles, relays)
beep = pygame.mixer.Sound(SOUNDS.BOX_OPEN)
beep.set_volume(0.3)
beep.play()
def AC_OPEN_FOURTH_BOX(master, task, game_state):
print("Fourth box was open!")
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_4, Colors.BLUE)
relays = master.getRelays(hallwayPuzzles).get()
relays[3] = 0
master.setRelays(hallwayPuzzles, relays)
beep = pygame.mixer.Sound(SOUNDS.BOX_OPEN)
beep.set_volume(0.3)
beep.play()
def REQ_COMMUTATOR_PUZZLE_SOLVED(master, task, game_state):
# return True
buttons = master.getButtons(hallwayPuzzles).get()
commutatorSolved = buttons[ButtonsIdTable.COMMUTATOR]
if commutatorSolved:
#if True:
return True
return False
class pColors:
RED = Colors.RED
GREEN = Colors.GREEN
BLUE = Colors.BLUE
def toggleHiddenColor(color):
if pColors.RED == color:
color = pColors.BLUE
else:
color = pColors.RED
return color
def toggleVisibleColor(color):
if pColors.GREEN == color:
color = pColors.BLUE
elif pColors.BLUE == color:
color = pColors.RED
else:
color = pColors.GREEN
return color
# initialization value
hiddenPanelColors = [pColors.RED] * 6
visiblePanelColors = [pColors.RED] * 6
visiblePanelSwitchers = []
oldVisiblePanelSwitchers = [None] * 6
hiddenPanelSwitchers = []
oldHiddenPanelSwitchers = [None] * 6
def REQ_TUMBLER_PUZZLE_SOLVED(master, task, game_state):
# return True
global hiddenPanelColors
global visiblePanelColors
global visiblePanelSwitchers
global oldVisiblePanelSwitchers
global hiddenPanelSwitchers
global oldHiddenPanelSwitchers
ELEMENTS_NUMBER = 6
VISIBLE_SWITCHERS_START_NUM = 12
VISIBLE_SWITCHERS_END_NUM = 17
HIDDEN_SWITCHERS_START_NUM = 0
HIDDEN_SWITCHERS_END_NUM = 5
buttons = master.getButtons(hallwayPuzzles).get()
# get values from visible Panel
visiblePanelSwitchers = buttons[VISIBLE_SWITCHERS_START_NUM:
VISIBLE_SWITCHERS_END_NUM + 1]
# doing reverse because num 12 in buttons is 6 on panel
visiblePanelSwitchers.reverse()
hiddenPanelSwitchers = buttons[HIDDEN_SWITCHERS_START_NUM:
HIDDEN_SWITCHERS_END_NUM + 1]
# print("Visible values: {}".format(visiblePanelSwitchers))
# print("Hidden values: {}".format(hiddenPanelSwitchers))
# checked Visible Panel
for index in range(ELEMENTS_NUMBER):
if oldVisiblePanelSwitchers[index] != visiblePanelSwitchers[index]:
# change color for current tumbler
visiblePanelColors[index] = toggleVisibleColor(
visiblePanelColors[index])
# change color for nex tumbler on the same line
# on hidden panel
colorId = index + 1
# if element before inc was been the last on the line
# next element been first on the same line
colorId = colorId % 3
hiddenPanelColors[colorId] = toggleHiddenColor(
hiddenPanelColors[colorId])
# checked Hidden Panel
for index in range(ELEMENTS_NUMBER):
if oldHiddenPanelSwitchers[index] != hiddenPanelSwitchers[index]:
hiddenPanelColors[index] = toggleHiddenColor(hiddenPanelColors[index])
colorId = index + 1
colorId = colorId % 3
visiblePanelColors[colorId] = toggleVisibleColor(
visiblePanelColors[colorId])
# save new values in global lists
oldVisiblePanelSwitchers = visiblePanelSwitchers[:]
oldHiddenPanelSwitchers = hiddenPanelSwitchers[:]
# set new colors on device
# 12 times executed function, whom used Rlock
# It's might be critical
smartLedsObj = master.getSmartLeds(hallwayPuzzles)
for index in range(ELEMENTS_NUMBER):
smartLedsObj.setOneLed(index, hiddenPanelColors[index])
# NUM_LEDS 32, but index from 0 to 31
visibleIndex = smartLedsObj.NUM_LEDS - 1 - index
smartLedsObj.setOneLed(visibleIndex, visiblePanelColors[index])
WINNER_COLOR_LIST= [pColors.BLUE] * 6
visiblePanelState = (WINNER_COLOR_LIST == visiblePanelColors)
hiddenPanelState = (WINNER_COLOR_LIST == hiddenPanelColors)
return visiblePanelState and hiddenPanelState
def AC_ADD_SEQUENCE_PUZZLE(master, task, game_state):
if not game_state.task_with_id_active(4):
game_state.add_active_task_with_id(4)
def REQ_CORRECT_SEQUENCE_ENTERED(master, task, game_state):
# ACTIVATION_SEQUENCE = ['L', 'L', 'R', 'L', 'R', 'R', 'L', 'R']
# Последовательность для открытия
# L - влево; R - вправо
BOX_LOCK_COLOR = Colors.RED
BOX_OPEN_COLOR = Colors.BLUE # Becouse reverse
BOX_BLINK_COLOR = Colors.GREEN
ACTIVATION_SEQUENCE = ['L', 'L', 'R', 'L', 'R', 'L', 'L']
# Позиция в массиве ADC
# ToDo move to head
LOCK_ID = AdcIdTable.BOX_LOCK
# погрешность
ERROR_VALUE = 10
# error between last and current read position
ERROR_POSITION = 10
# like number of reads before data will be analize
READ_DATA_LENGTH = 10
class Time:
# time after sequence clean
LOCK_INACTIVE = 10
# delay between every read
READ_DELAY = 0.01
# blink time for on/off
BLINK = 0.07
class Stage:
READ = 1
CHECK_LOCK_POSITION = 2
BLINK = 3
READ_DELAY = 4
CHECK_SEQUENCE = 5
class BlinkStage:
ON = 5
OFF = 6
IDLE = 7
class State:
def __init__(self, stage=Stage.READ):
self.stage = stage
self.blink_stage = BlinkStage.IDLE
self.blink_time_start = time.time()
self.start_time = time.time()
self.read_data = []
self.player_sequence = []
self.inactive_start = time.time()
self.last_lock_position = None
def checkLockPosition(state):
first_value = state.read_data[0]
for val in state.read_data[1:]:
if abs(val - first_value) > ERROR_VALUE:
state.read_data = []
state.start_time = time.time()
state.stage = Stage.READ_DELAY
return state
# detect lock value
lock_value = Counter(state.read_data).most_common(1)[0][0]
read_data_store = state.read_data[:]
state.read_data = []
# check lock position
if state.last_lock_position is None:
state.last_lock_position = lock_value
gt_default = (lock_value + ERROR_POSITION) <= state.last_lock_position
lt_default = (lock_value - ERROR_POSITION) >= state.last_lock_position
# does it change
if not gt_default and not lt_default:
state.start_time = time.time()
state.stage = Stage.READ_DELAY
# maybe previous value is not so stable as this
state.last_lock_position = lock_value
return state
print("="*80 + "\n==")
print("lastLockPosition: {}, lockPosition: {}"
.format(state.last_lock_position, lock_value))
turn_direction = getTurnDirection(state.last_lock_position, lock_value)
state.player_sequence.append(turn_direction)
state.last_lock_position = lock_value
state.stage = Stage.BLINK
state.blink_stage = BlinkStage.ON
state.inactive_start = time.time()
return state
def turnLeft(lastValue, newValue):
if lastValue == 255 and newValue == 0:
return True
elif lastValue == 0 and newValue == 255:
return False
elif newValue > lastValue:
return True
return False
def turnRigth(lastValue, newValue):
if lastValue == 0 and newValue == 255:
return True
elif lastValue == 255 and newValue == 0:
return False
elif newValue < lastValue:
return True
return False
def getTurnDirection(lastValue, newValue):
if turnLeft(lastValue, newValue):
return "L"
if turnRigth(lastValue, newValue):
return "R"
if task.stack == []:
state = State()
task.stack.append(state)
state = task.stack.pop()
if Stage.READ == state.stage:
value = master.getAdc(hallwayPuzzles).get()[LOCK_ID]
state.read_data.append(value)
if len(state.read_data) > READ_DATA_LENGTH:
state.stage = Stage.CHECK_LOCK_POSITION
else:
state.stage = Stage.READ_DELAY
state.start_time = time.time()
elif Stage.READ_DELAY == state.stage:
wait_time = time.time() - state.start_time
if wait_time > Time.READ_DELAY:
state.stage = Stage.READ
elif Stage.CHECK_LOCK_POSITION == state.stage:
state = checkLockPosition(state)
elif Stage.BLINK == state.stage:
if BlinkStage.ON == state.blink_stage:
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_1, BOX_BLINK_COLOR)
state.blink_time_start = time.time()
state.blink_stage = BlinkStage.OFF
elif BlinkStage.OFF == state.blink_stage:
blink_time = time.time() - state.blink_time_start
if blink_time > Time.BLINK:
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_1, BOX_LOCK_COLOR)
state.blink_stage = BlinkStage.ON
state.stage = Stage.CHECK_SEQUENCE
state.inactive_time = time.time()
elif Stage.CHECK_SEQUENCE == state.stage:
rev_player_sequence = copy(
state.player_sequence[-len(ACTIVATION_SEQUENCE):])
rev_player_sequence.reverse()
print("Player sequence: {} \n reverse: {}"
.format(state.player_sequence, rev_player_sequence))
if ACTIVATION_SEQUENCE == rev_player_sequence:
smartLeds = master.getSmartLeds(hallwayPuzzles)
smartLeds.setOneLed(LedsIdTable.BOX_1, BOX_OPEN_COLOR)
task.stack = []
return True
state.stage = Stage.READ_DELAY
state.start_time = time.time()
inactive_time = time.time() - state.inactive_start
if inactive_time > Time.LOCK_INACTIVE:
state.player_sequence = []
task.stack.append(state)
def REQ_MECHANICS_CARD_USED(master, task, game_state):
# return True
buttons = master.getButtons(hallwayPuzzles).get()
cardUsed = buttons[ButtonsIdTable.MECHANICS_CARD]
if cardUsed:
return True
return False
def AC_ENABLE_TUMBLER_PUZZLE(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles).get()
ledIdStartPosition = 31
for index in range(6):
ledID = ledIdStartPosition - index
setLedValue(smartLeds, ledID, Colors.RED)
setLedValue(smartLeds, index, Colors.RED)
master.setSmartLeds(hallwayPuzzles, smartLeds)
def AC_ENABLE_TUMBLER_PUZZLE_LIGHT_WIN(master, task, game_state):
smartLeds = master.getSmartLeds(hallwayPuzzles).get()
ledIdStartPosition = 31
for index in range(6):
ledID = ledIdStartPosition - index
setLedValue(smartLeds, ledID, Colors.BLUE)
setLedValue(smartLeds, index, Colors.BLUE)
master.setSmartLeds(hallwayPuzzles, smartLeds)
def REQ_ROBOT_ASSEMBLED(master, task, game_state):
# return True
buttons = master.getButtons(hallwayPuzzles)
robotAssembled = buttons.get()[ButtonsIdTable.ROBOT_HEAD]
if robotAssembled:
smartLeds = master.getSmartLeds(hallwayPuzzles)