-
Notifications
You must be signed in to change notification settings - Fork 0
/
ktane_modules_solvers.py
1339 lines (1243 loc) · 38.3 KB
/
ktane_modules_solvers.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
""" A Library of solvers for the included modules in the game Keep talking nobody explodes"""
import find_path as pathfinder
def wires(serial_num: list, wire_list: list): # Module for Simple wires
"""
args:
:param serial_num: List form of the serial number ['A','L','5','0','F','2']
:param wire_list: The colors of the of the wires in list form e.g. ['red','blue','black','white']
:return: A int of the wire to be cut
"""
# Variable creation
number_of_yellow_wires = 0
number_of_red_wires = 0
number_of_blue_wires = 0
number_of_black_wires = 0
number_of_white_wires = 0
# Data gathering from input
number_of_wires = len(wire_list)
# Splits the list in to the number of each wire color
for i in range(number_of_wires):
temp = wire_list[i]
if temp == "Yellow":
number_of_yellow_wires += 1
elif temp == "Red":
number_of_red_wires += 1
elif temp == "Blue":
number_of_blue_wires += 1
elif temp == "Black":
number_of_black_wires += 1
elif temp == "White":
number_of_white_wires += 1
# Solver N.B. the if/elif/else statements are not combined when the results have the same outputs due to the fact
# that multiple statements can be true and so it is necessary to run them in the same order of the manual.
# todo tidy up this comment.
answer = 0
if number_of_wires == 3:
if wire_list == ["Blue", "Blue", "Red"] or number_of_red_wires == 0:
answer = 1 # "Cut The Second Wire"
else:
answer = 2 # "Cut Third Wire"
elif number_of_wires == 4:
if number_of_red_wires > 1 and (int(serial_num[-1]) % 2 == 0):
for i in range(number_of_wires):
temp_num = -1 - i
temp_wire_color = wire_list[temp_num]
if temp_wire_color == "Red":
answer = number_of_wires - i # "Cut The Last red Wire"
break
elif wire_list[-1] == "Yellow" and number_of_red_wires == 0:
answer = 0 # "Cut The First Wire"
elif number_of_blue_wires == 1:
answer = 0 # "Cut The First Wire"
elif number_of_yellow_wires > 1:
answer = 3 # "Cut The Last Wire"
else:
answer = 1 # "Cut The Second Wire"
elif number_of_wires == 5:
if wire_list[-1] == "Black" and int(serial_num[-1]) % 2 != 0:
answer = 3 # "Cut The Fourth Wire"
elif number_of_red_wires == 1 and number_of_yellow_wires > 1:
answer = 0 # "Cut The First Wire"
elif number_of_black_wires == 0:
answer = 1 # "Cut The Second Wire"
else:
answer = 0 # "Cut The First Wire"
elif number_of_wires == 6:
if number_of_yellow_wires == 0 and int(serial_num[-1]) % 2 != 0:
answer = 2 # "Cut The Third Wire"
elif number_of_yellow_wires == 1 and number_of_white_wires > 1:
answer = 3 # "Cut The Fourth Wire"
elif number_of_red_wires == 0:
answer = 5 # "Cut The Last Wire"
else:
answer = 3 # "Cut The Forth Wire"
return answer
# End function
def button(
number_of_batteries: int,
car_indicator_light_is_lit: bool,
frk_indicator_light_is_lit: bool,
button_color: str,
button_label: str,
): # The Button
"""
:param number_of_batteries: The number of batteries on the bomb
:param car_indicator_light_is_lit: If the CAR indicator light is lit
:param frk_indicator_light_is_lit: If the FRK indicator light is lit
:param button_color: The color of the button
:param button_label: The label on the button
:return: bool that if True means that the button is a push and Immediately release
"""
# var creation
button_color = button_color.lower()
button_label = button_label.lower()
# colors
blue = False
red = False
white = False
yellow = False
# labels
abort = False
detonate = False
hold = False
# data formatting
# colors
if button_color == "blue":
blue = True
elif button_color == "red":
red = True
elif button_color == "white":
white = True
elif button_color == "yellow":
yellow = True
# labels
if button_label == "abort":
abort = True
elif button_label == "detonate":
detonate = True
elif button_label == "hold":
hold = True
# solving
# main section
# If the button is blue and the button says "Abort", hold the button and refer to "Releasing a Held Button".
if blue is True and abort is True:
press_and_immediately_release = False
# If there is more than 1 battery on the bomb and the button says "Detonate", press and immediately release the
# button.
elif number_of_batteries > 1 and detonate is True:
press_and_immediately_release = True
# If the button is white and there is a lit indicator with label CAR, hold the button and refer to "Releasing a
# Held Button".
elif white is True and car_indicator_light_is_lit is True:
press_and_immediately_release = False
# If there are more than 2 batteries on the bomb and there is a lit indicator with label FRK, press and
# immediately release the button.
elif frk_indicator_light_is_lit is True and number_of_batteries > 2:
press_and_immediately_release = True
# If the button is yellow, hold the button and refer to "Releasing a Held Button".
elif yellow is True:
press_and_immediately_release = False
# If the button is red and the button says "Hold", press and immediately release the button.
elif red is True and hold is True:
press_and_immediately_release = True
# If none of the above apply, hold the button and refer to "Releasing a Held Button".
else:
press_and_immediately_release = False
return press_and_immediately_release
def button_indicator_color(color: str):
held_button_dict = {"blue": 4, "yellow": 5, "other": 1}
return held_button_dict[color.lower()]
def maze(
mazes: dict, green_1: list, green_2: list, start_position: list, end_position: list
): # a pathfinder that calculates moves to complete
"""
N.B. top left of maze is [0,0] Bottom right is [5,5]
:param mazes: dictionary of all the mazes ("mazes.json")
:param green_1: list coordinate of the first green circle e.g. [0,1]
:param green_2: list coordinate of the second green circle e.g. [5,2]
:param start_position: list coordinate of the white square e.g. [0,0]
:param end_position: list coordinate of the red triangle e.g. [5,2]
:return: list of list coordinate of the coordinates from the start position to the end position
e.g. [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]
"""
# var creation
maze_map = {}
# maze selection
test = False
for i in range(9):
if test is False:
current_maze = mazes[str(i + 1)]
temp_green_1 = current_maze["Green_circle_1"]
temp_green_2 = current_maze["Green_circle_2"]
if green_1 == temp_green_1 or green_1 == temp_green_2:
if green_2 == temp_green_1 or green_2 == temp_green_2:
maze_map = current_maze
# pathfinding
route = pathfinder.solve_maze(
start_position, start_position, end_position, [], maze_map
)
return route
# def simon_says_solver():
def simon_says(
serial_number: list, strikes: int, colors_list: list
): # simon says module
"""
:param serial_number: List form of the serial number ['A','L','5','0','F','2']
:param strikes: Integer of the number of strikes
:param colors_list: List of colors ["red","blue","green","yellow"]
:return: List of colors to press in order
"""
vowels = False
for i in range(len(serial_number)):
temp = str(serial_number[i])
temp = temp.upper()
if temp == "A" or temp == "E" or temp == "I" or temp == "O" or temp == "U":
vowels = True
continue
if vowels: # vowel simon says
if strikes == 0:
switch_dict = {
"red": "blue",
"blue": "red",
"green": "yellow",
"yellow": "green",
}
elif strikes == 1:
switch_dict = {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
}
else:
switch_dict = {
"red": "green",
"blue": "red",
"green": "yellow",
"yellow": "blue",
}
else: # no vowel simon says
if strikes == 0:
switch_dict = {
"red": "blue",
"blue": "yellow",
"green": "green",
"yellow": "red",
}
elif strikes == 1:
switch_dict = {
"red": "red",
"blue": "blue",
"green": "yellow",
"yellow": "green",
}
else:
switch_dict = {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
}
answer = []
for i in range(len(colors_list)):
temp_color = switch_dict[colors_list[i]]
answer.append(temp_color)
return answer
def memory(
display_number: int,
position_list: list,
label_list: list,
stage: int,
button_number_order: list,
):
"""
:param display_number: Integer of the number displayed on the module
:param position_list: List of previous positions of buttons
:param label_list: List of previous labels
:param stage: the current stage
:param button_number_order: the combination of 4 buttons at the bottom of the module [4,2,3,1]
:return: both the position and the label int
"""
position = 0
label = 0
if stage == 0: # Stage 1
if display_number == 1 or display_number == 2:
position = 2 # Second position
label = button_number_order[position - 1]
elif display_number == 3:
position = 3 # Third position
label = button_number_order[position - 1]
elif display_number == 4:
position = 4 # Forth position
label = button_number_order[position - 1]
elif stage == 1: # Stage 2
if display_number == 1:
label = 4 # Labeled 4
position = button_number_order.index(label) + 1
elif display_number == 2 or display_number == 4:
position = position_list[0] # Same position as stage 1
label = button_number_order[position - 1]
elif display_number == 3:
position = 1 # First position
label = button_number_order[position - 1]
elif stage == 2: # Stage 3
if display_number == 1:
label = label_list[1] # Same label as stage 2
position = button_number_order.index(label) + 1
elif display_number == 2:
label = label_list[0] # Same label as stage 1
position = button_number_order.index(label) + 1
elif display_number == 3:
position = 3 # Third position
label = button_number_order[position - 1]
elif display_number == 4:
label = 4 # Labeled 4
position = button_number_order.index(label) + 1
elif stage == 3: # Stage 4
if display_number == 1:
position = position_list[0] # Same position as stage 1
label = button_number_order[position - 1]
elif display_number == 2:
position = 1 # First position
label = button_number_order[position - 1]
elif display_number == 3 or display_number == 4:
position = position_list[1] # Same position as stage 2
label = button_number_order[position - 1]
elif stage == 4: # Stage 5
if display_number == 1:
label = label_list[0] # Same label as stage 1
position = button_number_order.index(label) + 1
elif display_number == 2:
label = label_list[1] # Same label as stage 2
position = button_number_order.index(label) + 1
elif display_number == 3:
label = label_list[3] # Same label as stage 4
position = button_number_order.index(label) + 1
elif display_number == 4:
label = label_list[2] # Same label as stage 3
position = button_number_order.index(label) + 1
else:
position = 0
label = 0
return position, label
def complex_wires(
serial_number: list,
parallel_port: bool,
battery_num: int,
red: bool,
blue: bool,
star: bool,
led: bool,
):
"""
:param serial_number: List form of the serial number ['A','L','5','0','F','2']
:param parallel_port: Boolean of whether the bomb has a parallel port
:param battery_num: Number of battery modules the bomb has
:param red: if the wire has the red trait
:param blue: if the wire has the blue trait
:param star: if the wire has the star trait
:param led: if the wire has the led trait
:return: whether or not the wire should be cut
"""
both_colors = False
white = False
red_only = False
blue_only = False
both_led_star = False
neither_led_star = False
star_only = False
led_only = False
if red is True and blue is True:
both_colors = True
elif red is False and blue is False:
white = True
elif red is True and blue is False:
red_only = True
elif red is False and blue is True:
blue_only = True
if star is True and led is True:
both_led_star = True
elif star is False and led is False:
neither_led_star = True
elif star is True and led is False:
star_only = True
elif star is False and led is True:
led_only = True
cut = False
if (
(int(serial_number[-1]) % 2) != 0 and parallel_port is False and battery_num < 2
): # all false
if (white is True and led is False) or (red_only is True and star_only is True):
cut = True
elif (
(int(serial_number[-1]) % 2) != 0
and parallel_port is False
and battery_num >= 2
): # battery
if (white is True and led_only is False) or (
red_only is True and neither_led_star is False
):
cut = True
elif (
(int(serial_number[-1]) % 2) != 0 and parallel_port is True and battery_num < 2
): # parallel
if (
(white is True and led is False)
or (red_only is True and star_only is True)
or (blue_only is True and led is True)
or (both_colors is True and star_only is True)
):
cut = True
elif (
(int(serial_number[-1]) % 2) != 0 and parallel_port is True and battery_num >= 2
): # parallel and battery
if (
(white is True and led_only is False)
or (red_only is True and neither_led_star is False)
or (blue_only is True and led is True)
or (both_colors is True and star_only is True)
):
cut = True
elif (
(int(serial_number[-1]) % 2) == 0 and parallel_port is False and battery_num < 2
): # even serial
if (
(star_only is True and blue is False)
or (neither_led_star is True)
or (both_colors is True and star is False)
):
cut = True
elif (
(int(serial_number[-1]) % 2) == 0
and parallel_port is False
and battery_num >= 2
): # even serial and battery
if (
(white is True and led_only is False or both_led_star is True)
or (red_only is True)
or (blue_only is True and neither_led_star is True)
or (both_colors is True and star is False)
):
cut = True
elif (
(int(serial_number[-1]) % 2) == 0 and parallel_port is True and battery_num < 2
):
if (
(neither_led_star is True)
or (star_only is True and blue_only is False)
or (led_only is True and blue is True)
or (both_led_star is True and blue_only is True)
):
cut = True
else: # all
if (
(white is True and led_only is False)
or (red_only is True)
or (blue_only is True and star_only is False)
or (both_colors is True and both_led_star is False)
):
cut = True
# all false
# answer= "+------+-------+-------+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+=======+\n" \
# "| None | Cut | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| LED | Don't | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Both | Don't | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+"
# battery
# answer = "+------+-------+-------+-------+----------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+==========+\n" \
# "| None | Cut | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+----------+\n" \
# "| Star | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-------+-------+----------+\n" \
# "| LED | Don't | Cut | Don't | Don't |\n" \
# "+------+-------+-------+-------+----------+\n" \
# "| Both | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-------+-------+----------+"
# parallel
# answer = "+------+-------+-------+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+=======+\n" \
# "| None | Cut | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| LED | Don't | Don't | Cut | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Both | Don't | Don't | Cut | Don't |\n" \
# "+------+-------+-------+-------+-------+"
# parallel and battery
# answer = "+------+-------+-------+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+=======+\n" \
# "| None | Cut | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| LED | Don't | Cut | Cut | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Both | Cut | Cut | Cut | Don't |\n" \
# "+------+-------+-------+-------+-------+"
# even serial
# answer = "+------+-------+-------+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+=======+\n" \
# "| None | Cut | Cut | Cut | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| LED | Don't | Don't | Don't | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Both | Don't | Don't | Don't | Don't |\n" \
# "+------+-------+-------+-------+-------+"
# even serial and battery
# answer = "+------+-------+-----+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=====+=======+=======+\n" \
# "| None | Cut | Cut | Cut | Cut |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| LED | Don't | Cut | Don't | Cut |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| Both | Cut | Cut | Don't | Don't |\n" \
# "+------+-------+-----+-------+-------+"
# even serial and parallel
# answer = "+------+-------+-------+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=======+=======+=======+\n" \
# "| None | Cut | Cut | Cut | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| LED | Don't | Don't | Cut | Cut |\n" \
# "+------+-------+-------+-------+-------+\n" \
# "| Both | Don't | Don't | Cut | Don't |\n" \
# "+------+-------+-------+-------+-------+"
# all
# answer = "+------+-------+-----+-------+-------+\n" \
# "| | White | Red | Blue | Both |\n" \
# "+======+=======+=====+=======+=======+\n" \
# "| None | Cut | Cut | Cut | Cut |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| Star | Cut | Cut | Don't | Cut |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| LED | Don't | Cut | Cut | Cut |\n" \
# "+------+-------+-----+-------+-------+\n" \
# "| Both | Cut | Cut | Cut | Don't |\n" \
# "------+-------+-----+-------+-------+"
return cut
def password_list(
first_letter_list: list, second_letter_list: list, third_letter_list: list
):
"""
:param first_letter_list: List of all the letters in the first column ["a","e","l","z","x"]
:param second_letter_list: List of all the letters in the second column ["a","e","l","z","x"]
:param third_letter_list: List of all the letters in the third column ["a","e","l","z","x"]
:return: list of possible word_list ["about","after"] only one will be compatible
"""
# var creation
password_list = [
"about",
"after",
"again",
"below",
"could",
"every",
"first",
"found",
"great",
"house",
"large",
"learn",
"never",
"other",
"place",
"plant",
"point",
"right",
"small",
"sound",
"spell",
"still",
"study",
"their",
"there",
"these",
"thing",
"think",
"three",
"water",
"where",
"which",
"world",
"would",
"write",
]
answers_list_1 = []
answers_list_2 = []
answers_list_3 = []
# first char search
for i in range(len(password_list)):
temp_word = password_list[i]
for j in range(len(first_letter_list)):
temp_search = first_letter_list[j]
temp_search = temp_search.lower()
if temp_word[0] == temp_search:
answers_list_1.append(temp_word)
# second char search
for i in range(len(answers_list_1)):
temp_word = answers_list_1[i]
for j in range(len(second_letter_list)):
temp_search = second_letter_list[j]
temp_search = temp_search.lower()
if temp_word[1] == temp_search:
answers_list_2.append(temp_word)
# third char search
for i in range(len(answers_list_2)):
temp_word = answers_list_2[i]
for j in range(len(third_letter_list)):
temp_search = third_letter_list[j]
temp_search = temp_search.lower()
if temp_word[2] == temp_search:
answers_list_3.append(temp_word)
return answers_list_3
def wire_sequences(color: str, color_history_dict: dict): # todo test
"""
:param color: The color of the wire currently be examined. "red" "blue" "black"
:param color_history_dict: the number of the wires of that color previously seen. Given in the form
color_history_dict={
"Red": 0,
"Blue": 3,
"Black": 2
}
:return: the terminals that if connect to the wire should be cut. todo improve
"""
red = color_history_dict["Red"]
blue = color_history_dict["Blue"]
black = color_history_dict["Black"]
red_options = {
1: ["C"],
2: ["B"],
3: ["A"],
4: ["A", "C"],
5: ["B"],
6: ["A", "C"],
7: ["A", "B", "C"],
8: ["A", "B"],
9: ["B"],
}
blue_options = {
1: ["B"],
2: ["A", "C"],
3: ["B"],
4: ["A"],
5: ["B"],
6: ["B", "C"],
7: ["C"],
8: ["A", "C"],
9: ["A"],
}
black_options = {
1: ["A", "B", "C"],
2: ["A", "C"],
3: ["B"],
4: ["A", "C"],
5: ["B"],
6: ["B", "C"],
7: ["A", "B"],
8: ["C"],
9: ["C"],
}
# solver
answer = "Error"
if color == "Red":
red += 1
answer = red_options[red]
elif color == "Blue":
blue += 1
answer = blue_options[blue]
elif color == "Black":
black += 1
answer = black_options[black]
return answer
def morse_sequence_to_word(sequence: str):
sequence_to_word_dict = {
".../...././.-../.-..": "shell",
"..../.-/.-../.-../...": "halls",
".../.-../../.-.-/-.-": "slick",
"-/.-./../-.-./-.-": "trick",
"-.../---/-..-/./...": "boxes",
".-.././.-/-.-/...": "leaks",
".../-/.-./---/-.../.": "strobe",
"-.../../.../-/.-./---": "bistro",
"..-./.-../../-.-./-.-": "flick",
"-.../---/--/-.../...": "bombs",
"-.../.-././.-/-.-": "break",
"-.../.-./../-.-./-.-": "brick",
".../-/./.-/-.-": "steak",
".../-/../-./--.": "string",
"...-/./-.-./-/---/.-.": "vector",
"-..././.-/-/...": "beats",
}
return sequence_to_word_dict[sequence]
def morse_word_to_frequency(word: str): # todo
word_frequency_dict = {
"shell": 3.505,
"halls": 3.515,
"slick": 3.522,
"trick": 3.532,
"boxes": 3.535,
"leaks": 3.542,
"strobe": 3.545,
"bistro": 3.552,
"flick": 3.555,
"bombs": 3.565,
"break": 3.572,
"brick": 3.575,
"steak": 3.582,
"string": 3.592,
"vector": 3.595,
"beats": 3.600,
}
return word_frequency_dict[word]
def morse_word_list():
return [
"shell",
"halls",
"slick",
"trick",
"boxes",
"leaks",
"strobe",
"bistro",
"flick",
"bombs",
"break",
"brick",
"steak",
"string",
"vector",
"beats",
]
def morse_smart_sort(
letters, word_list
): # Removes words from the word_list which don't contain all the letters in letters]
new_words_list = []
for i in range(len(word_list)):
word = list(word_list[i])
contains_letters = False
for j in range(len(letters)):
if letters[j] in word:
word.remove(letters[j])
contains_letters = True
else:
contains_letters = False
break
if contains_letters is True:
new_words_list.append(word_list[i])
if len(new_words_list) == 0:
return word_list
else:
return new_words_list
def whose_on_first_step_one(displayed_word=""): # todo test
"""
:param displayed_word: The word on the display
:return: the location to read from
"""
display_word_dictionary = {
"blank": "middle right",
"c": "top right",
"cee": "bottom right",
"display": "bottom right",
"first": "top right",
"hold on": "bottom right",
"lead": "bottom right",
"led": "middle left",
"leed": "bottom left",
"no": "bottom right",
"nothing": "middle left",
"okay": "top right",
"read": "middle right",
"red": "middle right",
"reed": "bottom left",
"says": "bottom right",
"see": "bottom right",
"their": "middle right",
"there": "bottom right",
"they are": "middle left",
"they're": "bottom left",
"ur": "top left",
"yes": "middle left",
"you": "middle right",
"you are": "bottom right",
"you're": "middle right",
"your": "middle right",
"": "bottom left",
}
return display_word_dictionary[displayed_word]
def whose_on_first_step_two(button_word=""):
"""
:param button_word: The word on the button in the position indicated
:return:list of word_list to be tried in order
"""
word_corresponding_list = {
"ready": [
"yes",
"okay",
"what",
"middle",
"left",
"press",
"right",
"blank",
"ready",
"no",
"first",
"uhhh",
"nothing",
"wait",
],
"first": [
"left",
"okay",
"yes",
"middle",
"no",
"right",
"nothing",
"uhhh",
"wait",
"ready",
"blank",
"what",
"press",
"first",
],
"no": [
"blank",
"uhhh",
"wait",
"first",
"what",
"ready",
"right",
"yes",
"nothing",
"left",
"press",
"okay",
"no",
"middle",
],
"blank": [
"wait",
"right",
"okay",
"middle",
"blank",
"press",
"ready",
"nothing",
"no",
"what",
"left",
"uhhh",
"yes",
"first",
],
"nothing": [
"uhhh",
"right",
"okay",
"middle",
"yes",
"blank",
"no",
"press",
"left",
"what",
"wait",
"first",
"nothing",
"ready",
],
"yes": [
"okay",
"right",
"uhhh",
"middle",
"first",
"what",
"press",
"ready",
"nothing",
"yes",
"left",
"blank",
"no",
"wait",
],
"what": [
"uhhh",
"what",
"left",
"nothing",
"ready",
"blank",
"middle",
"no",
"okay",
"first",
"wait",
"yes",
"press",
"right",
],
"uhhh": [
"ready",
"nothing",
"left",