-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheroquest_solo_function.py
1478 lines (1236 loc) · 61.1 KB
/
heroquest_solo_function.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/env python
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Everlast Legends Heroes
------------------------------------------
begin : 2021-01-02
copyright : (C) 2021 by Luca Mandolesi
email : mandoluca at gmail.com
version : 0.951 ALPHA
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import random
import sqlite3
from permutations_iter import Permutation_class
#TODO se il mostro può attaccare subito perchè vicino all'eroe, segnalare se poi si allontana o resta lì
#TODO E' nella linea di vista del mostro l'eroe?
#TODO I MOSTRI SONO IN GRUPPO SE SI VEDONO RECIPROCAMENTE
#TODO inserire sequenza di movimento mostri se quello con più punti attacco, quello che si muove di più
#TODO quando si trova la stanza finale cambiare il testo dei mostri: vengono caricati dei mostri con la descrizione finale ma il testo può dire: nessun mostro in vista.
#TODO quandi ci si trova a metà di un nuovo corridoio decidere come fare ad esplorarlo.
#TODO far apparire più porte tra stanze
#TODO aggiungere opzione per avere percorsi tra stanze e scegliere il numero della stanza finale
#TODO far apparire più mostri nei corridoi
#TODO come capire se si ripassa da un corridoio già esplorato?
class Heroquest_solo:
"""main class for variables management"""
rng = random.SystemRandom()
TOTAL_NUMBER_OF_TURNS = rng.randint(10, 12)
rng = random.SystemRandom()
MAX_ROOM_COUNTER = rng.randint(5, 6)
CURRENT_ROOM_COUNTER = 0
MISSION_PERCENT_MADE = 0
ESCAPE_FOUND = 0
FIRST_ROOM = 0
CONFIG_DICT = ''
THE_MISSION = ''
SPECIAL_ROOM_CHARGED = ''
MONSTER_CLASS = ''
POV_LIST = []
ROOMS_NUMBERS_LIST = []
PRIMARY_PATH = []
START_FROM = ''
ARRIVE_TO = '' # randomly selected by the app from point of views kesy
MIN_PATH = 4 # randomly selected by the app between 3 and 6
SECONDARY_PATH = []
THE_SECONDARY_START = ''
THE_SECONDARY_ARRIVE = ''
THE_SECONDARY_MIN_PATH = ''
COMPLEX_PATH = []
POINT_OF_VIEW_EXPLORED = []
DUNGEON_EXPLORED = []
ROOMS_EXPLORED_LAST_TURN = 0
DOORS_TO_ROOMS_APPLIED = []
ROOMS_EXPLORED = []
CONNECTION = sqlite3.connect('./db_heroquest_legends.sqlite')
CURSOR = CONNECTION.cursor()
NEW_DATA_TO_TEST_DELETE = 0
ROOMS_RANDOM_EVENTS = []
"""DATA FROM DATABASE"""
#charge alls the fornitures linked to ID
db_fornitures_query = CURSOR.execute("Select * from fornitures")
db_fornitures_charged = db_fornitures_query.fetchall()
#charge alls the monsters linked to ID
db_monsters_query = CURSOR.execute("Select * from monsters")
db_monsters_charged = db_monsters_query.fetchall()
FORNITURES_QTY_DICT = {"1":db_fornitures_charged[0][2],
"2":db_fornitures_charged[1][2],
"3":db_fornitures_charged[2][2],
"4":db_fornitures_charged[3][2],
"5":db_fornitures_charged[4][2],
"6":db_fornitures_charged[5][2],
"7":db_fornitures_charged[6][2],
"8":db_fornitures_charged[7][2],
"9":db_fornitures_charged[8][2],
"10":db_fornitures_charged[9][2],
"11":db_fornitures_charged[10][2],
"12":db_fornitures_charged[11][2],
"13":db_fornitures_charged[12][2]}
MONSTERS_QTY_DICT = {"1":db_monsters_charged[0][2],
"2":db_monsters_charged[1][2],
"3":db_monsters_charged[2][2],
"4":db_monsters_charged[3][2],
"5":db_monsters_charged[4][2],
"6":db_monsters_charged[5][2],
"7":db_monsters_charged[6][2],
"8":db_monsters_charged[7][2],
"9":db_monsters_charged[8][2]}
MONSTERS_COMBAT_VALUES_DICT = {"1":db_monsters_charged[0][4],
"2":db_monsters_charged[1][4],
"3":db_monsters_charged[2][4],
"4":db_monsters_charged[3][4],
"5":db_monsters_charged[4][4],
"6":db_monsters_charged[5][4],
"7":db_monsters_charged[6][4],
"8":db_monsters_charged[7][4],
"9":db_monsters_charged[8][4]}
MONSTERS_CATEGORY = {"1":db_monsters_charged[0][1],
"2":db_monsters_charged[1][1],
"3":db_monsters_charged[2][1],
"4":db_monsters_charged[3][1],
"5":db_monsters_charged[4][1],
"6":db_monsters_charged[5][1],
"7":db_monsters_charged[6][1],
"8":db_monsters_charged[7][1],
"9":db_monsters_charged[8][1]
}
"""DATA FROM INTERNAL DICT FOR DUNGEON GENERATION"""
POINT_OF_VIEW = {
"A": ("1", "4"),
"B": ("1", "2"),
"C": ("2", "3"),
"D": ("3", "4"),
"E": ("1", "5", "6"),
"F": ("2", "6", "7"),
"G": ("3", "7", "8"),
"H": ("4", "5", "8"),
"1": ("A", "B", "E"),
"2": ("B", "C", "F"),
"3": ("C", "D", "G"),
"4": ("A", "D", "H"),
"5": ("E", "H"),
"6": ("E", "F"),
"7": ("F", "G"),
"8": ("G", "H")}
DUNGEON_TO_ROOM = {
"A1": ("401", "402", "403"),
"B1": ("301", "302", "303"),
"B2": ("301", "304"),
"C2": ("201", "204"),
"C3": ("201", "202", "203"),
"D3": ("101", "102", "103"),
"D4": ("101", "104"),
"A4": ("401", "404"),
"E1": ("303", "403", "501"),
"E5": ("403", "406", "501"),
"E6": ("303", "305", "501"),
"F2": ("204", "205", "304", "305", "501"),
"F6": ("303", "305", "501"),
"F7": ("203", "205", "501"),
"G3": ("103", "203", "501"),
"G7": ("203", "205", "501"),
"G8": ("103", "105", "501"),
"H4": ("104", "105", "404", "405", "406", "501"),
"H5": ("403", "406", "501"),
"H8": ("103", "105", "501")}
ROOM_TO_ROOM = {
"101": ("102", "104"),
"102": ("101", "103", "105"),
"103": ("102", "105"),
"104": ("101", "105"),
"105": ("102", "103", "104"),
"201": ("202", "204"),
"202": ("201", "203", "205"),
"203": ("202", "205"),
"204": ("201", "205"),
"205": ("202", "203", "204"),
"301": ("302", "304"),
"302": ("301", "303", "305"),
"303": ("302", "305"),
"304": ("301", "305"),
"305": ("302", "303", "304"),
"401": ("402", "404"),
"402": ("401", "403", "404", "405", "406"),
"403": ("402"),
"404": ("401", "404", "405", "406"),
"405": ("402", "404", "406"),
"406": ("402", "405")}
ROOM_TO_DUNGEON = {
"101": ("D3", "D4"),
"102": ("D3"),
"103": ("D3", "G3", "G8"),
"104": ("D4", "H4"),
"105": ("H4", "H8"),
"201": ("C2", "C3"),
"202": ("C3"),
"203": ("C3", "G3", "G7"),
"204": ("C2", "F2"),
"205": ("F2", "F7"),
"301": ("B1", "B2"),
"302": ("B1"),
"303": ("B1", "E1", "E6"),
"304": ("B2", "F2"),
"305": ("F2", "F6"),
"401": ("A1", "A4"),
"402": ("A1"),
"403": ("A1", "E1"),
"404": ("A4", "H4"),
"405": ("H4"),
"406": ("H4", "H5"),
"501": (
"E1", "E5", "E6", "F2", "F6", "F7", "G3", "G7", "G8",
"H4", "H5", "H8")}
ROOMS_NUM_TILES = {
'101': 12,
'102': 12,
'103': 15,
'104': 20,
'105': 20,
'201': 16,
'202': 16,
'203': 15,
'204': 16,
'205': 16,
'301': 16,
'302': 12,
'303': 20,
'304': 16,
'305': 15,
'401': 16,
'402': 20,
'403': 15,
'404': 16,
'405': 6,
'406': 6,
'501': 30}
def __init__(self, cd):
"""The class is instanced with dictionary from config file"""
self.CONFIG_DICT = cd
#self.r_num = random
#position dict
self.position_dict = self.CONFIG_DICT["position_dict"]
#fornitures dict
self.forniture_dict = self.CONFIG_DICT['fornitures_dict']
#treasures dict that you can find inside a cest or in other forniture
self.treasures_card_dict = self.CONFIG_DICT['treasures_card_dict']
#monsters dict that you can find inside a Room or in a aisle
self.monsters_dict = self.CONFIG_DICT['monsters_dict']
def special_data_mission_charged(self, mn):
self.THE_MISSION = "{}".format(mn)
print("THE MISSION")
print(self.THE_MISSION)
self.SPECIAL_ROOM_CHARGED = self.CONFIG_DICT["specials_rooms"][self.THE_MISSION]
print("SPECIAL ROOM CHARGED")
print(self.SPECIAL_ROOM_CHARGED)
self.MONSTER_CLASS = self.CONFIG_DICT["monster_class"][self.THE_MISSION]
#remove_forniture_for_special_room
id_forniture_special_room_list = self.SPECIAL_ROOM_CHARGED[0] #charge id list
print("special room list:"+str(id_forniture_special_room_list))
for i in id_forniture_special_room_list:
values_str = "{}".format(i)
print("VALUES STRS")
print(str(values_str))
tot_forniture = self.FORNITURES_QTY_DICT[values_str]
new_tot_forniture = tot_forniture-1
self.FORNITURES_QTY_DICT[values_str] = new_tot_forniture
def charge_point_of_views(self):
for keys in self.POINT_OF_VIEW.keys():
self.POV_LIST.append(keys)
return self.POV_LIST
def charge_rooms_numbers(self):
for keys in self.ROOMS_NUM_TILES.keys():
self.ROOMS_NUMBERS_LIST.append(keys)
return self.ROOMS_NUMBERS_LIST
def random_numbers(self):
""" a random number generator based on four D6.
A simple statistic to understand the probability of success
>= X == y%
4 = 100%
5 = 99.92%
6 = 99.61%
7 = 98.84%
8 = 97.30%
9 = 94.60%
10 = 90.28%
11 = 84.10%
12 = 76.08%
13 = 66.44%
14 = 55.63%
15 = 44.37%
16 = 33.50%
17 = 23.92%
18 = 15.90%
19 = 9.72%
20 = 5.40%
21 = 2.70%
22 = 1.16%
23 = 0.39%
24 = 0.08% """
rng = random.SystemRandom()
value_1 = rng.randint(1, 6)
rng = random.SystemRandom()
value_2 = rng.randint(1, 6)
rng = random.SystemRandom()
value_3 = rng.randint(1, 6)
rng = random.SystemRandom()
value_4 = rng.randint(1, 6)
rn_list = [value_1, value_2, value_3, value_4]
rn_sum = sum(rn_list)
return rn_sum
def mission_percent_made(self, ct):
current_turn = ct
total_comparison_value = self.TOTAL_NUMBER_OF_TURNS+self.MAX_ROOM_COUNTER
partial_comparison_value =current_turn+self.CURRENT_ROOM_COUNTER
self.MISSION_PERCENT_MADE = (partial_comparison_value/total_comparison_value)*100
#TODO TO DELETE
total_turn = "total_turns_made {}".format(self.TOTAL_NUMBER_OF_TURNS)
total_rooms = "total_rooms {}".format(self.MAX_ROOM_COUNTER)
current_turn_made = "current_turn_made {}".format(current_turn)
current_room_made = "current_room_made {}".format(self.CURRENT_ROOM_COUNTER)
totale_percent_made = "total_percent_made {}".format(self.MISSION_PERCENT_MADE)
def permutation_sum(self,l):
"""NEW SYSTEM FOR ROOM GENERATION NOT USED BY NOW"""
sum(l)
if s == self.N:
self.RES.append(l)
return
elif s > self.N:
return
for x in range(1, self.N + 1):
self.permutation_sum(l + [x])
"""
def room_generator_2(self, room_dimension, ct, re):
#NEW SYSTEM FOR ROOM GENERATION NOT USED BY NOW
#create random rooms with fornitures 2
#create random rooms with fornitures
#turn controller INPUT
self.current_turn = ct
#room controller INPUT
self.room_explored = int(re)
rng = random.SystemRandom()
value = rng.randint(1, 2)
self.room_dimension = int(room_dimension)/value #total of room's tiles
#forniture_square_taken
tot_square_taken = 0
#messages controller
msg_forniture = ''
msg_monsters = ''
msg_end = ''
msg_list = []
#roll the dice and select a random number of fornitures between 1 and 3
rng = random.SystemRandom()
forniture_numbers = rng.randint(1, 4)
count = 0
ac = Permutation_class(int(self.room_dimension))
ac.rec([])
dimensions_list = Permutation_class.res
len_list_options= len(dimensions_list)
rng = random.SystemRandom()
slice_number = rng.randint(1, int(len_list_options))
"""
def room_generator(self, room_dimension, ct, re):
"""create random rooms with fornitures"""
#turn controller INPUT
self.current_turn = ct
#room controller INPUT
self.room_explored = int(re)
rng = random.SystemRandom()
value = rng.randint(2, 3)
rng = random.SystemRandom()
room_dimension = int(room_dimension)-rng.randint(1, 3)
self.room_dimension = round(int(room_dimension)/value) #total of room's tiles
#print("room dimension"+str(room_dimension))
#print("self room dimension"+str(self.room_dimension))
#forniture_square_taken
tot_square_taken = 0
#messages controller
msg_forniture = ''
msg_monsters = ''
msg_end = ''
msg_list = []
#roll the dice and select a random number of fornitures between 1 and 3
rng = random.SystemRandom()
forniture_numbers = rng.randint(1, 4)
#count = 0
#if the current turn is max or equal and the escape is founded
print("room gen 1")
if self.room_explored == 0:
if self.CURRENT_ROOM_COUNTER < self.MAX_ROOM_COUNTER:
self.CURRENT_ROOM_COUNTER += 1
if self.current_turn >= self.TOTAL_NUMBER_OF_TURNS and self.ESCAPE_FOUND==0 and self.room_explored == 0 and self.CURRENT_ROOM_COUNTER >= self.MAX_ROOM_COUNTER:
print("room gen 2")
msg_end = self.SPECIAL_ROOM_CHARGED[1] #Replace the number with THE_MISSION = RAND_NUM
self.ESCAPE_FOUND = 1
print("room gen 3")
else:
if self.room_explored == 0: #if the room is not explored
count = 0 #counter
for i in range(forniture_numbers):
rng_0 = random.SystemRandom()
alea = rng_0.randint(0, 10)
if alea <= 4:
rng_1 = random.SystemRandom()
id_forniture_rand = rng_1.randint(12, 13)
else:
rng_1 = random.SystemRandom()
id_forniture_rand_1 = rng_1.randint(0, 6)
rng_2 = random.SystemRandom()
id_forniture_rand_2 = rng_2.randint(1, 5) #create a random ID for fornitures between 1 and 13
id_forniture_rand = str(id_forniture_rand_1+id_forniture_rand_2)
#verify if the fornitures is still present
print("room gen 10")
forniture_residue = self.FORNITURES_QTY_DICT[str(id_forniture_rand)]
if forniture_residue > 0:
# charge from DB the selected fornitures
print("room gen 11")
query_select = '{}{}'.format("SELECT * FROM fornitures WHERE id_forniture = ", id_forniture_rand)
res = self.CURSOR.execute(query_select)
forniture_selected = res.fetchone()
print("room gen 13"+query_select)
square_taken_temp = forniture_selected[4]
tot_square_taken += square_taken_temp
#if there is residue space in rooms
print("room gen 14")
if tot_square_taken < self.room_dimension:
if count == 0:
print("room gen 15")
if id_forniture_rand == "11" or id_forniture_rand == "12":
rng = random.SystemRandom()
msg_forniture = '{} {} {};'.format(msg_forniture, self.forniture_dict[str(id_forniture_rand)],self.position_dict[str(rng.randint(1, 3))])
print("room gen 16")
else:
rng = random.SystemRandom()
msg_forniture = '{} {} {};'.format(msg_forniture, self.forniture_dict[str(id_forniture_rand)],self.position_dict[str(rng.randint(1, 5))])
new_forniture_residue = forniture_residue - 1
self.FORNITURES_QTY_DICT[id_forniture_rand] = new_forniture_residue
count = 1
else:
rng = random.SystemRandom()
msg_forniture = '{} {} {};'.format(msg_forniture, self.forniture_dict[str(id_forniture_rand)],
self.position_dict[str(rng.randint(1, 5))])
new_forniture_residue = forniture_residue - 1
self.FORNITURES_QTY_DICT[str(id_forniture_rand)] = new_forniture_residue
else: #no forniture is added and the temporary squares is re added
print("room gen 18")
tot_square_taken -= square_taken_temp
else: #if the forniture is not present
print("room gen 19")
msg_forniture = msg_forniture
if msg_forniture != '':
print("room gen 20")
msg_rand = rng.randint(0, 3)
aux_message = ['aux_msg_2', 'aux_msg_3', 'aux_msg_4', 'aux_msg_5']
msg_forniture = '{} {}.'.format(self.CONFIG_DICT[aux_message[msg_rand]], msg_forniture)
else:
print("room gen 21")
msg_forniture = self.CONFIG_DICT['aux_msg_7']
#generate the room
if self.FIRST_ROOM == 1:
print("room gen 22")
if self.ESCAPE_FOUND == 2:
print("room gen 22.1")
msg_monsters = self.monsters_generator_2(self.random_numbers(),tot_square_taken, self.current_turn,0)
if self.ESCAPE_FOUND == 0:
print("room gen 22.2")
msg_monsters = self.monsters_generator_2(self.random_numbers(),tot_square_taken, self.current_turn,0)
if self.ESCAPE_FOUND == 1:
print("room gen 22.3")
msg_monsters = self.monsters_generator_2(self.random_numbers(),tot_square_taken, self.current_turn,1)
self.ESCAPE_FOUND = 2
else:
print("room gen 23")
msg_monsters = self.CONFIG_DICT['monsters_msg_first_room']
self.FIRST_ROOM = 1
print("room gen 25")
msg_list.append(msg_forniture)
msg_list.append(msg_monsters)
msg_list.append(msg_end)
return msg_list
def monsters_generator_2(self, rv, square_taken, ct,n):
"""create random group of monsters based on squares taken by fornitures"""
self.rv = rv #the random values to know to create the percentage of possibilities to find monsters
self.residual_tiles = int(square_taken) #total of room's tiles residue
self.current_turn = ct
self.n = n #if in this turn the special room is founded
msg_monsters = ''
monsters_msg_partial = ''
print("monst gen 1")
if self.rv >= 20:
print("monst gen 2")
return '{} {}'.format(msg_monsters, self.CONFIG_DICT['monsters_msg_2'])
else:
print("monst gen 3")
if self.residual_tiles >= 0 and self.residual_tiles <= 3:
print("monst gen 4")
rng_base = random.SystemRandom()
monsters_number = rng_base.randint(1, 2)
elif self.residual_tiles > 3 and self.residual_tiles <= 6:
print("monst gen 5")
rng_base = random.SystemRandom()
monsters_number = rng_base.randint(1, 5)
elif self.residual_tiles > 6 and self.residual_tiles <= 12:
print("monst gen 6")
rng_base = random.SystemRandom()
monsters_number = rng_base.randint(1, 6)
elif self.residual_tiles > 12 and self.residual_tiles <= 30:
print("monst gen 8")
rng_base = random.SystemRandom()
monsters_number = rng_base.randint(4, 6)
else:
print("monst gen 9")
rng_base = random.SystemRandom()
monsters_number = 1
print("monst gen 10")
query_string_base="Select id_monster from monsters where "
query_string_where = ""
print("monst class lenght: "+str(len(self.MONSTER_CLASS)))
for cm in self.MONSTER_CLASS:
if query_string_where == "":
query_string_where = "monster_class = '{}' or monster_class LIKE '%{}' or monster_class LIKE '{}%' or monster_class LIKE '%{}%'".format(cm, cm, cm, cm)
print("monst gen 10.1: "+query_string_where)
else:
query_string_where += " or monster_class = '{}' or monster_class LIKE '%{}' or monster_class LIKE '{}%' or monster_class LIKE '%{}%'".format(cm, cm, cm, cm)
print("monst gen 10.2: " + query_string_where)
print("monst gen 11")
query_string = '{} {}'.format(query_string_base, query_string_where)
print("monst gen 12")
for i in range(monsters_number):
#choose id based on monster class
print("monst gen 12.1")
print(query_string)
db_monsters_class_query = self.CURSOR.execute(query_string)
print("monst gen 12.2")
db_monsters_class_charged = db_monsters_class_query.fetchall()
print("monst gen 12.3")
db_monsters_class_charged_list = []
print("monst gen 13")
for i in db_monsters_class_charged:
db_monsters_class_charged_list.append(i[0])
print("monst gen 14")
db_monsters_class_charged_lenght = len(db_monsters_class_charged_list)-1
rng = random.SystemRandom()
id_monster_rand = db_monsters_class_charged_list[rng.randint(0, db_monsters_class_charged_lenght)]
print("monst gen 15")
monsters_residue = int(self.MONSTERS_QTY_DICT[str(id_monster_rand)])
print("monst gen 16")
if monsters_residue > 0:
print("monst gen 17")
rng = random.SystemRandom()
monsters_msg_partial = '{} {} {};'.format(monsters_msg_partial,
self.monsters_dict[str(id_monster_rand)],
self.position_dict[str(rng.randint(1, 5))])
new_monster_residue = int(monsters_residue) - 1
self.MONSTERS_QTY_DICT[str(id_monster_rand)] = new_monster_residue
print("monst gen 18")
if monsters_msg_partial != '':
msg_monsters = '{} {} {}'.format(self.CONFIG_DICT['monsters_msg_intro'], monsters_msg_partial, self.CONFIG_DICT['monsters_msg_close'])
else:
if self.n == 0:
msg_monsters = '{} {}'.format(self.CONFIG_DICT['monsters_msg_intro'],self.CONFIG_DICT['monsters_msg_2'])
else:
msg_monsters = '{} {}'.format(self.CONFIG_DICT['monsters_msg_intro'],self.CONFIG_DICT['monsters_msg_5'])
return msg_monsters
def random_monsters_on_aisles(self, n):
turn = n
self.mission_percent_made(turn)
rn = self.random_numbers()
comparison_value = 0
if self.MISSION_PERCENT_MADE >= 100:
comparison_value = 5
elif self.MISSION_PERCENT_MADE >= 70:
comparison_value = 10
elif self.MISSION_PERCENT_MADE >= 20:
comparison_value = 18
else:
comparison_value = 15
if rn >= comparison_value:
query_string_base="Select id_monster from monsters where "
query_string_where = ""
for cm in self.MONSTER_CLASS:
if query_string_where == "":
query_string_where = "monster_class = '{}' or monster_class LIKE '%{}' or monster_class LIKE '{}%' or monster_class LIKE '%{}%'".format(cm, cm, cm, cm)
else:
query_string_where += " or monster_class = '{}' or monster_class LIKE '%{}' or monster_class LIKE '{}%' or monster_class LIKE '%{}%'".format(cm, cm, cm, cm)
query_string = '{} {}'.format(query_string_base, query_string_where)
db_monsters_class_query = self.CURSOR.execute(query_string)
db_monsters_class_charged = db_monsters_class_query.fetchall()
db_monsters_class_charged_list = []
for i in db_monsters_class_charged:
db_monsters_class_charged_list.append(i[0])
db_monsters_class_charged_lenght = len(db_monsters_class_charged_list) - 1
rng = random.SystemRandom()
id_monster_rand = db_monsters_class_charged_list[rng.randint(0, db_monsters_class_charged_lenght)]
monsters_residue = self.MONSTERS_QTY_DICT[str(id_monster_rand)]
if monsters_residue > 0:
msg_monsters = self.CONFIG_DICT['aux_msg_9'].format(self.monsters_dict[str(id_monster_rand)])
new_monster_residue = monsters_residue - 1
self.MONSTERS_QTY_DICT[str(id_monster_rand)] = new_monster_residue
if msg_monsters == "":
return "Per ora tutto ok!" #TODO sistemare il null
else:
return msg_monsters
else:
return self.CONFIG_DICT['aux_msg_10']
else:
return self.CONFIG_DICT['aux_msg_10']
def put_the_doors(self, d):
""""Receive the POV and describe where are the doors"""
print("PUT_THE_DOORS 1")
dungeon_id = d
print("PUT_THE_DOORS 3")
rooms_tup = self.DUNGEON_TO_ROOM[dungeon_id]
print("PUT_THE_DOORS 4")
rooms_list = []
for e in rooms_tup:
rooms_list.append(e)
for i in rooms_list:
if i in self.ROOMS_EXPLORED or i in self.DOORS_TO_ROOMS_APPLIED:
rooms_list.remove(i)
door_msg = ''
if len(rooms_list) > 0:
for room_num in rooms_list:
num = self.random_numbers()
if num >=12 and self.FORNITURES_QTY_DICT["13"]>=1 and room_num not in self.ROOMS_EXPLORED and room_num not in self.DOORS_TO_ROOMS_APPLIED:
rng = random.SystemRandom()
self.DOORS_TO_ROOMS_APPLIED.append(str(room_num))
door_type_msg = rng.randint(1, 2)
if door_type_msg == 1:
print("Door type ms 1")
door_msg += self.CONFIG_DICT["dungeon_msg_01"].format(str(room_num))
new_doors_residue = self.FORNITURES_QTY_DICT["13"] - 1
self.FORNITURES_QTY_DICT["11"] = new_doors_residue
else:
print("Door msg plus")
door_msg += self.CONFIG_DICT['dungeon_msg_02'].format(str(room_num))
new_doors_residue = self.FORNITURES_QTY_DICT["13"] - 1
self.FORNITURES_QTY_DICT["11"] = new_doors_residue
else:
print("Door pass to verify")
pass #TODO VERIFY THIS PASS....
#door_msg += "No doors for room {}. \n".format(str(room_num))
print("door_msg 9867: " + str(door_msg))
else:
door_msg = self.CONFIG_DICT['dungeon_msg_22']
print("door_msg: 6587"+door_msg)
return door_msg
def how_is_the_dungeon(self, pv, r):
print("How_is_the_dungeon")
"""DESCRIBE THE DUNGEON MAIN BASED ON PRIMARY PATH AND SECONDARY PATH. THERE ARE MANY DIFFERENT CASE
THAT THIS FUNCTION ANALYSE AND PASS TO def run_how_is_the_dungeon"""
pointofview = pv
round = r
msg = self.CONFIG_DICT['dungeon_msg_00'].format(str(round))
#ESTENSIONE DEL PRIMO PATH DAL PRIMO A PARTIRE DAL PRIMO PUNTO DEL PRIMARY PATH
if pointofview == self.START_FROM and pointofview == self.THE_SECONDARY_START:
print("HITD OP1")
pov_direction = self.run_how_is_the_dungeon(pointofview, 1)
msg += self.CONFIG_DICT['dungeon_msg_13'].format(str(pov_direction))
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
# ESTENSIONE DALL'ULTIMO PUNTO DEL PRIMARY PATH
elif pointofview == self.ARRIVE_TO and pointofview == self.THE_SECONDARY_START:
print("HITD OP2")
pov_direction = self.run_how_is_the_dungeon(pointofview, 2)
msg += self.CONFIG_DICT['dungeon_msg_14'].format(str(pov_direction))
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
#BIFORCAZIONE AL CENTRO se il punto corrente corrisponde a qualcosa in primary path e inizio del secondario: alla biforcazione
elif pointofview in self.PRIMARY_PATH and pointofview == self.THE_SECONDARY_START:
print("HITD OP3")
pov_direction = self.run_how_is_the_dungeon(pointofview, 3)
msg += self.CONFIG_DICT['dungeon_msg_15'].format(str(pov_direction)) #self.CONFIG_DICT['dungeon_msg_12'].format(str(next_pov_primary),str(next_pov_secondary))
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
elif pointofview == self.START_FROM:
print("HITD OP4")
pov_direction = self.run_how_is_the_dungeon(pointofview, 4)
msg += self.CONFIG_DICT['dungeon_msg_16'].format(str(pov_direction))
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
elif pointofview == self.ARRIVE_TO:
print("HITD OP5")
pov_direction = self.run_how_is_the_dungeon(pointofview, 5)
msg += self.CONFIG_DICT['dungeon_msg_17'].format(pov_direction)
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
elif pointofview == self.THE_SECONDARY_ARRIVE:
print("HITD OP6 a")
pov_direction = self.run_how_is_the_dungeon(pointofview, 6)
print("HITD OP6 b")
msg += self.CONFIG_DICT["dungeon_msg_18"].format(pov_direction)
print("HITD OP6 c")
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
print("HITD OP6 d")
return msg
elif pointofview in self.PRIMARY_PATH:
print("HITD OP7")
pov_direction = self.run_how_is_the_dungeon(pointofview, 7)
msg += self.CONFIG_DICT['dungeon_msg_19'].format(pov_direction)
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
elif pointofview in self.SECONDARY_PATH:
print("HITD OP8")
pov_direction = self.run_how_is_the_dungeon(pointofview, 8)
msg += self.CONFIG_DICT['dungeon_msg_19'].format(pov_direction)
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
elif pointofview not in self.COMPLEX_PATH:
print("HITD OP9")
msg += self.CONFIG_DICT['dungeon_msg_20']
self.POINT_OF_VIEW_EXPLORED.append(pointofview)
return msg
def run_how_is_the_dungeon(self, pov, sn):
"""DUNGEON CREATION SYSTEM: DESCRIBE THE DUNGEON STARTING FROM A POV AND A CASE, BASED ON
POV AND PRIMARY AND SECONDARY PATH"""
self.pointofview_l = pov
self.system_number = sn
#carica i singoli punti di vista legati al punto di vista corrente
single_points = self.POINT_OF_VIEW[self.pointofview_l]
msg = self.CONFIG_DICT['dungeon_msg_23']
if self.system_number == 1:
pov_1 = self.PRIMARY_PATH[1]
pov_2 = self.SECONDARY_PATH[1]
for i in single_points:
if i == pov_1 or i == pov_2:
msg += self.CONFIG_DICT['dungeon_msg_21'].format(str(i))
if i.isdigit() is True:
dungeon_id = '{}{}'.format(str(self.pointofview_l), str(i))
msg_doors = self.put_the_doors(dungeon_id)
msg += msg_doors
else:
dungeon_id = '{}{}'.format(str(i), str(self.pointofview_l))
msg_doors = self.put_the_doors(dungeon_id)
msg += msg_doors
else:
if i not in self.POINT_OF_VIEW_EXPLORED:
msg += self.CONFIG_DICT['dungeon_msg_24'].format(str(i))
return msg
if self.system_number == 2:
pov_1 = self.SECONDARY_PATH[1]
for i in single_points:
if i == pov_1:
msg += self.CONFIG_DICT['dungeon_msg_21'].format(str(i))
if i.isdigit() is True:
dungeon_id = '{}{}'.format(
str(self.pointofview_l), str(i))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(dungeon_id)
else:
dungeon_id = '{}{}'.format(str(i), str(
self.pointofview_l))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(dungeon_id)
else:
if i not in self.POINT_OF_VIEW_EXPLORED:
msg += self.CONFIG_DICT['dungeon_msg_25'].format(str(i))
return msg
if self.system_number == 3:
pov_1 = self.PRIMARY_PATH[self.PRIMARY_PATH.index(self.pointofview_l)+1]
pov_3 = self.PRIMARY_PATH[self.PRIMARY_PATH.index(self.pointofview_l)-1]
pov_2 = self.SECONDARY_PATH[1]
for i in single_points:
if i == pov_1 or i == pov_2 or i == pov_3 :
if i in self.POINT_OF_VIEW_EXPLORED:
msg += self.CONFIG_DICT['dungeon_msg_26'].format(str(i))
else:
msg += self.CONFIG_DICT['dungeon_msg_21'].format(str(i))
if i.isdigit() is True:
dungeon_id = '{}{}'.format(
str(self.pointofview_l), str(i))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(
dungeon_id)
else:
dungeon_id = '{}{}'.format(str(i),
str(
self.pointofview_l))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(
dungeon_id)
else:
msg += self.CONFIG_DICT['dungeon_msg_27'].format(str(i))
return msg
if self.system_number == 4:
pov_1 = self.START_FROM
for i in single_points:
if str(i) == self.PRIMARY_PATH[self.PRIMARY_PATH.index(pov_1)+1]:
msg += self.CONFIG_DICT['dungeon_msg_21'].format(str(i))
if i.isdigit() is True:
dungeon_id = '{}{}'.format(
str(self.pointofview_l), str(i))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(dungeon_id)
else:
dungeon_id = '{}{}'.format(str(i), str(
self.pointofview_l))
msg_doors = self.put_the_doors(
dungeon_id)
msg += msg_doors
self.DUNGEON_EXPLORED.append(dungeon_id)
else:
if i not in self.POINT_OF_VIEW_EXPLORED:
msg += self.CONFIG_DICT['dungeon_msg_25'].format(str(i))
return msg
if self.system_number == 5:
msg = self.CONFIG_DICT['dungeon_msg_28']
return msg
if self.system_number == 6:
msg = self.CONFIG_DICT['dungeon_msg_29']
for i in single_points:
if i not in self.COMPLEX_PATH:
msg += self.CONFIG_DICT['dungeon_msg_24'].format(str(i))
return msg
if self.system_number == 7:
for i in single_points:
if str(i) == self.PRIMARY_PATH[self.PRIMARY_PATH.index(self.pointofview_l)+1] or str(i) == self.PRIMARY_PATH[self.PRIMARY_PATH.index(self.pointofview_l)-1]:
msg += self.CONFIG_DICT['dungeon_msg_30'].format(str(i))
if i.isdigit() is True:
dungeon_id = '{}{}'.format(str(self.pointofview_l), str(i))
msg_doors = self.put_the_doors(dungeon_id)
print("msg_door_32_gigi {}".format(msg_doors))
if msg_doors != '' and i not in self.POINT_OF_VIEW_EXPLORED:
msg += msg_doors
self.DUNGEON_EXPLORED.append(dungeon_id)
elif msg_doors != '':
rng_1 = random.SystemRandom() # you'll find a weapon
rand_num = rng_1.randint(1, 3)
if rand_num == 1:
print("dungeon_msg_31")
msg += self.CONFIG_DICT['dungeon_msg_31'].format(msg_doors)
elif rand_num == 2:
print("dungeon_msg_32 con Dungeon ID")
msg += self.CONFIG_DICT['dungeon_msg_32'].format(dungeon_id, msg_doors)
else:
print("dungeon_msg_33")
msg = self.CONFIG_DICT['dungeon_msg_33']
self.DUNGEON_EXPLORED.append(dungeon_id)
else:
dungeon_id = '{}{}'.format(str(i), str(self.pointofview_l))
msg_doors = self.put_the_doors(
dungeon_id)
self.DUNGEON_EXPLORED.append(dungeon_id)
if msg_doors != '' and i in self.POINT_OF_VIEW_EXPLORED: