-
Notifications
You must be signed in to change notification settings - Fork 0
/
slotmachine_main.py
1586 lines (1336 loc) · 43.7 KB
/
slotmachine_main.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
# -*- coding: cp1252 -*-
# Copyright (C) 2005 by Alex Duesel <alex@alex-duesel.de>
# homepage: http://www.mandarine.tv
# See file license.txt for licensing issues
#
# 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 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
slotmachine_main.py - Simulation of a state-of-the-art slotmachine
If you have ever wondered how a State-of-the-Art slotmachine works,
then this Python program is for you.
It features a complete state machine, bonus scheme and special rules of a commercial slotmachine.
Well actually I modified the rules in order to get a better payout rate :-]
I wrote this simulation after I quit my job in the casino games industry back in 2005.
It features various parameter options, even support for macros, see comments in source code.
Options:
-h : this help text
-r : TOTAL RISK Mode
-b : BLIND GAME
-a : Accept 40TS and Total Risk
-i : interactive mode do not use -b and -t options
-l : turn logging on in conjunction with -b, -r and -t
-n : number of games
-m : MACRO mode
Default option -i
Examples:
python slotmachine_main.py -r -l -n 3400 > output.txt
python slotmachine_main.py -b -n 1000
python slotmachine_main.py -i
python slotmachine_main.py -m a5[10]1 > ausgabe.txt
python slotmachine_main.py -t -l > test.txt
python slotmachine_main.py -t
slotmachine_main.py mini.py -l -z -r -n 100000 > test.txt
Hint: Hold 'Enter' key in interactive mode in order to speed run games
'''
import random
import string
import time
import os
import getopt
import sys
import math
from slotmachine_tables import *
# constants and variables
NUM_GAMES = 3400000
DEPOSIT = 20
EXTRAGAME_BOUNDS = 4
FOUR_ROW_MODE_BOUNDS = 100
INTERACTIVE = 0
LOGGING = 0
MACRO = 0
BLIND = 0
TOTAL = 0
TEST = 0
RECEIVING_40 = 0
ADVANCED_LOGGING = 1
TEXT_MODE = 0
RISK_FINISHED = 12
UNDEFINED = -1
COLUMN_WIN_COMBINATIONS = 0
COLUMN_NEXT_STATE = 1
COLUMN_MONEY = 2
COLUMN_SUPER = 3
COLUMN_TURBO = 4
COLUMN_FOUR_ROW = 5
COLUMN_EXTRA = 6
COLUMN_JACKPOT = 7
COLUMN_RANK = 8
COLUMN_SYMBOL = 9
DEFAULT = 255
ROLLERS = 'Normal Rotor-Game'
MONEY_TOTAL = "Summe of all money prizes"
SUPER_TOTAL = "Sum of all Super Games:"
TURBO_TOTAL = "Sum of all Turbo Games:"
FOUR_ROW_TOTAL = "Sum of all Four-Row Games:"
EXTRA_TOTAL = "Sum of all Extra Points:"
JPTOTAL = "Sum of all Jackpot Points:"
POWER_RUN_COUNTER = "Power Run Counter"
POWER_RUN_HITS = "Power Run Hits"
TURBO_RUN = "Turbo Run"
SUPER_RUN = "Super Run"
NO_HITS = 'Fail!'
LOG = 'Logging procedure'
END_OF_GAME = 'Game Over!'
ROWS = 'Winning Rows'
PROCESS = "Key Handling"
counter = {}
stats = {}
carry = {}
counter[EXTRA_POINT] = 0
counter[TURBO] = 0
counter[FOUR_ROW] = 0
counter[SUPER] = 0
counter[JP] = 1
counter[MONEY] = 2000
counter[MONEY_TOTAL] = 0
counter[EXTRA_TOTAL] = 0
counter[TURBO_TOTAL] = 0
counter[FOUR_ROW_TOTAL] = 0
counter[SUPER_TOTAL] = 0
counter[JPTOTAL] = 0
counter[POWER_RUN_COUNTER] = 0
counter[POWER_RUN_HITS] = 0
counter[EXTRA_PLUS_LEFT] = 0
counter[EXTRA_PLUS_RIGHT] = 0
counter[TURBO_RUN] = 0
counter[SUPER_RUN] = 0
counter[NO_HITS] = 0
carry[MONEY] = 0
carry[SUPER] = 0
carry[TURBO] = 0
carry[FOUR_ROW] = 0
carry[EXTRA_POINT] = 0
carry[JP] = 0
game_mode = NORMAL
winning_combinations = []
winning_combinations_stack = []
extra_double_jump = 0
in_run = 0
free_flg = 0
four_row_flg = 0
risk_accept_flg = 0
risk_start_flg = 0
num_games = 0
num_won = 0
num_risk_steps = 0
num_wheel = 0
num_draws = 0
num_jackpot = 0
risk_fail_flg = 0
risk_win_flg = 0
cheatrun = 0
cheatcode = 0
macro_list = []
picture = [ S20C, S20C, S20C,\
S20C, S20C, S20C ]
next_combination = ()
def get_turbo_plan():
return SUPER_PLAN
def get_normal_plan():
return NORMAL_PLAN
def get_turbol_plan():
if game_mode == SUPER and counter[SUPER] <= 19:
return TURBO_PLAN
else:
return SUPER_PLAN
BONUS_SCHEME = {
NORMAL : get_normal_plan,
TURBO : get_turbo_plan,
SUPER : get_turbol_plan,
FOUR_ROW: get_normal_plan
}
# cheatcodes
def get_cheatrun(cheatcode, picture):
'''... this procedure should be rather self-explanatory :-] ...'''
if cheatcode == 'a': return (S30C,S30C,S30C, \
S50C,S80C,S20C)
if cheatcode == 'b': return (S20C,S20C,S20C, \
S50C,S80C,S30C)
if cheatcode == 'c': return (JACK,JACK,JACK, \
S50C,S80C,S30C)
if cheatcode == 'd': return (S50C,S80C,S30C, \
S50C,S80C,S30C)
if cheatcode == 'e': return (S50C,S50C,S50C, \
S50C,S80C,S30C)
if cheatcode == 'f': return (S160C,S160C,S160C, \
S50C, S80C, S30C)
if cheatcode == 'g': return (S50C,S80C,S160C, \
S50C,S80C,S30C)
if cheatcode == 'h': return (S50C,S80C,JACK, \
S50C,S80C,S160)
if cheatcode == 'i': return (S50C,S80C,S3BAR, \
S80C,S50C,S1BAR)
if cheatcode == 'j': return (JACK,JACK,JACK, \
S80C,S50C,S1BAR)
if cheatcode == 'k': return (S50C,S80C,S7, \
S80C,S50C,S30C)
if cheatcode == 'l': return (S50C,S80C,S7, \
S50C,S80C,S30C)
if cheatcode == 'm': return (S80C,S50C,S80C, \
S50C,S80C,S30C)
if cheatcode == 'n': return (S50C, S80C, S30C, \
S160C,S160C,S160C)
if cheatcode == 'o': return (S2BAR, S2BAR, S2BAR, \
S160C,S160C,S160C)
if cheatcode == 'p': return (S7, S7, S7, \
S160C,S160C,S160C)
return picture
# rule base
def pre_rules(game_state, index):
'''... these special rules will be evaluated before a state change triggered by the state table ...'''
global extra_double_jump
global game_mode
global winning_combinations
global in_run
global free_flg
global four_row_flg
global risk_start_flg
global winning_line
# set game_mode { NORMAL | SUPER | TURBO | FOUR_ROW }
if counter[FOUR_ROW] >= FOUR_ROW_MODE_BOUNDS or four_row_flg:
game_mode = FOUR_ROW
four_row_flg = 1
if counter[TURBO] > 0:
game_mode = TURBO
counter[SUPER] = 0
elif counter[SUPER] > 0:
game_mode = SUPER
elif not four_row_flg:
game_mode = NORMAL
# reset free games mode
if len(winning_combinations) > 0:
counter[NO_HITS] = 0
free_flg = 0
# if we reach TURBO game mode we will change our SUPER games into TURBO games 1:1
if game_state == WIN and game_mode == TURBO and carry[SUPER] > 0:
if LOGGING or INTERACTIVE: print "Rule: Change Super-Games 1:1 into Turbo-Games"
carry[TURBO] = carry[SUPER]
carry[SUPER] = 0
# we let our Success-Run begin if we win SUPER or TURBO games for the first time
if game_state == WIN and (carry[TURBO] > 0 or carry[SUPER] > 0) \
and not in_run and counter[TURBO] == 0 and counter[SUPER] == 0:
if LOGGING or INTERACTIVE: print "Rule: Success-Run started!"
in_run = 1
counter[POWER_RUN_HITS] = 0
counter[SUPER_RUN] = 0
counter[TURBO_RUN] = 0
# restart Success-Run if we win TURBO games in SUPER games mode
if in_run and game_mode == SUPER and carry[TURBO] > 0 \
and game_state == WIN:
if LOGGING or INTERACTIVE: print "Rule: Restart Success-Run!"
counter[POWER_RUN_COUNTER] = 0
in_run = 1
counter[POWER_RUN_HITS] = 0
counter[SUPER_RUN] = 0
counter[TURBO_RUN] = 0
# count SUPER and TURBO games if we are in a Success-RUN
if game_state == WIN and in_run:
if carry[TURBO] > 0:
counter[TURBO_RUN]+=carry[TURBO]
elif carry[SUPER] > 0:
counter[SUPER_RUN]+=carry[SUPER]
# if not in FREE games mode charge money for one game
if counter[MONEY] > 20 and game_state == ROLLERS and not free_flg:
counter[MONEY]-=DEPOSIT
# set free games mod (well at the moment you can can get free games only when you do not win anything in 100 games)
# be careful this has a big impact on the payout rate
if counter[NO_HITS] >= 100:
if LOGGING or INTERACTIVE: print "Rule: Free Games running!"
free_flg = 1
# decrement FOUR-ROW games
if counter[FOUR_ROW] > 0 and game_state == ROLLERS and game_mode == FOUR_ROW:
counter[FOUR_ROW]-=1
# exit FOUR-ROW mode
if counter[FOUR_ROW]==0:
four_row_flg = 0
# decrement SUPER games
if counter[SUPER] > 0 and game_state == ROLLERS and game_mode == SUPER:
counter[SUPER]-=1
# exit Success-Run
if in_run and counter[SUPER] == 0:
in_run = 0
if counter[POWER_RUN_COUNTER] > 0:
counter[POWER_RUN_COUNTER] = 0
# decrement TURBO games
if counter[TURBO] > 0 and game_state == ROLLERS and game_mode == TURBO:
counter[TURBO]-=1
# exit Success-Run
if in_run and counter[TURBO] == 0:
in_run = 0
if counter[POWER_RUN_COUNTER] > 0:
counter[POWER_RUN_COUNTER] = 0
# calculate POWER-RUN when in SUPER games mode
if counter[SUPER] > 0 and game_mode == SUPER and in_run:
counter[POWER_RUN_COUNTER] = counter[POWER_RUN_HITS]-math.ceil(counter[SUPER_RUN]*0.5)
# calculate POWER-RUN when in TURBO games mode
if counter[TURBO] > 0 and game_mode == TURBO and in_run:
counter[POWER_RUN_COUNTER] = counter[POWER_RUN_HITS]-math.ceil(counter[TURBO_RUN]*0.75)
# win another TURBO game if POWER-RUN < 0
if game_mode == TURBO and counter[POWER_RUN_COUNTER] < 0 and counter[TURBO]==0:
if LOGGING or INTERACTIVE: print "Rule: Won another Turbo-Game for free"
counter[TURBO] = 1
# win another SUPER game if POWER-RUN < 0
if game_mode == SUPER and counter[POWER_RUN_COUNTER] < 0 and counter[SUPER]==0:
if LOGGING or INTERACTIVE: print "Rule: Won another Super-Game for free"
counter[SUPER] = 1
# win a Wheel of Fortune 60 draw
if counter[JP]==7 and (S50C, S50C, S50C) in winning_combinations:
if LOGGING or INTERACTIVE: print "Rule: Jackpot-Win a Wheel of Fortune 60 draw!"
counter[JP]=1
counter[EXTRA_POINT]+=3
counter[EXTRA_TOTAL]+=3
winning_combinations = []
return WHEEL60
# win a Wheel of Fortune 80 draw
elif counter[JP]==8 and (S160C, S160C, S160C) in winning_combinations:
if LOGGING or INTERACTIVE: print "Rule: Jackpot-Win a Wheel of Fortune 80 draw!"
counter[JP]=1
counter[EXTRA_POINT]+=4
counter[EXTRA_TOTAL]+=4
winning_combinations = []
return WHEEL80
## RISK-LINES
# no RISK lines when in blind game mode
if (game_state == RISK_L or game_state == RISK_R) and BLIND:
if LOGGING or INTERACTIVE: print "Rule: BLIND -> No risk line!"
if carry[SUPER] > 0 and counter[TURBO]>0:
if LOGGING or INTERACTIVE: print "Rule: Change Super-Games 1:1 into Turbo-Games"
carry[TURBO] = carry[SUPER]
carry[SUPER] = 0
return WIN
# no RISK lines when TURBO games or SUPER games counter > 200
if (counter[TURBO] > 200 or counter[SUPER] > 200) \
and (game_state == RISK_L or game_state == RISK_R):
if LOGGING or INTERACTIVE: print "Regel: Sonder > 150 -> Kein Risiko!"
if carry[SUPER] > 0:
if LOGGING or INTERACTIVE: print "Rule: Change Super-Games 1:1 into Turbo-Games"
carry[TURBO] = carry[SUPER]
carry[SUPER] = 0
return WIN
# if risk line right step 4 then execute a DRAW200 game
if index == 4 and game_state == RISK_R:
return DRAW200
# if risk line left step 4 then execute a DRAW300 game
elif index == 4 and game_state == RISK_L:
return DRAW300
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_L and index == 5:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_R and index == 5:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_L and index == 7:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_R and index == 7:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_L and index == 9:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# executea double jump in risk line
elif counter[EXTRA_POINT] > 0 and game_state == RISK_R and index == 9:
if LOGGING or INTERACTIVE: print "Rule: Double-Jump!"
extra_double_jump = 1
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_L and index == 6:
risk_start_flg = 0
return START6S
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_L and index == 7:
risk_start_flg = 0
return START12S
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_L and index == 8:
risk_start_flg = 0
return START12T
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_L and index == 9:
risk_start_flg = 0
return START25T
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_L and index == 10:
risk_start_flg = 0
return START50T
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_R and index == 6:
risk_start_flg = 0
return START4S
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_R and index == 7:
risk_start_flg = 0
return START8S
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_R and index == 8:
risk_start_flg = 0
return START8T
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_R and index == 9:
risk_start_flg = 0
return START20T
# execute start draw when on risk line step
if risk_start_flg and game_state == RISK_R and index == 10:
risk_start_flg = 0
return START40T
# restart state
if counter[FOUR_ROW] >= FOUR_ROW_MODE_BOUNDS or four_row_flg:
game_mode = FOUR_ROW
four_row_flg = 1
if counter[TURBO] > 0:
game_mode = TURBO
counter[SUPER] = 0
elif counter[SUPER] > 0:
game_mode = SUPER
elif not four_row_flg:
game_mode = NORMAL
# default
return game_state
def post_rules(game_state, next_state, index):
'''... these special rules will be evaluated after a state change triggered by the state table ...'''
global winning_combinations_stack
global winning_combinations
global winning_line
# increment Jackpot-Points if RISK step accepted
if risk_accept_flg and game_state == RISK_R and next_state==WIN and index == 10:
if LOGGING or INTERACTIVE: print "Rule: Win Jackpot Points!"
counter[JP]+=1
counter[JPTOTAL]+=1
# if RISK step failed then evaluate next winning line (only in FOUR-ROW and NORMAL games)
if (game_state == RISK_L or game_state == RISK_R) and next_state == ROLLERS and \
len(winning_combinations_stack)>0 and \
(game_mode == NORMAL or game_mode==FOUR_ROW):
return NEXT_ROW
# another winning rule for Jackpot points
if game_state == DRAW3BAR and carry[TURBO] == 150 and next_state == WIN:
if LOGGING or INTERACTIVE: print "Rule: Win Jackpot Points!"
counter[JP]+=1
counter[JPTOTAL]+=1
# count FREE-GAMES mode games
if game_state == ROLLERS and len(winning_combinations)==0:
counter[NO_HITS]+=1
# split 150 SUPER games into 50 TURBO games + 1EXTRA Point
if (game_state==RISK_L or game_state==RISK_R or game_state.startswith("START") or \
game_state.startswith("FAIL")) \
and next_state == WIN and carry[TURBO] == 150:
if LOGGING or INTERACTIVE: print "Rule: Split into 50 TURBO games + 1EXTRA Point"
carry[TURBO] = 50
carry[EXTRA_POINT] = 1
# default
return next_state
def compare_picture_with_plan(picture, winning_lines, winning_plan):
'''... check if win in standard draw ...'''
global winning_combinations
i = 0
for row in winning_plan:
found = 1
j = 0
for symbol in row[COLUMN_WIN_COMBINATIONS]:
if(picture[winning_lines[j]]!=symbol and \
symbol!=JOKER):
found = 0
i+=1
break
j+=1
if found:
# hit!
return i, row[COLUMN_WIN_COMBINATIONS]
# no hit!
return UNDEFINED, UNDEFINED
def compare_draw_table(drawtable, rand_value):
'''... check if win in risk draw ...'''
prob = 0
index = 0
for wert in drawtable[PROPABILITY]:
prob += wert
if prob >= rand_value:
break
index+=1
if index < len(drawtable[PROPABILITY]):
# win!
return index
# no win!?
print "ERROR! No match in table found"
sys.exit(1)
def put_into_account(xtable, index, plan_row=None):
'''... put prize onto player's account ...'''
if plan_row==None:
# handle drawtable
prize = xtable[PRIZE][index]
typ = xtable[PRIZE_TYPE][index]
carry[typ] = prize
if prize > 0:
symbol = xtable[SYMBOLS][index]
carry[symbol] = 1
else:
# handle winning_plan put onto carry over
carry[MONEY] = plan_row[COLUMN_MONEY]
carry[SUPER] = plan_row[COLUMN_SUPER]
carry[TURBO] = plan_row[COLUMN_TURBO]
# instant win
counter[FOUR_ROW] += plan_row[COLUMN_FOUR_ROW]
counter[FOUR_ROW_TOTAL] += plan_row[COLUMN_FOUR_ROW]
counter[EXTRA_POINT] += plan_row[COLUMN_EXTRA]
counter[EXTRA_TOTAL] += plan_row[COLUMN_EXTRA]
counter[JP] += plan_row[COLUMN_JACKPOT]
counter[JPTOTAL] += plan_row[COLUMN_JACKPOT]
def win_route(statedict,name,index):
'''... puts carry overs onto counters ...'''
for z in carry.keys():
try:
counter[z] += carry[z]
except KeyError:
counter[z] = 0
counter[z] += carry[z]
counter[MONEY_TOTAL] += carry[MONEY]
counter[SUPER_TOTAL] += carry[SUPER]
counter[TURBO_TOTAL] += carry[TURBO]
counter[FOUR_ROW_TOTAL] += carry[FOUR_ROW]
counter[EXTRA_TOTAL] += carry[EXTRA_POINT]
counter[JPTOTAL] += carry[JP]
return ROLLERS, DEFAULT
def draw_process(statedict, name,index):
'''... random normal draw ...'''
rand_value = random.randint(1, 1000)
index = compare_draw_table(statedict[name][TABLE],rand_value)
if index != UNDEFINED:
if (MACRO or TEST) and (name == DRAW200 or name == DRAW300 \
or name == DRAW20 or name == DRAW30):
index= 0
# prize
put_into_account(statedict[name][TABLE], index)
return statedict[name][TABLE][NEXT_STATE][index], index
# should not happen
print "ERROR! no matchin value found"
sys.exit(1)
def risk_process(statedict, name,index):
'''... random risk draw ...'''
global risk_win_flg
global risk_fail_flg
global risk_accept_flg
if risk_accept_flg:
# accept risk step
put_into_account(statedict[name][TABLE],index)
return WIN, index
# step up
index+=1
if (random.randint(0, 1) or risk_win_flg) \
and not risk_fail_flg:
# prize
put_into_account(statedict[name][TABLE],index)
if index >= RISK_FINISHED:
# reached final step
return WIN, DEFAULT
# next step
return name, index
# risk failed!
if game_mode == NORMAL and index>=9 and index<=12:
# failed in top area win FOUR-ROW game
counter[FOUR_ROW]+=1
counter[FOUR_ROW_TOTAL]+=1
if index >= RISK_FINISHED:
# fail safe
if name == RISK_L:
return FAIL50, DEFAULT
else:
return FAIL40, DEFAULT
# normal fail
return ROLLERS, DEFAULT
def extra_risk_process(statedict, name,index):
'''... risk draw when EXTRA points on player's account ...'''
global risk_win_flg
global risk_fail_flg
global risk_accept_flg
if risk_accept_flg:
# accept
put_into_account(statedict[name][TABLE],index)
return WIN, index
# double setpup
index +=2
if(random.randint(1, 100)>30 or risk_win_flg) \
and not risk_fail_flg:
# prize
put_into_account(statedict[name][TABLE],index)
if index >= RISK_FINISHED-1:
# decrement EXTRA_POINT s
counter[EXTRA_POINT]-=1
return WIN, DEFAULT
# next step
return name, index
# fail
if game_mode == NORMAL and index>=9 and index<=12:
# failed in top area win FOUR-ROW game
counter[FOUR_ROW]+=1
counter[FOUR_ROW_TOTAL]+=1
return ROLLERS, DEFAULT
def extra_plus_risk_process(statedict, name,index):
'''... risk draw when extra_plus counters > 0 ...'''
global risk_win_flg
global risk_fail_flg
global risk_accept_flg
if risk_accept_flg:
# accept
put_into_account(statedict[name][TABLE],index)
return WIN, index
# stepup
index +=1
if(random.randint(1, 100)>30 or risk_win_flg) \
and not risk_fail_flg:
# prize
put_into_account(statedict[name][TABLE],index)
if name == RISK_L:
# decrement extra_plus counter
if index == counter[EXTRA_PLUS_LEFT]:
counter[EXTRA_PLUS_LEFT]-=1
else:
# decrement extra_plus counter
if index == counter[EXTRA_PLUS_RIGHT]:
counter[EXTRA_PLUS_RIGHT]-=1
# next step
return name, index
# fail
return ROLLERS, DEFAULT
def risk_dispatch_process(statedict, name,index):
'''... dispatches into various risk draw modes ...'''
global extra_double_jump
if counter[EXTRA_PLUS_LEFT] and name == RISK_L \
and index < counter[EXTRA_PLUS_LEFT]:
if (LOGGING or INTERACTIVE) and ADVANCED_LOGGING:
print "70% Risk Chance!"
return extra_plus_risk_process(statedict, name,index)
elif counter[EXTRA_PLUS_RIGHT] and name == RISK_R \
and index < counter[EXTRA_PLUS_RIGHT]:
if (LOGGING or INTERACTIVE) and ADVANCED_LOGGING:
print "70% Risk Chance!"
return extra_plus_risk_process(statedict, name,index)
elif extra_double_jump:
extra_double_jump = 0
if (LOGGING or INTERACTIVE) and ADVANCED_LOGGING:
print "70% Risk Chance!"
return extra_risk_process(statedict, name,index)
else:
if (LOGGING or INTERACTIVE) and ADVANCED_LOGGING:
print "50% Risk Chance!"
return risk_process(statedict, name,index)
def normal_process(statedict, name,index):
'''... normal rotor game ...'''
global winning_combinations
global winning_combinations_stack
global in_run
global picture
global restart_flg
global cheatrun
global winning_line
# draw
rotorpos = [0,0,0,0,0,0]
for i in range(len(rotorpos)):
rotorpos[i] = random.randint( 0, len(CYLINDER[i%3])-1)
picture = [ CYLINDER[0][rotorpos[0]], CYLINDER[1][rotorpos[1]], CYLINDER[2][rotorpos[2]],
CYLINDER[0][rotorpos[3]], CYLINDER[1][rotorpos[4]], CYLINDER[2][rotorpos[5]]]
# cheating
if cheatrun:
picture = get_cheatrun(cheatcode, picture)
rotorpos[0] = list(CYLINDER[0]).index(picture[0])
rotorpos[1] = list(CYLINDER[1]).index(picture[1])
rotorpos[2] = list(CYLINDER[2]).index(picture[2])
rotorpos[3] = list(CYLINDER[0]).index(picture[3])
rotorpos[4] = list(CYLINDER[1]).index(picture[4])
rotorpos[5] = list(CYLINDER[2]).index(picture[5])
# restart rotors
winsymbole = (S1BAR, S2BAR,S3BAR,S7,JACK)
if picture[TOP_LEFT] not in winsymbole and \
picture[BOTTOM_LEFT] not in winsymbole and not cheatrun:
n1 = random.randint( 0, len(CYLINDER[0])-1)
n2 = random.randint( 0, len(CYLINDER[0])-1)
picture[TOP_LEFT] = CYLINDER[0][n1]
picture[BOTTOM_LEFT] = CYLINDER[0][n2]
restart_flg = 1
cheatrun = 0
# evaluation
winning_plan = statedict[name][TABLE][game_mode]()
wiin_rows = statedict[name][ROWS][game_mode]
max_rang = UNDEFINED
winning_combinations = []
winning_combinations_stack = []
idx = 0
for row in wiin_rows:
i, kombi = compare_picture_with_plan(picture, row, winning_plan)
rang = UNDEFINED
if i != UNDEFINED:
rang = winning_plan[i][COLUMN_RANK]
winning_combinations_stack.append((rang,i,row))
winning_combinations.append(kombi)
if rang > max_rang:
max_rang = rang
winning_line = row
idx = i
# hit!
if len(winning_combinations)>0:
# Success-Run!
if in_run:
counter[POWER_RUN_HITS]+=1
if counter[POWER_RUN_COUNTER] < 0:
counter[POWER_RUN_COUNTER]+=1
elif counter[POWER_RUN_COUNTER] == 0:
in_run = 0
counter[POWER_RUN_HITS] = 0
counter[SUPER_RUN] = 0
counter[TURBO_RUN] = 0
# sort winning combinations
winning_combinations_stack.sort()
winning_combinations_stack.reverse()
# put_into_account
if max_rang != UNDEFINED:
# pop stack
winning_combinations_stack = winning_combinations_stack[1:]
# put_into_account and set next step
put_into_account(statedict[name][TABLE], idx, winning_plan[idx])
return winning_plan[idx][COLUMN_NEXT_STATE], idx
# no hit
return ROLLERS, DEFAULT
def jackpot_route(statedict, name,index):
'''... won jackpot: 2 EXTRA_POINT points and wheel of fortune 40'''
counter[JP]=1
counter[EXTRA_POINT]+=2
counter[EXTRA_TOTAL]+=2
return WHEEL40, DEFAULT
def extra_plus_process(statedict, name,index):
'''... increment extra plus counters and win 10C ...'''
if counter[EXTRA_PLUS_LEFT] < EXTRAGAME_BOUNDS or \
counter[EXTRA_PLUS_RIGHT] < EXTRAGAME_BOUNDS:
if counter[EXTRA_PLUS_LEFT] > counter[EXTRA_PLUS_RIGHT]:
counter[EXTRA_PLUS_RIGHT]+=1
else:
counter[EXTRA_PLUS_LEFT]+=1
carry[MONEY] = 10
return WIN, DEFAULT
def next_row_process(statedict, name,index):
'''... if more then one winning row check for the next one ...'''
global winning_combinations_stack
global next_combination
global naechste_linie
if len(winning_combinations_stack) > 0:
idx = winning_combinations_stack[0][1]
naechste_linie = winning_combinations_stack[0][2]
winning_combinations_stack = winning_combinations_stack[1:]
winning_plan = statedict[name][TABLE][game_mode]()
next_combination = winning_plan[idx][COLUMN_WIN_COMBINATIONS]
put_into_account(statedict[name][TABLE], idx, winning_plan[idx])
return winning_plan[idx][COLUMN_NEXT_STATE], idx
else:
# should not happen
print "ERROR: There is no next winning row!!!"
sys.exit(1)
# logging
def print_head():
'''... print counters ...'''
print "-------------------------------------------------------------"
print "Counters:"
c = (JP, TURBO, SUPER, FOUR_ROW, MONEY, EXTRA_POINT, EXTRA_PLUS_LEFT, EXTRA_PLUS_RIGHT, POWER_RUN_COUNTER)
for z in counter.keys():
if counter[z]!=0 and z in c:
print z, counter[z]
print "-------------------------------------------------------------"
def print_bottom():
''' ... print carry overs ...'''
for z in carry.keys():
if carry[z]>0:
print z, carry[z]
def log_normal(frame_nr, statedict, name, index):
'''... normal rotor game has been finished print result ...'''
global num_games
global picture
num_games+=1
if LOGGING or INTERACTIVE:
print "#############################################################"
print "Game No.: %s is a %s" % (str(frame_nr),name)
print "Mode: ",game_mode
if ADVANCED_LOGGING:
print "Rotor Picture:"
print picture[:3]
print picture[3:]
if len(winning_combinations)>0:
print "Winning combinations:"
for prize in winning_combinations:
print prize
print_head()
print_bottom()
def log_draw(frame_nr, statedict, name, index):
'''... risk draw has been finished ...'''
global num_draws
num_draws+=1
stats[name][statedict[name][TABLE][SYMBOLS][index]]+=1
if LOGGING or INTERACTIVE:
print "Game No. %s features a %s:" % (str(frame_nr), name)
print_bottom()
def log_wheel(frame_nr, statedict, name, index):
'''... wheel of fortune has been finsihed ...'''
global num_wheel
num_wheel+=1
stats[name][statedict[name][TABLE][SYMBOLS][index]]+=1
if LOGGING or INTERACTIVE:
print "Game No.: %s features a %s:" % (str(frame_nr), name)
print_bottom()
def log_risiko(frame_nr, statedict, name, index):
'''... risk step has been evaluated ...'''
global num_risk_steps
num_risk_steps+=1
if LOGGING or INTERACTIVE:
if not risk_accept_flg:
print "Risk accepted"