-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
2218 lines (1902 loc) · 58.9 KB
/
game.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
import random
import os
import time
import msvcrt
import curses
import math
import dungeon_map as map
#PREFERENCES
#Uses Dvorak keyboard, set with USE_DVORAK = True or USE_DVORAK = False
USE_DVORAK = True
WRITE_MAP = True
#Shows all dividers and slots in status bar, " | stuff | | morestuff" for True, "stuff | morestuff" for False
SHOW_ALL_STATUS_GAPS = False
SCALING = 1
#CHEATS:
#HANDICAP = 7 #RADIANT
HANDICAP = 1
START_FL = False
START_TORCH = False
START_BEAM = False
START_CAST = False
START_TRAP = False
START_BOMB = False
START_SNAKE = False
START_PING = False
VIEW_ALL = False
DISCOVER_BEAM = False
DISCOVER_FIRST_LEVEL = False
DISCOVER_CAULDRON = False
#this is good, not a cheat.
DISCOVER_ONE = True
FPS = 12
BEAMPS = 12
BEAMCREATEPS = 4
ENEMYPS = .8
TRGTPS = 1
BOMBPS = 6
CASTPS = 1
HELD_ITEMS_BLOCK = False
ENEMY_MV_THRES = .2
ENEMY_LIGHT_MV_THRES = .8
ENEMY_HARSH_LIGHT_MV_THRES = .99
PRED_HIDE = False
INSANITY = False
INSANITY_CHARS = "X#&@a|^v<>!=....................................."
INSANITY_THRES = .01
INSANITY_RET_THRES = .99
if INSANITY:
INSANITY_DICT = dict()
RIGHT_BORDER = True
RIGHT_BORDER_CHR = "R"
NEW_ROCK_ALG = True
USE_DUNGEON_MAP = True
ROCK_MIN = 10
ROCK_MAX = 6
#TRAP SETTINGS
TRAP_MAX = 5
TRAP_RECOVERY_MODIFIER = 2
#CAULDRON RECOVERY MODIFIER
CAULDRON_RECOVERY_MODIFIER = 5
CAULDRON_REMOVES_LIGHT = False
ALLOW_CAULDRON_ACTION = False
CAULDRON_PROVIDES_LIGHT = True
CAULDRON_RANGE = 3
#SNAKE
SNAKE_MAX = 9
SNAKE_USE_PER_LEVEL_AGE = True
SNAKE_MAX_AGE_PER_LEVEL = 50
SNAKE_MAX_AGE = 300
SNAKE_COST = 0
SNAKE_USAGE_COST = 20
SNAKE_ENERGY_COST = 6
#BOMB
BOMB_MAX = 2
BOMB_END_AGE = 4
BOMB_MAX_AGE = 12
BOMBS_BREAK_WALL = True
BOMBS_HURT_SELF = True
BOMB_DEBRIS = ",;:\"'-_/\\{}[]"
#TORCH_SETTINGS
TORCH_MAX = 5
TORCH_RANGE = 6
TORCH_COST = 1
pred_in_light_char = "X"
if PRED_HIDE:
pred_in_light_char = "#"
#FL SETTINGS
#FL_COST = 4
#FL_RANGE = 9
#FL_SLOPE = .8
#FL POWER
#settings
# name ,cost,range, slope, isHarsh
flsettingsinit = [
("Low" , 0 , 4 , .4, False),
("Medium", 2 , 6 , .6, False),
("High" , 6 , 9 , .8, True ),
("Absurd", 10, 20, 4, True )
]
#FL_SETTINGS = [None]
#PRED SETTINGS,
PRED_THRESH = 15
PRED_SPAWN_SQDIST = 4 ** 2
PRED_PER_LEVEL = 2
PRED_INITIAL_COUNT = 2 + (HANDICAP * PRED_PER_LEVEL)
#CAST SETTINGS
#CAST_RANGE = 7
CAST_MAX = 4
MAX_CAST_AGE = 30
CAST_COST = 2
CAST_DISCOVER = True
#BEAM SETTINGS
BEAM_COST = 3
USE_DUAL_BEAMS = False
BEAM_PASSTHROUGH = 12
#PING SETTINGS
PING_USAGE_COST = 5
PING_ENERGY_COST = 2
PING_LIMIT = 10
#SUPER SIGHT PING
#PING_PASSTHROUGH = 10
#PING_DESTROYS = False
#PING_SEE_AHEAD = False
#PING_WIDE_DESTROY = False
#Normal ping: ping destroys true, wide destroy false, see ahead true
PING_PASSTHROUGH = 1
PING_DESTROYS_PRED = True
PING_DESTROYS_ROCKS = True
PING_SEE_AHEAD = False
PING_WIDE_DESTROY = False
PING_LINGER = True
PING_LINGER_LENGTH = 4
PING_LINGER_BIG = True
#
#
LANTERN_COST = 40
LANTERN_RANGE = 50
LIGHT_MIN_MAX = 10
LIGHT_SMALL_MAX = 20
LIGHT_MEDIUM_MAX = 30
LIGHT_BIG_MAX = 60
LIGHT_HUGE_MAX = 100
LIGHT_HUGER_MAX = 150
LIGHT_HUGEST_MAX = 200
LIGHT_RADIATING_MAX = 300
#LEVEL DEPENDENT
LPLEVELS = [LIGHT_RADIATING_MAX, LIGHT_HUGEST_MAX, LIGHT_HUGER_MAX, LIGHT_HUGE_MAX, LIGHT_BIG_MAX, LIGHT_MEDIUM_MAX, LIGHT_SMALL_MAX, LIGHT_MIN_MAX]
LPRECOVERIES = [12, 5, 3, 2, 2, 1, 1, 0]
CASTMAXES = [16, 10, 8, 4, 3, 2, 1, 1]
CASTRANGES = [6.5, 4.5, 4, 3.25, 3, 2.8, 2.75, 2]
BEAM_RANGES = [6, 5, 4, 3, 2, 2, 1, 1]
LEVELNAMES = ["Radiant", "Master", "Teacher", "Adept", "Student", "Pupil", "Trainee", "Novice"]
NE = (1, -1)
E = (1, 0)
SE = (1, 1)
S = (0, 1)
SW = (-1, 1)
W = (-1, 0)
NW = (-1, -1)
N = (0, -1)
NOP = (0, 0)
L = (2, 3)
TN = (-5, -5)
TS = (-5, -4)
TE = (-5, -3)
TW = (-5, -2)
TF = ("TRAP", "FULL")
TNE = (-6, 6)
TSE = (-6, 1)
TSW = (-6, 2)
TNW = (-6, 3)
YN = (-2, -5)
YS = (-2, -4)
YE = (-2, -3)
YW = (-2, -2)
CT = (5,5) #clear traps
CY = (5,7)
OFF = ("off", "Flashlight")
ON = ("ON", "Flashlight")
O = ("TOGGLE", "FLASHLIGHT")
FLC = ""
FLD = "FLD"
CASTN = ("CASTN", "THING")
CASTW = ("CASTW", "THING")
CASTS = ("CASTS", "THING")
CASTE = ("CASTE", "THING")
CASTFULL = ("CASTF", "THING")
B = ("BEAM", "BEAM")
BOM = "BOMB"
BOMC = "BOMBC"
SNK = "SNAKE"
SNKC = "SNKC"
PKUP = "PKUP"
PING = "PING"
trgtdrs = [NE, E, SE, S, SW, W, NW, N, NOP]
carddrs = [N, E, S, W]
alldrs = [NE, E, SE, S, SW, W, NW, N]
trapdict = {
TE : E,
TS : S,
TW : W,
TN : N,
TSE : SE,
TSW : SW,
TNE : NE,
TNW : NW
}
torchdict = {
YE : E,
YS : S,
YW : W,
YN : N
}
castdict = {
CASTN: N,
CASTW: W,
CASTE: E,
CASTS: S
}
preddrs = [N, E, S, W]#, NE, SW, NW, SE]
#bmbdrs = [N, E, S, W, NE, SW, NW, SE, (0, 0)]
bmbdrs = [N, E, S, W, NE, SW, NW, SE, (0, 0), (2,0), (0, 2), (-2, 0), (0, -2)]
#motion
ARROWOP = {b'H' : N,#"N",
b'P' : S,#"S",
b'M' : E,#"E",
b'K' : W,#"W",
b'Q' : S,#"S",
b'I' : N,#"N",
}
#appended to suffixes
ARROWCODE = {b'H' : "N",
b'P' : "S",
b'M' : "E",
b'K' : "W",
b'Q' : "S",
b'I' : "N",
}
DVORAK_NAMES = {
#"OFF" : OFF,
#"OF" : OFF,
#"ON" : ON,
"O" : O,
#"L" : L,
#"TE" : TE,
#"TN" : TN,
#"TS" : TS,
#"TW" : TW,
"AE" : TE,
"AN" : TN,
"AS" : TS,
"AW" : TW,
#"TF" : TF,
"AF" : TF,
"AA" : TF,
#"TNE" : TNE,
#"TSE" : TSE,
#"TSW" : TSW,
#"TNW" : TNW,
"YE" : YE,
"YN" : YN,
"YS" : YS,
"YW" : YW,
"CT" : CT,
"A." : CT,
"CY" : CY,
"Y." : CY,
#"NE" : NE,
#"E" : E,
#"SE" : SE,
#"S" : S,
#"SW" : SW,
#"W" : W,
#"NW" : NW,
#"N" : N,
#"CASTN" : CASTN,
#"CASTS" : CASTS,
#"CASTE" : CASTE,
#"CASTW" : CASTW,
#"CASTFULL" : CASTFULL,
#"CN" : CASTN,
#"CS" : CASTS,
#"CE" : CASTE,
#"CW" : CASTW,
#"CF" : CASTFULL,
"UN" : CASTN,
"US" : CASTS,
"UE" : CASTE,
"UW" : CASTW,
"UF" : CASTFULL,
"UU" : CASTFULL,
"F" : CASTFULL,
"B" : B,
";" : B,
"," : FLC,
"'" : FLD,
"I" : BOM,
"D" : BOMC,
"K" : SNK,
"J" : SNKC,
" " : PKUP,
"E" : PING,
}
QWERTY_NAMES = {
"S" : O,
"KE" : TE,
"KN" : TN,
"KS" : TS,
"KW" : TW,
"AE" : TE,
"AN" : TN,
"AS" : TS,
"AW" : TW,
"KF" : TF,
"AF" : TF,
"AA" : TF,
#"TNE" : TNE,
#"TSE" : TSE,
#"TSW" : TSW,
#"TNW" : TNW,
"TE" : YE,
"TN" : YN,
"TS" : YS,
"TW" : YW,
"IK" : CT,
"AE" : CT,
"IT" : CY,
"TE" : CY,
#"NE" : NE,
"E" : E,
#"SE" : SE,
"S" : S,
#"SW" : SW,
"W" : W,
#"NW" : NW,
"N" : N,
#"CASTN" : CASTN,
#"CASTS" : CASTS,
#"CASTE" : CASTE,
#"CASTW" : CASTW,
#"CASTFULL" : CASTFULL,
"IN" : CASTN,
"IS" : CASTS,
"IE" : CASTE,
"IW" : CASTW,
"IF" : CASTFULL,
"FN" : CASTN,
"FS" : CASTS,
"FE" : CASTE,
"FW" : CASTW,
"FF" : CASTFULL,
"FU" : CASTFULL,
"Y" : CASTFULL,
"B" : B,
"N" : B,
"Z" : B,
"W" : FLC,
"Q" : FLD,
"G" : BOM,
"H" : BOMC,
"V" : SNK,
"C" : SNKC,
" " : PKUP,
}
if USE_DVORAK:
prfxs = "CTYAU"
plyrdrnames = DVORAK_NAMES
else:
prfxs = "IKTAF"
plyrdrnames = QWERTY_NAMES
class Cast(object):
def __init__(self, pos, dir):
self.pos = pos
self.dir = dir
self.age = 0
self.over = False
class Beam(object):
def __init__(self, pos, dir):
self.pos = pos
self.dir = dir
self.passthrough = BEAM_PASSTHROUGH
self.over = False
self.energy = 0
def update(self, allowed, inGrid):
p = mve(self.pos, self.dir)
if allowed(p):
self.pos = p
elif self.passthrough > 0 and inGrid(p):
self.pos = p
self.passthrough -= 1
else:
self.over = True
class Ping(object):
def __init__(self, pos, dir):
self.pos = pos
self.dir = dir
self.passthrough = PING_PASSTHROUGH
self.linger_length = PING_LINGER_LENGTH
self.lingering = False
self.over = False
self.energy = 0
def update(self, allowed, inGrid):
if self.over:
return
self.energy += 1
if self.energy >= PING_ENERGY_COST:
self.energy -= PING_ENERGY_COST
if not self.lingering:
p = mve(self.pos, self.dir)
alwd = allowed(p)
if PING_WIDE_DESTROY:
idx = carddrs.index(self.dir)
otherdirs = [mve(p, nxt) for nxt in [carddrs[(idx + 1) % 4], carddrs[(idx + 3) % 4]]]
alwd = alwd and all([allowed(ps) for ps in otherdirs])
if alwd:
self.pos = p
elif self.passthrough > 0 and inGrid(p):
self.pos = p
self.passthrough -= 1
else:
if PING_LINGER:
self.lingering = True
else:
self.over = True
elif self.lingering:
if self.linger_length > 0:
self.linger_length -= 1
else:
self.over = True
class FLSetting(object):
def __init__(self, name, cost, range, slope, is_harsh):
self.name = name
self.cost = cost
self.range = range
self.slope = slope
self.is_harsh = is_harsh
class Cauldron(object):
def __init__(self, position):
self.position = position
self.being_carried = False
self.discovered = False
class Bomb(object):
def __init__(self, position):
self.position = position
self.age = BOMB_MAX_AGE
self.exploding = False
self.blewselfup = False
class Snake(object):
def __init__(self, position, direction):
self.position = position
self.direction = direction
self.rh = random.randint(0,1)
self.drs = [[S, E, N, W], [N, E, S, W]][self.rh]
self.drIndex = self.drs.index(self.direction)
self.dead = False
self.age = 0
self.foundWall = False
self.energy = 0
self.speed = random.randint(1, SNAKE_ENERGY_COST)
def update(self, allowed, max_age):
self.energy += self.speed
if self.energy < SNAKE_ENERGY_COST:
return
else:
self.energy -= SNAKE_ENERGY_COST
self.age += 1
self.dead = (self.age > max_age)
if not self.foundWall:
if allowed(mve(self.position, self.direction)):
self.position = mve(self.position, self.direction)
return
else:
self.foundWall = True
self.drIndex = (self.drIndex + 3) % len(self.drs)
if self.foundWall:
testIndex = (self.drIndex + 1) % len(self.drs)
if allowed(mve(self.position, self.drs[testIndex])):
self.direction = self.drs[testIndex]
self.drIndex = testIndex
self.position = mve(self.position, self.direction)
return
else:
testIndex = (self.drIndex)
if allowed(mve(self.position, self.drs[testIndex])):
self.direction = self.drs[testIndex]
self.drIndex = testIndex
self.position = mve(self.position, self.direction)
return
else:
testIndex = (self.drIndex + 3) % len(self.drs)
if allowed(mve(self.position, self.drs[testIndex])):
self.direction = self.drs[testIndex]
self.drIndex = testIndex
self.position = mve(self.position, self.direction)
return
else:
testIndex = (self.drIndex + 2) % len(self.drs)
if allowed(mve(self.position, self.drs[testIndex])):
self.direction = self.drs[testIndex]
self.drIndex = testIndex
self.position = mve(self.position, self.direction)
return
else:
self.dead = True
FL_SETTINGS = [FLSetting(*obj) for obj in flsettingsinit]
def mve(pt1, pt2):
return (pt1[0] + pt2[0], pt1[1] + pt2[1])
def scale(value, dim):
return max(1,int(value * (SCALING ** dim)))
class Grid(object):
def __init__(self, xm, ym):
# = sight
self.lastop = N
self.lastmovop = N
self.lastchr = "^"
self.xm = xm
self.ym = ym
self.lighton = False
self.spotted = False
self.turns = 0
self.walls_destroyed = 0
self.flSettingInd = 0
self.hasFL = START_FL
self.hasTorch = START_TORCH
self.hasCast = START_CAST
self.hasTrap = START_TRAP
self.hasBeam = START_BEAM
self.hasBomb = START_BOMB
self.hasSnake = START_SNAKE
self.hasPing = START_PING
self.heldItem = None
self.beamOn = False
self.boundarySet = set()
for i in range(self.xm):
self.boundarySet.add((i, 0))
self.boundarySet.add((i, self.ym - 1))
for i in range(self.ym):
self.boundarySet.add((0, i))
self.boundarySet.add((self.xm - 1, i))
#print(self.boundarySet)
#exit(0)
self.preds = []
self.casts = []
self.beams = []
self.pings = []
self.plyr = (-1, -1)
self.trgt = (-1, -1)
self.traps = []
self.bombs = []
self.torches = []
self.snakes = []
self.cauldrons = []
self.map = None
if USE_DUNGEON_MAP:
self.rocks = []
mp = map.getMap(xm // 2, ym // 2)
for y in range(len(mp.grid)):
for x in range(len(mp.grid[y])):
if mp.grid[y][x] == "#":
self.rocks.append((x,y))
self.map = mp.grid
else:
rockfactor = random.randint(xm * ym // ROCK_MIN, xm * ym // ROCK_MAX)
#print("Rock factor is " + str(rockfactor))
self.rocks = [(random.randint(1, xm -2), random.randint(1, ym - 2)) for i in range(rockfactor)]
self.map = []
for y in range(ym):
row = []
self.map.append(row)
for x in range(xm):
if (x,y) in self.rocks:
row.append("#")
else:
row.append(" ")
if WRITE_MAP:
with open("lastmap.txt", "w+") as f:
f.write("\n".join("".join(j) for j in self.map))
self.discovered = []
self.trgt = (random.randint(0, xm-2), random.randint(0, ym -2))
while not self.allowed(self.trgt):
self.trgt = (random.randint(0, xm-2), random.randint(0, ym -2))
self.plyr = (random.randint(0, xm-1), random.randint(0, ym -1))
while not (self.allowed(self.plyr) and (self.plyr != self.trgt)) :
self.plyr = (random.randint(0, xm-1), random.randint(0, ym -1))
for i in range(scale(PRED_INITIAL_COUNT, 2)):
pred = (random.randint(0, xm-1), random.randint(0, ym -1))
while not (self.allowed(pred) and (pred != self.trgt) and (pred != self.plyr)) :
pred = (random.randint(0, xm-1), random.randint(0, ym -1))
self.preds.append(pred)
self.lpexps = []
for i in range(len(LPLEVELS) - 1 - HANDICAP):
lpexp = (random.randint(0, xm-1), random.randint(0, ym -1))
while not (self.allowed(lpexp) and (lpexp != self.trgt) and (lpexp != self.plyr)) :
lpexp = (random.randint(0, xm-1), random.randint(0, ym -1))
self.lpexps.append(lpexp)
self.lightpower = self.getLPMax()
#item positions
self.flGetter, self.castGetter, self.trapGetter, self.torchGetter, self.beamGetter, self.bombGetter, self.snakeGetter,self.pingGetter,cpt = random.sample([(x,y) for x in range(xm) for y in range(ym) if self.allowed((x,y))], 9)
cdrn = Cauldron(cpt)
self.cauldrons.append(cdrn)
if DISCOVER_CAULDRON:
cdrn.discovered = True
if START_FL:
self.flGetter = None
if START_TORCH:
self.torchGetter = None
if START_BEAM:
self.beamGetter = None
if START_CAST:
self.castGetter = None
if START_TRAP:
self.trapGetter = None
if START_BOMB:
self.bombGetter = None
if START_SNAKE:
self.snakeGetter = None
if START_PING:
self.pingGetter = None
if DISCOVER_BEAM:
self.discovered.append(self.beamGetter)
if DISCOVER_ONE and not DISCOVER_BEAM:
#self.discovered.append(random.choice(tuple(self.getItemPositionList())))
self.discovered.append(min(self.getLightGetterPositionList(), key = lambda p: self.getSqEulDist(p, self.plyr)))
if DISCOVER_FIRST_LEVEL and len(self.lpexps):
self.discovered.append(self.lpexps[0])
def bumpFLSetting(self):
self.flSettingInd = (self.flSettingInd + 1) % len(FL_SETTINGS)
def spawnPreds(self):
#lazy about what happens if not enough free spots. Shouldn't happen often.
newPreds = random.sample([(x,y) for x in range(self.xm) for y in range(self.ym) if self.allowed((x,y)) and (self.getSqEulDist(self.plyr, (x,y)) > scale(PRED_SPAWN_SQDIST, 2))], scale(PRED_PER_LEVEL, 2))
self.preds.extend(newPreds)
def dropFLSetting(self):
self.flSettingInd = max((self.flSettingInd - 1), 0)
def getCurrentFLSetting(self):
return FL_SETTINGS[self.flSettingInd]
def getDscChr(self, x, y):
if (x, y) in self.rocks:
return "*"
elif (x,y) in self.getItemPositionList():
return "!"
else:
return "~"
def getGetterPositionList(self):
items = set()
for i2 in [self.flGetter, self.torchGetter, self.castGetter, self.beamGetter, self.trapGetter, self.bombGetter, self.snakeGetter, self.pingGetter]:
if i2 is not None:
items.add(i2)
return items
def getLightGetterPositionList(self):
items = set()
for i2 in [self.flGetter, self.torchGetter, self.castGetter, self.beamGetter, self.pingGetter]:
if i2 is not None:
items.add(i2)
return items
def getItemPositionList(self):
items = set()
for item in self.lpexps:
if item is not None:
items.add(item)
for i2 in [self.flGetter, self.torchGetter, self.castGetter, self.beamGetter, self.trapGetter, self.bombGetter, self.snakeGetter, self.pingGetter]:
if i2 is not None:
items.add(i2)
return items
def getIgnChr(self, x, y):
if (x,y) == self.plyr:
c = self.getPlyrChr()
self.lastchr = c
return c
if (x,y) in [mve(b.position, dr) for dr in bmbdrs for b in self.bombs if b.exploding]:
return random.choice(BOMB_DEBRIS)
if (x,y) in [b.position for b in self.bombs if b.age > BOMB_END_AGE]:
return "b"
if (x,y) in [b.position for b in self.bombs if b.age <= BOMB_END_AGE]:
return "B"
if (x,y) in self.traps:
return "%"
if (x,y) in self.torches:
return "Y"
if (x,y) in [cast.pos for cast in self.casts]:
return "O"
if (x,y) in [c.position for c in self.cauldrons if not c.being_carried]:
for c in self.cauldrons:
if (x,y) == c.position:
c.discovered = True
return "U"
if (x,y) in [c.position for c in self.cauldrons if c.being_carried and c.position not in self.rocks]:
return "u"
if (x,y) in [c.position for c in self.cauldrons if c.being_carried and c.position in self.rocks]:
return "w"
if (x,y) in self.rocks:
if (x,y) not in self.discovered:
self.discovered.append((x,y))
return "#"
if (x,y) == self.trgt:
if self.inHarshLight(self.trgt):
return " "
elif self.inLight(self.trgt):
return "a"
else:
return "@"
elif (x,y) in self.preds:
if self.inHarshLight((x,y)):
return "G"
elif self.inLight((x,y)):
return pred_in_light_char
else:
return "X"
if (x,y) == self.flGetter:
return "|"
if (x,y) == self.castGetter:
return "o"
if (x,y) == self.trapGetter:
return "A"
if (x,y) == self.torchGetter:
return "y"
if (x,y) == self.beamGetter:
return "+"
if (x,y) == self.bombGetter:
return "b"
if (x,y) == self.snakeGetter:
return "S"
if (x,y) == self.pingGetter:
return "\""
if (x,y) in self.lpexps:
return "="
if (x,y) in [beam.pos for beam in self.beams]:
return "+"
if (x,y) in [ping.pos for ping in self.pings if ping.dir in (N,S) and not ping.lingering]:
return "\""
if (x,y) in [ping.pos for ping in self.pings if ping.dir in (E, W) and not ping.lingering]:
return ":"
if (x,y) in [snk.position for snk in self.snakes if not snk.foundWall]:
return "-"
if (x,y) in [snk.position for snk in self.snakes if snk.foundWall and snk.rh]:
return "s"
if (x,y) in [snk.position for snk in self.snakes if snk.foundWall and not snk.rh]:
return "z"
else:
if INSANITY:
if (x,y) in INSANITY_DICT:
if random.random() < INSANITY_RET_THRES:
return INSANITY_DICT[(x,y)]
else:
if random.random() < INSANITY_THRES:
ret = random.choice(INSANITY_CHARS)
INSANITY_DICT[(x,y)] = ret
return ret
else:
del INSANITY_DICT[(x,y)]
return "."
else:
if random.random() < INSANITY_THRES:
ret = random.choice(INSANITY_CHARS)
INSANITY_DICT[(x,y)] = ret
return ret
else:
return "."
else:
return "."
def getChr(self, x, y):
if (x,y) == self.plyr:
c = self.getPlyrChr()
self.lastchr = c
return c
if (x,y) in self.bombs:
return "\""
if (x,y) in self.traps:
return "%"
if (x,y) in self.torches:
return "Y"
if (x,y) in [cast.pos for cast in self.casts]:
return "O"
if not self.inView((x,y)) and ((x,y) not in self.discovered) and not ((len(self.lpexps) == 0) and (x,y) in [self.flGetter, self.castGetter, self.trapGetter, self.torchGetter, self.beamGetter]):
return " "
elif not self.inView((x,y)) and ((x,y) in self.discovered):
return "*"
if (x,y) in self.rocks:
if (x,y) not in self.discovered:
self.discovered.append((x,y))
return "#"
if (x,y) == self.trgt:
if (self.inFlashlight(self.trgt) or self.inLantern(self.trgt) or self.inCast(self.trgt) or self.inBeam(self.trgt) or self.inPing(self.trgt)):
return "a"
else:
return "@"
elif (x,y) in self.preds:
if self.inTorch((x,y)):
return "G"
if self.inLight((x,y)):
return "&"
else:
return "X"
if (x,y) == self.flGetter:
return "|"
if (x,y) == self.castGetter:
return "o"
if (x,y) == self.trapGetter:
return ":"
if (x,y) == self.torchGetter:
return "y"
if (x,y) == self.beamGetter:
return "+"
if (x,y) == self.bombGetter:
return "'"
if (x,y) in self.lpexps:
return "="
#if (x,y) in [beam.pos for beam in self.beams]:
# return "+"
else:
return "."
def getAttemptedPathTo(self, p1, p2, limit = None, passthrough = 0):
past = passthrough
x1,y1 = p1
x2,y2 = p2
dx = x2 - x1
dy = y2 - y1
retlist = [p1]
steps = max(abs(dx), abs(dy))
if steps == 0:
retlist.append(p2)
return retlist
if abs(dx) > abs(dy):
slope = dy / dx
if dx > 0:
step = 1
else:
step = -1
if dy > 0:
rnd = math.ceil
else:
rnd = math.floor
for i in range(0, dx, step):
px = x1 + i
py = int(rnd(slope* (i) + y1))
testpoint = (px, py)
if limit is not None and (self.getSqEulDist(testpoint, p1) > (limit ** 2)):
return retlist
retlist.append(testpoint)
if ((not self.allowed(testpoint) and past == 0) or (testpoint == self.trgt)):
return retlist
if not self.allowed(testpoint) and past > 0:
past -= 1
else:
slope = dx / dy
if dy > 0:
step = 1
else:
step = -1
if dx > 0:
rnd = math.ceil
else:
rnd = math.floor
for i in range(0, dy, step):
py = y1 + i
px = int(rnd(slope* (i) + x1))
testpoint = (px, py)
if limit is not None and (self.getSqEulDist(testpoint, p1) > (limit ** 2)):
return retlist
retlist.append(testpoint)
if ((not self.allowed(testpoint) and past == 0) or (testpoint == self.trgt)):
return retlist
if not self.allowed(testpoint) and past > 0:
past -= 1
return retlist
def getPointsInView(self, p1, limit = None):
retset = set()
boundary = self.boundarySet
if limit is not None:
boundary = set()