forked from lhayhurst/ladyluck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_summary_stats.py
889 lines (632 loc) · 33.3 KB
/
game_summary_stats.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
import collections
from flask import url_for
from AttackSet import AttackSet, INITIAL, SCORE, END
from counter import Counter, COUNTER
from parser import LogFileParser
from persistence import Game, DiceThrowType, DiceThrowAdjustmentType, DiceFace, DiceType, Dice
from plots.player_plots import LuckPlot, AdvantagePlot, DamagePlot, VersusPlot
from score import Score
STATIC = 'static'
__author__ = 'lhayhurst'
import unittest
class GameTapeRecord:
def __init__(self, attacking_player, defending_player):
self.attacking_player = attacking_player
self.defending_player = defending_player
self.dice_num = None
self.throw_num = None
self.attack_roll = None
self.attack_roll_luck = None
self.attack_reroll = None
self.attack_reroll_luck = None
self.attack_convert = None
self.attack_cancel = None
self.attack_convert_luck = None
self.attack_turn = None
self.defense_turn = None
self.attack_add = None
self.defense_add = None
self.attack_end = None
self.attack_end_luck = None
self.defense_roll = None
self.defense_luck = None
self.defense_reroll = None
self.defense_reroll_luck = None
self.defense_convert = None
self.defense_convert_luck = None
self.defense_end = None
self.defense_end_luck = None
self.defense_cancel = None
self.was_cancelled = False
def cancel(self):
self.was_cancelled = True
def get_image(self, dice):
if dice == None:
return url_for(STATIC, filename='blank.png')
if dice.dice_type == DiceType.RED and dice.dice_origination == Dice.ROLLED:
if dice.dice_face == DiceFace.HIT:
return url_for(STATIC, filename="red_hit.png")
elif dice.dice_face == DiceFace.CRIT:
return url_for(STATIC,filename="red_crit.png")
elif dice.dice_face == DiceFace.FOCUS:
return url_for(STATIC,filename="red_focus.png")
elif dice.dice_face == DiceFace.BLANK:
return url_for(STATIC,filename="red_blank.png")
elif dice.dice_type == DiceType.RED and dice.dice_origination == Dice.ADDED:
if dice.dice_face == DiceFace.HIT:
return url_for(STATIC, filename="added_hit.png")
elif dice.dice_face == DiceFace.CRIT:
return url_for(STATIC,filename="added_crit.png")
elif dice.dice_type == DiceType.GREEN and dice.dice_origination == Dice.ROLLED:
if dice.dice_face == DiceFace.EVADE:
return url_for(STATIC,filename="green_evade.png")
elif dice.dice_face == DiceFace.FOCUS:
return url_for(STATIC,filename="green_focus.png")
elif dice.dice_face == DiceFace.BLANK:
return url_for(STATIC,filename="green_blank.png")
elif dice.dice_type == DiceType.GREEN and dice.dice_origination == Dice.ADDED:
if dice.dice_face == DiceFace.EVADE:
return url_for(STATIC,filename="added_evade.png")
def final_as_image(self):
if self.was_cancelled == True:
return self.get_image(None)
elif self.was_not_a_hit_or_crit() == True:
return self.get_image(None)
else:
return self.attack_end_as_img()
def attack_roll_as_img(self):
return self.get_image(self.attack_roll)
def attack_reroll_as_img(self):
return self.get_image(self.attack_reroll)
def attack_convert_as_img(self):
return self.get_image(self.attack_convert)
def attack_cancelled_as_img(self):
return self.get_image(self.attack_cancel)
def defense_cancelled_as_img(self):
return self.get_image(self.defense_cancel)
def attack_end_as_img(self):
if self.attack_cancel:
return self.get_image(None)
return self.get_image(self.attack_end)
def attack_added_as_img(self):
return self.get_image(self.attack_add)
def defense_added_as_img(self):
return self.get_image(self.defense_add)
def defense_roll_as_img(self):
return self.get_image(self.defense_roll)
def defense_reroll_as_img(self):
return self.get_image(self.defense_reroll)
def defense_convert_as_img(self):
return self.get_image(self.defense_convert)
def defense_end_as_img(self):
return self.get_image(self.defense_end)
def visit(self, adjustment, atype):
if adjustment.adjustment_type == DiceThrowAdjustmentType.REROLL:
if atype == DiceThrowType.ATTACK:
self.attack_reroll = adjustment.to_dice
elif atype == DiceThrowType.DEFEND:
self.defense_reroll = adjustment.to_dice
elif adjustment.adjustment_type == DiceThrowAdjustmentType.CONVERT:
if atype == DiceThrowType.ATTACK:
self.attack_convert = adjustment.to_dice
elif atype == DiceThrowType.DEFEND:
self.defense_convert = adjustment.to_dice
elif adjustment.adjustment_type == DiceThrowAdjustmentType.TURNED:
if atype == DiceThrowType.ATTACK:
self.attack_turn = adjustment.to_dice
elif atype == DiceThrowType.DEFEND:
self.defense_turn = adjustment.to_dice
elif adjustment.adjustment_type == DiceThrowAdjustmentType.CANCELLED:
self.cancel()
if atype == DiceThrowType.ATTACK:
self.attack_cancel = adjustment.to_dice
elif atype == DiceThrowType.DEFEND:
self.defense_cancel = adjustment.to_dice
def was_not_a_hit_or_crit(self):
if self.was_hit() == True or self.was_crit() == True:
return False
return True
def was_hit(self):
if self.attack_end == None:
return False
return self.attack_end.is_hit()
def was_crit(self):
if self.attack_end == None:
return False
return self.attack_end.is_crit()
def was_evade(self):
if self.defense_end == None:
return False
return self.defense_end.is_evade()
class GameTape(object):
def __init__(self, game):
self.game = game
game.game_tape = self
throws = self.game.game_throws
attack_sets = []
self.attack_sets = attack_sets
#do the attack sets first
for throw in throws:
if throw.throw_type == DiceThrowType.ATTACK:
attack_set = AttackSet( throw.attack_set_num, throw )
attack_sets.append( attack_set )
attack_set.attacking_player = throw.player
for result in throw.results:
record = GameTapeRecord( attacking_player=attack_set.attacking_player,
defending_player=attack_set.defending_player)
attack_set.records.append(record)
record.dice_num = result.dice_num
record.attack_roll = result.dice
record.attack_end = result.final_dice
if result.final_dice.was_added():
record.attack_add = result.dice
record.attack_roll = None
for adjustment in result.adjustments:
record.visit(adjustment, DiceThrowType.ATTACK)
elif throw.throw_type == DiceThrowType.DEFEND:
attack_set = self.get_attack_set(throw.attack_set_num)
if attack_set is None: #happenswhen,for example, I roll defense dice and then you roll defesnse dice
continue
attack_set.add_defending_throw(throw)
for result in throw.results:
record = attack_set.get_record_for_dice_num( result.dice_num )
if record is not None:
record = attack_set.get_record_for_dice_num( result.dice_num )
record.defending_player = throw.player
record.defense_roll = result.dice
record.defense_end = result.final_dice
if result.final_dice.was_added():
record.defense_add = result.dice
record.defense_roll = None
for adjustment in result.adjustments:
record.visit(adjustment, DiceThrowType.DEFEND)
else:
record = GameTapeRecord(attacking_player=attack_set.attacking_player, defending_player=throw.player)
attack_set.records.append(record)
record.dice_num = result.dice_num
record.defense_roll = result.dice
record.defense_end = result.final_dice
for adjustment in result.adjustments:
record.visit(adjustment, DiceThrowType.DEFEND)
#now circle through all the records and net out the records
for ats in self.attack_sets:
ats.net_results()
def versus_graph(self, attacker, defender):
vp = VersusPlot( self.game, attacker, defender )
return vp.plot()
def luck_graph(self, player, plot_against_player, dice_type):
lp = LuckPlot( self.game, player, plot_against_player, DiceType.from_string(dice_type))
return lp.plot()
def advantage_graph(self, use_initial):
av = AdvantagePlot( self.game, use_initial)
return av.plot()
def damage_graph(self):
dg = DamagePlot(self.game)
return dg.plot()
def attack_set_subsets(self, modvalue=15):
ret = []
i = 0
subset = []
for ats in self.attack_sets:
i = i + 1
if i % modvalue == 0:
ret.append(list(subset))
subset = []
else:
subset.append( ats )
if len(subset) > 0:
ret.append(subset)
return ret
def total_attack_sets(self, player):
cnt = 0
for ats in self.attack_sets:
if ats.attacking_player.name == player.name:
cnt = cnt + 1
return cnt
def damage(self, player):
return self.damage_hash[ player.name ]
def score(self):
self.final_scores = collections.defaultdict( lambda: collections.defaultdict(list))
self.initial_scores = collections.defaultdict( lambda: collections.defaultdict(list))
self.stats = collections.defaultdict( lambda: collections.defaultdict(dict))
p1 = self.game.game_players[0].name
p2 = self.game.game_players[1].name
self.final_scores[ p1][ DiceType.RED ].append( 0 )
self.final_scores[ p2 ][ DiceType.RED ].append( 0 )
self.final_scores[ p1 ][ DiceType.GREEN ].append( 0 )
self.final_scores[ p2 ][ DiceType.GREEN ].append( 0 )
self.initial_scores[ p1][ DiceType.RED ].append( 0 )
self.initial_scores[ p2 ][ DiceType.RED ].append( 0 )
self.initial_scores[ p1 ][ DiceType.GREEN ].append( 0 )
self.initial_scores[ p2 ][ DiceType.GREEN ].append( 0 )
self.stats[ p1 ][INITIAL] = { COUNTER : Counter(True), SCORE: Score() }
self.stats[ p2 ][INITIAL] = { COUNTER : Counter(True), SCORE: Score() }
self.stats[ p1 ][END] = { COUNTER : Counter(True), SCORE: Score() }
self.stats[ p2 ][END] = { COUNTER : Counter(True), SCORE: Score() }
p1_red_score = self.final_scores[ p1 ][ DiceType.RED ]
p2_red_score = self.final_scores[ p2 ][ DiceType.RED ]
p1_green_score = self.final_scores[ p1 ][ DiceType.GREEN ]
p2_green_score = self.final_scores[ p2 ][ DiceType.GREEN ]
p1_begin_red_score = self.initial_scores[ p1 ][ DiceType.RED ]
p2_begin_red_score = self.initial_scores[ p2 ][ DiceType.RED ]
p1_begin_green_score = self.initial_scores[ p1 ][ DiceType.GREEN ]
p2_begin_green_score = self.initial_scores[ p2 ][ DiceType.GREEN ]
self.p1_damage = [0]
self.p2_damage = [0]
self.damage_hash = { p1: self.p1_damage, p2 : self.p2_damage }
for ats in self.attack_sets:
ats.score(self.stats )
if ats.attacking_player.name == p1:
self.p1_damage.append( ats.num_net_hits() +ats.net_crits + self.p1_damage[-1])
self.p2_damage.append( self.p2_damage[-1] )
p1_red_score.append( ats.cumulative_attack_end_luck )
p1_begin_red_score.append( ats.cumulative_attack_begin_luck )
p1_green_score.append( p1_green_score[-1])
p1_begin_green_score.append( p1_begin_green_score[-1])
p2_red_score.append( p2_red_score[-1])
p2_begin_red_score.append( p2_begin_red_score[-1])
if ats.cumulative_defense_end_luck is not None:
p2_green_score.append( ats.cumulative_defense_end_luck )
else:
p2_green_score.append( p2_green_score[-1])
if ats.cumulative_defense_begin_luck is not None:
p2_begin_green_score.append( ats.cumulative_defense_begin_luck )
else:
p2_begin_green_score.append( p2_begin_green_score[-1])
else: #p2 is the attacking player
self.p2_damage.append( ats.num_net_hits() +ats.net_crits + self.p2_damage[-1])
self.p1_damage.append( self.p1_damage[-1] )
p2_red_score.append( ats.cumulative_attack_end_luck )
p2_begin_red_score.append( ats.cumulative_attack_begin_luck )
p2_green_score.append( p2_green_score[-1])
p2_begin_green_score.append( p2_begin_green_score[-1])
p1_red_score.append( p1_red_score[-1])
p1_begin_red_score.append( p1_begin_red_score[-1])
if ats.cumulative_defense_end_luck is not None:
p1_green_score.append( ats.cumulative_defense_end_luck )
else:
p2_green_score.append( p2_green_score[-1])
if ats.cumulative_defense_begin_luck is not None:
p1_begin_green_score.append( ats.cumulative_defense_begin_luck )
else:
p2_begin_green_score.append( p2_begin_green_score[-1])
def final_red_scores(self, player):
return self.final_scores[ player.name][DiceType.RED]
def final_green_scores(self, player):
return self.final_scores[ player.name][DiceType.GREEN]
def initial_red_scores(self, player):
return self.initial_scores[ player.name][DiceType.RED]
def initial_green_scores(self, player):
return self.initial_scores[ player.name][DiceType.GREEN]
def get_attack_set(self, attack_set_num):
for aset in self.attack_sets:
if aset.number == attack_set_num:
return aset
return None
def initial_player_score(self, player):
return self.stats[player][INITIAL][SCORE]
def initial_player_counter(self, player):
return self.stats[player.name][INITIAL][COUNTER]
def unmodified_attack_data(self, player):
return self.initial_player_score(player).red_luck
def total_reds(self, player):
return self.initial_player_counter(player).total_reds
#total helper methods methods
def crits_added(self,player):
return self.initial_player_counter(player).red_crits_added
def hits_added(self,player):
return self.initial_player_counter(player).red_hits_added
def total_green_evades_added(self, player):
return self.initial_player_counter(player).green_evades_added
def unmodified_hits(self, player):
return self.initial_player_counter(player).red_hits
def total_reds_after_rerolls(self, player):
return self.initial_player_counter(player).total_reds_after_rerolls()
def total_greens_after_rerolls(self, player):
return self.initial_player_counter(player).total_greens_after_rerolls()
def total_red_hits_after_rerolls(self, player):
return self.initial_player_counter(player).total_red_hits_after_rerolls()
def total_red_hits_after_converts(self, player):
return self.initial_player_counter(player).total_red_hits_after_converts()
def total_green_evades_after_converts(self, player):
return self.initial_player_counter(player).total_green_evades_after_converts()
def total_red_crits_after_rerolls(self, player):
return self.initial_player_counter(player).total_red_crits_after_rerolls()
def total_red_crits_after_converts(self, player):
return self.initial_player_counter(player).total_red_crits_after_converts()
def total_red_focuses_after_rerolls(self, player):
return self.initial_player_counter(player).total_red_focuses_after_rerolls()
def expected_green_focuses_after_rerolls(self, player):
return self.initial_player_counter(player).expected_green_focuses_after_rerolls()
def total_red_blanks_after_rerolls(self, player):
return self.initial_player_counter(player).total_red_blanks_after_rerolls()
def total_green_evades_after_rerolls(self, player):
return self.initial_player_counter(player).total_green_evades_after_rerolls()
def total_red_focuses_after_converts(self, player):
return self.initial_player_counter(player).total_red_focuses_after_converts()
def total_red_blanks_after_converts(self, player):
return self.initial_player_counter(player).total_red_blanks_after_converts()
def expected_hits_after_rerolls(self, player):
return self.initial_player_counter(player).expected_hits_after_rerolls()
def expected_crits_after_rerolls(self, player):
return self.initial_player_counter(player).expected_crits_after_rerolls()
def expected_crits_after_converts(self, player):
return self.initial_player_counter(player).expected_crits_after_rerolls() #converts implies no rerolls
def expected_hits_after_converts(self, player):
#its the same name as the re-rolls, since no new dice have been thrown
return self.expected_hits_after_rerolls(player)
def expected_focuses_after_rerolls(self, player):
return self.initial_player_counter(player).expected_focuses_after_rerolls()
def expected_blanks_after_rerolls(self, player):
return self.initial_player_counter(player).expected_blanks_after_rerolls()
def expected_blanks_after_converts(self, player):
return self.expected_blanks_after_rerolls(player) #count doesn't change
def expected_focuses_after_converts(self, player):
return self.expected_focuses_after_rerolls(player) #thecount doesn't go up, so can piggy back
def expected_green_focuses_after_converts(self, player):
return self.expected_green_focuses_after_rerolls(player) #thecount doesn't go up, so can piggy back
def expected_green_blanks_after_converts(self, player):
return self.expected_green_blanks_after_rerolls(player)
def expected_green_evades_after_converts(self, player):
return self.expected_green_evades_after_rerolls(player)
def total_greens(self, player):
return self.initial_player_counter(player).total_greens
def total_green_focuses_after_rerolls(self, player):
return self.initial_player_counter(player).total_green_focuses_after_rerolls()
def total_green_focuses_after_converts(self, player):
return self.initial_player_counter(player).total_green_focuses_after_converts()
def total_green_blanks_after_rerolls(self, player):
return self.initial_player_counter(player).total_green_blanks_after_rerolls()
def total_green_blanks_after_converts(self, player):
return self.initial_player_counter(player).total_green_blanks_after_converts()
def expected_unmodified_hits(self, player):
return self.initial_player_counter(player).expected_red_hits()
def unmodified_evades(self, player):
return self.initial_player_counter(player).green_evades
def expected_unmodified_evades(self, player):
return self.initial_player_counter(player).expected_green_evades()
def expected_green_evades_after_rerolls(self, player):
return self.initial_player_counter(player).expected_green_evades_after_rerolls()
def unmodified_crits(self, player):
return self.initial_player_counter(player).red_crits
def expected_unmodified_focuses(self, player):
return self.initial_player_counter(player).expected_red_eyes()
def unmodified_focuses(self, player):
return self.initial_player_counter(player).red_eyes
def expected_unmodified_green_focuses(self, player):
return self.initial_player_counter(player).expected_green_eyes()
def unmodified_green_focuses(self, player):
return self.initial_player_counter(player).green_eyes
def expected_unmodified_blanks(self, player):
return self.initial_player_counter(player).expected_red_blanks()
def unmodified_blanks(self, player):
return self.initial_player_counter(player).red_blanks
def expected_unmodified_green_blanks(self, player):
return self.initial_player_counter(player).expected_green_blanks()
def expected_green_blanks_after_rerolls(self, player):
return self.initial_player_counter(player).expected_green_blanks_after_rerolls()
def unmodified_green_blanks(self, player):
return self.initial_player_counter(player).green_blanks
def expected_unmodified_crits(self, player):
return self.initial_player_counter(player).expected_red_crits()
class GameTapeTester(unittest.TestCase):
def setUp(self):
self.parser = LogFileParser(None)
self.parser.read_input_from_file("../logfiles/fsm_test_input.txt")
self.parser.run_finite_state_machine()
self.game_tape = self.parser.game_tape
self.g = Game(None,self.parser.get_players())
for throw_result in self.game_tape:
self.g.game_throws.append(throw_result)
self.tape = GameTape( self.g )
self.tape.score()
def testDamage(self):
p1 = self.g.game_players[0]
p2 = self.g.game_players[1]
p1_damage = self.g.game_tape.damage( p1 )
p2_damage = self.g.game_tape.damage( p2 )
self.assertEqual( 0, p1_damage[0])
self.assertEqual( 0, p1_damage[1])
self.assertEqual( 1, p1_damage[2])
self.assertEqual( 1, p1_damage[3])
self.assertEqual( 1, p1_damage[4])
self.assertEqual( 0, p2_damage[0])
self.assertEqual( 0, p2_damage[1])
self.assertEqual( 0, p2_damage[2])
self.assertEqual( 0, p2_damage[3])
self.assertEqual( 0, p2_damage[4])
def testCumulativeStats(self):
p1 = self.g.game_players[0]
p2 = self.g.game_players[1]
self.assertEqual( 4, self.g.total_reds( p1) )
self.assertEqual( 3, self.g.total_reds( p2) )
p1_init_reds = self.g.game_tape.initial_red_scores(p1)
self.assertEqual( 5, len(p1_init_reds))
self.assertEqual( 0, p1_init_reds[0])
self.assertEqual( -0.8125, p1_init_reds[1])
self.assertEqual( 0.125, p1_init_reds[2])
self.assertEqual( 0.125, p1_init_reds[3])
self.assertEqual( 0.125, p1_init_reds[4])
p1_reds = self.g.game_tape.final_red_scores( p1 )
self.assertEqual( 5, len(p1_reds))
self.assertEqual( 0, p1_reds[0])
self.assertEqual( -0.3125, p1_reds[1])
self.assertEqual( 0.625, p1_reds[2])
self.assertEqual( 0.625, p1_reds[3])
self.assertEqual( 0.625, p1_reds[4])
p2_reds = self.g.game_tape.final_red_scores( p2 )
self.assertEqual( 5, len(p2_reds))
self.assertEqual( 0, p2_reds[0])
self.assertEqual( 0, p2_reds[1])
self.assertEqual( 0, p2_reds[2])
self.assertEqual( 0.9375, p2_reds[3])
self.assertEqual( 1.53125, p2_reds[4])
p1_greens = self.g.game_tape.final_green_scores( p1 )
self.assertEqual( 5, len(p1_greens))
self.assertEqual(0, p1_greens[0])
self.assertEqual(0, p1_greens[1])
self.assertEqual(0, p1_greens[2])
self.assertEqual(1.3125, p1_greens[3])
self.assertEqual(0.625, p1_greens[4])
p2_greens = self.g.game_tape.final_green_scores( p2 )
print(p2_greens)
self.assertEqual( 5, len(p2_greens))
self.assertEqual( 0, p2_greens[0])
self.assertEqual( 0.3125, p2_greens[1])
self.assertEqual( 0.75, p2_greens[2])
self.assertEqual( 0.75, p2_greens[3])
self.assertEqual( 0.75, p2_greens[4])
def testRawSummaryStats(self):
p1 = self.g.game_players[0]
p2 = self.g.game_players[1]
#HITS
#totals first
self.assertEqual( 4, self.g.total_reds( p1) )
self.assertEqual( 3, self.g.total_reds( p2) )
#p1, initial rolls
self.assertEqual( 1, self.g.unmodified_hits( p1 ) )
self.assertEqual( (3.0/8.0) * 4 , self.g.expected_unmodified_hits( p1 ) )
#p2, initial roles
self.assertEqual( 0, self.g.unmodified_hits( p2 ) )
self.assertEqual( (3.0/8.0) * 3 , self.g.expected_unmodified_hits( p2 ) )
#p1, after rerolls
self.assertEqual( 1, self.g.total_red_hits_after_rerolls( p1 ) )
self.assertEqual( 1.5, self.g.expected_hits_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 1, self.g.total_red_hits_after_rerolls( p2 ) )
self.assertEqual( (3.0/8.0) * 5, self.g.expected_hits_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 2, self.g.total_red_hits_after_converts( p1 ) )
self.assertEqual( 1.5, self.g.expected_hits_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 1, self.g.total_red_hits_after_converts( p2 ) )
self.assertEqual( (3.0/8.0) * 5, self.g.expected_hits_after_converts ( p2 ))
#CRITS
#p1, initial rolls
self.assertEqual( 1, self.g.unmodified_crits( p1 ) )
self.assertEqual( (1.0/8.0) * 4 , self.g.expected_unmodified_crits( p1 ) )
#p2, initial roles
self.assertEqual( 1, self.g.unmodified_crits( p2 ) )
self.assertEqual( (1.0/8.0) * 3 , self.g.expected_unmodified_crits( p2 ) )
#p1, after rerolls
self.assertEqual( 1, self.g.total_red_crits_after_rerolls( p1 ) )
self.assertEqual( .5, self.g.expected_crits_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 1, self.g.total_red_crits_after_rerolls( p2 ) )
self.assertEqual( (1.0/8.0) * 5, self.g.expected_crits_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 1, self.g.total_red_crits_after_converts( p1 ) )
self.assertEqual( .5, self.g.expected_crits_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 2, self.g.total_red_crits_after_converts( p2 ) )
self.assertEqual( (1.0/8.0) * 5, self.g.expected_crits_after_converts ( p2 ))
#RED FOCUS
#p1, initial rolls
self.assertEqual( 1, self.g.unmodified_focuses( p1 ) )
self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_focuses( p1 ) )
#p2, initial roles
self.assertEqual( 0, self.g.unmodified_focuses( p2 ) )
self.assertEqual( (2.0/8.0) * 3 , self.g.expected_unmodified_focuses( p2 ) )
#p1, after rerolls
self.assertEqual( 1, self.g.total_red_focuses_after_rerolls( p1 ) )
self.assertEqual( 4 * (2.0/8.0), self.g.expected_focuses_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 1, self.g.total_red_focuses_after_rerolls( p2 ) )
self.assertEqual( (2.0/8.0) * 5, self.g.expected_focuses_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 0, self.g.total_red_focuses_after_converts( p1 ) )
self.assertEqual( (2.0/8.0) * 4, self.g.expected_focuses_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 0, self.g.total_red_focuses_after_converts( p2 ) )
self.assertEqual( (2.0/8.0) * 5, self.g.expected_focuses_after_converts ( p2 ))
#RED BLANK
#p1, initial blank rolls
self.assertEqual( 1, self.g.unmodified_blanks( p1 ) )
self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_blanks( p1 ) )
#p2, initial blank rolls
self.assertEqual( 2, self.g.unmodified_blanks( p2 ) )
self.assertEqual( (2.0/8.0) * 3 , self.g.expected_unmodified_focuses( p2 ) )
#p1, blanks after rerolls
self.assertEqual( 1, self.g.total_red_blanks_after_rerolls( p1 ) )
self.assertEqual( 4 * (2.0/8.0), self.g.expected_blanks_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 2, self.g.total_red_blanks_after_rerolls( p2 ) )
self.assertEqual( (2.0/8.0) * 5, self.g.expected_blanks_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 1, self.g.total_red_blanks_after_converts( p1 ) )
self.assertEqual( (2.0/8.0) * 4, self.g.expected_blanks_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 2, self.g.total_red_blanks_after_converts( p2 ) )
self.assertEqual( (2.0/8.0) * 5, self.g.expected_blanks_after_converts ( p2 ))
#green dice
self.assertEqual( 6, self.g.total_greens(p1))
self.assertEqual( 4, self.g.total_greens(p2))
#EVADES
self.assertEqual( 0, self.g.unmodified_evades(p1))
self.assertEqual( (3.0/8.0) * 6, self.g.expected_unmodified_evades(p1))
self.assertEqual( 2, self.g.unmodified_evades(p2))
self.assertEqual( (3.0/8.0) * 4, self.g.expected_unmodified_evades(p2))
#p1, after rerolls
self.assertEqual( 0, self.g.total_green_evades_after_rerolls( p1 ) )
self.assertEqual( (3.0/8.0) * 7, self.g.expected_green_evades_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 2, self.g.total_green_evades_after_rerolls( p2 ) )
self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_evades_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 4, self.g.total_green_evades_after_converts( p1 ) )
self.assertEqual( (3.0/8.0) * 7 , self.g.expected_green_evades_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 3, self.g.total_green_evades_after_converts( p2 ) )
self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_evades_after_converts ( p2 ))
#GREEN FOCUSES
self.assertEqual( 3, self.g.unmodified_green_focuses( p1 ) )
self.assertEqual( (2.0/8.0) * 6 , self.g.expected_unmodified_green_focuses( p1 ) )
#p2, initial roles
self.assertEqual( 1, self.g.unmodified_green_focuses( p2 ) )
self.assertEqual( (2.0/8.0) * 4 , self.g.expected_unmodified_green_focuses( p2 ) )
#p1, after rerolls
self.assertEqual( 4, self.g.total_green_focuses_after_rerolls( p1 ) )
self.assertEqual( 7 * (2.0/8.0), self.g.expected_green_focuses_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 1, self.g.total_green_focuses_after_rerolls( p2 ) )
self.assertEqual( (2.0/8.0) * 4, self.g.expected_green_focuses_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 0, self.g.total_green_focuses_after_converts( p1 ) )
self.assertEqual( (2.0/8.0) * 7, self.g.expected_green_focuses_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 0, self.g.total_green_focuses_after_converts( p2 ) )
self.assertEqual( (2.0/8.0) * 4, self.g.expected_green_focuses_after_converts ( p2 ))
#GREEN BLANKS
self.assertEqual( 3, self.g.unmodified_green_blanks( p1 ) )
self.assertEqual( (3.0/8.0) * 6 , self.g.expected_unmodified_green_blanks( p1 ) )
#p2, initial roles
self.assertEqual( 1, self.g.unmodified_green_blanks( p2 ) )
self.assertEqual( (3.0/8.0) * 4 , self.g.expected_unmodified_green_blanks( p2 ) )
#p1, after rerolls
self.assertEqual( 3, self.g.total_green_blanks_after_rerolls( p1 ) )
self.assertEqual( 7 * (3.0/8.0), self.g.expected_green_blanks_after_rerolls( p1 ))
#p2, after rerolls
self.assertEqual( 1, self.g.total_green_blanks_after_rerolls( p2 ) )
self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_blanks_after_rerolls( p2 ))
#p1, after converts
self.assertEqual( 3, self.g.total_green_blanks_after_converts( p1 ) )
self.assertEqual( (3.0/8.0) * 7, self.g.expected_green_blanks_after_converts ( p1 ))
#p2, after converts
self.assertEqual( 1, self.g.total_green_blanks_after_converts( p2 ) )
self.assertEqual( (3.0/8.0) * 4, self.g.expected_green_blanks_after_converts ( p2 ))
def testAttackSetStats(self):
self.assertEqual( 4, len(self.tape.attack_sets) )
aset = self.tape.attack_sets[0]
self.assertEqual( -.3125, aset.total_attack_end_luck() )
self.assertEqual( .3125, aset.total_defense_end_luck() )
aset = self.tape.attack_sets[1]
self.assertEqual( .9375, aset.total_attack_end_luck() )
self.assertEqual( 0.4375, aset.total_defense_end_luck() )
aset = self.tape.attack_sets[2]
self.assertEqual( 0.9375, aset.total_attack_end_luck() )
self.assertEqual( 1.3125, aset.total_defense_end_luck() )
aset = self.tape.attack_sets[3]
self.assertEqual( 0.59375, aset.total_attack_end_luck() )
self.assertEqual( -0.6875, aset.total_defense_end_luck() )
if __name__ == "__main__":
unittest.main()