forked from rspeer/dominionstats
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_parse_game.py
1263 lines (1100 loc) · 72.1 KB
/
test_parse_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError, e:
import unittest
import parse_game
import pprint
DEF_NAME_LIST = ['p' + str(x) for x in range(15)]
class CaptureCardsTest(unittest.TestCase):
def test_capture_cards(self):
captured = parse_game.capture_cards(
'player0 plays 3 <span class=card-treasure>Coppers</span>.')
self.assertEquals(captured, ['Copper'] * 3)
captured = parse_game.capture_cards(
'... ... and plays the <span class=card-none>Throne Room</span> '
'again.')
self.assertEquals(captured, ['Throne Room'])
captured = parse_game.capture_cards(
'... player0 gains the '
'<span class=card-reaction>Watchtower</span>.')
self.assertEquals(captured, ['Watchtower'])
captured = parse_game.capture_cards(
'... player1 gains a <span class=card-treasure>Copper</span> '
'and a <span class=card-curse>Curse</span>')
self.assertEquals(captured, ['Copper', 'Curse'])
captured = parse_game.capture_cards(
'player1 plays a <span class=card-treasure>Platinum</span>, '
'3 <span class=card-treasure>Golds</span>, and a '
'<span class=card-treasure>Copper</span>.')
self.assertEquals(captured, ['Platinum', 'Gold', 'Gold', 'Gold',
'Copper'])
captured = parse_game.capture_cards(
'cards in supply: <span cardname="Black Market" '
'class=card-none>Black Market</span>, '
'<span cardname="Caravan" class=card-duration>Caravan</span>')
self.assertEquals(captured, ['Black Market', 'Caravan'])
captured = parse_game.capture_cards(
'player0 plays a <span class=card-none>Coppersmith</span>.')
self.assertEquals(captured, ['Coppersmith'])
captured = parse_game.capture_cards(
'player4 buys an <span class=card-none>Expand</span>')
self.assertEquals(captured, ['Expand'])
def test_bane(self):
captured = parse_game.capture_cards(
'<span cardname="Chapel" class=card-none>Chapel</span>, <span cardname="Moat" class=card-reaction>Moat</span><span class=bane-star>♦</span>,')
self.assertEquals(captured, ['Chapel', 'Moat'])
class DeleteKeysTest(unittest.TestCase):
def test_delete_keys_with_empty_vals(self):
d1 = {'p6': {}}
parse_game.delete_keys_with_empty_vals(d1)
self.assertEquals(d1, {})
def test_ultimately_empty_nested_dict(self):
d2 = {'p1': {'opp': {}}}
parse_game.delete_keys_with_empty_vals(d2)
self.assertEquals(d2, {})
class PlayerTrackerTest(unittest.TestCase):
def setUp(self):
self.tracker = parse_game.PlayerTracker()
def test_simple_tracking(self):
self.assertEquals(0, self.tracker.get_active_player(
'player0 plays 3 <span class=card-treasure>Coppers</span>.'))
self.assertEquals(self.tracker.current_player(), 0)
self.assertEquals(0, self.tracker.get_active_player(
'player0 buys a <span class=card-treasure>Silver</span>.'))
def test_complicated_tracking(self):
line_output_list = [
('player1 plays a <span class=card-none>Throne Room</span>.', 1),
('... and plays a <span class=card-none>Bureaucrat</span>.,', 1),
('... ... gaining a <span class=card-treasure>Silver</span> and putting it on the deck.', 1),
('... ... player2 puts an <span class=card-victory>Estate</span> back on the deck.', 2),
('... and plays the <span class=card-none>Bureaucrat</span> again.', 1),
('... ... gaining a <span class=card-treasure>Silver</span> and putting it on the deck.', 1),
('... ... player2 reveals 4 <span class=card-treasure>Golds</span>.', 2)]
for line, expected_output in line_output_list:
self.assertEquals(self.tracker.get_active_player(line),
expected_output, line)
self.assertEquals(self.tracker.current_player(), 1)
class ParseTurnHeaderTest(unittest.TestCase):
def test_normal_turn(self):
parsed_turn_header = parse_game.parse_turn_header(
"--- player0's turn 3 ---", DEF_NAME_LIST)
self.assertEquals(parsed_turn_header['name'], 'p0')
self.assertEquals(parsed_turn_header['turn_no'], 3)
def test_possesion_turn(self):
parsed_turn_header = parse_game.parse_turn_header(
"--- player0's turn (possessed by player1) ---", DEF_NAME_LIST)
self.assertEquals(parsed_turn_header['name'], 'p0')
self.assertEquals(parsed_turn_header['pname'], 'p1')
def test_outpost_turn(self):
parsed_turn_header = parse_game.parse_turn_header(
"""--- player0's extra turn (from <span class=card-duration>Outpost</span>) ---""", DEF_NAME_LIST)
self.assertEquals(parsed_turn_header['name'], 'p0')
self.assertEquals(parsed_turn_header['outpost'], True)
def test_header_with_leading_space(self):
parsed_turn_header = parse_game.parse_turn_header(
" --- player0's turn 3 ---", DEF_NAME_LIST)
self.assertEquals(parsed_turn_header['name'], 'p0')
self.assertEquals(parsed_turn_header['turn_no'], 3)
class ParseTurnTest(unittest.TestCase):
def test_parse_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player0's turn 3 ---
player0 plays 3 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-treasure>Silver</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p0')
self.assertEquals(turn_info['plays'], ['Copper', 'Copper', 'Copper'])
self.assertEquals(turn_info['buys'], ['Silver'])
self.assertEquals(turn_info['money'], 3)
def test_chapel_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player5's turn 4 ---
player5 plays a <span class=card-none>Chapel</span>.
... trashing 2 <span class=card-treasure>Coppers</span>.
(player5 reshuffles.)""", DEF_NAME_LIST)
self.assertEquals(turn_info['plays'], ['Chapel'])
self.assertEquals(turn_info['trashes'], ['Copper', 'Copper'])
self.assertTrue('opp' not in turn_info)
def test_bishop_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player2's turn 7 ---
player2 plays a <span class=card-none>Bishop</span>.
... getting +$1 and +1 ▼.
... player2 trashes a <span class=card-treasure>Copper</span>.
... player3 trashes a <span class=card-treasure>Copper</span>.
player2 plays 3 <span class=card-treasure>Coppers</span>.
player2 buys a <span class=card-treasure>Silver</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['plays'], ['Bishop', 'Copper',
'Copper', 'Copper'])
self.assertEquals(turn_info['trashes'], ['Copper'])
self.assertEquals(turn_info['vp_tokens'], 1)
self.assertEquals(turn_info['money'], 4)
def test_bishop_turn2(self):
turn_info = parse_game.parse_turn(
u"""--- player3's turn 3 ---
player3 plays a <span class=card-none>Bishop</span>.
... getting +$1 and +1 ▼.
... player3 trashes an <span class=card-victory>Estate</span> and gets +1 ▼.
... player6 trashes nothing.
player3 plays 3 <span class=card-treasure>Coppers</span>.
player3 buys a <span class=card-none>Throne Room</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['trashes'], ['Estate'])
self.assertTrue('opp' not in turn_info)
self.assertEquals(turn_info['vp_tokens'], 2)
self.assertEquals(turn_info['money'], 4)
def test_bishop_turn3(self):
turn_info = parse_game.parse_turn(
u""" --- player6's turn 4 ---
player6 plays a <span class=card-none>Bishop</span>.
... getting +$1 and +1 ▼.
... player6 trashes an <span class=card-victory>Estate</span> and gets +1 ▼.
... player3 trashes a <span class=card-treasure>Copper</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['vp_tokens'], 2)
self.assertEquals(turn_info['trashes'], ['Estate'])
self.assertEquals(turn_info['opp']['p3']['trashes'], ['Copper'])
self.assertEquals(turn_info['money'], 1)
def test_trader_gain_silver_instead_of_buy(self):
turn_info = parse_game.parse_turn(
u"""--- player1's turn 8 ---
player1 plays a <span class=card-duration>Lighthouse</span>.
... getting +1 action and +$1.
player1 plays 3 <span class=card-treasure>Coppers</span>.
player1 buys a <span class=card-victory>Gardens</span>.
... player1 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... player1 gains a <span class=card-treasure>Silver</span>.,.
""",
DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Silver'])
self.assertFalse('buys' in turn_info, 'should not be here: ' +
str(turn_info.get('buys', [])))
def test_trader_gain_silver_instead_of_gain(self):
turn_info = parse_game.parse_turn(
u"""--- player1's turn 11 ---</a>
player1 plays a <span class=card-none>Torturer</span>.
... drawing 3 cards.
... player2 gains a <span class=card-curse>Curse</span> in hand.
... ... player2 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... ... player2 gains a <span class=card-treasure>Silver</span>.
player1 plays 2 <span class=card-treasure>Silvers</span> and a <span class=card-treasure>Copper</span>.
player1 buys an <span class=card-none>Upgrade</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['gains'], ['Silver'])
def test_mine_upgrade_turn(self):
turn_info = parse_game.parse_turn(u"""--- player3's turn 12 ---
player3 plays a <span class=card-none>Mine</span>.
... trashing a <span class=card-treasure>Talisman</span> and gaining a <span class=card-treasure>Gold</span>.
player3 plays a <span class=card-treasure>Gold</span>, a <span class=card-treasure>Royal Seal</span>, and a <span class=card-treasure>Copper</span>.
player3 buys a <span class=card-treasure>Gold</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Gold'])
self.assertEquals(turn_info['buys'], ['Gold'])
self.assertEquals(turn_info['trashes'], ['Talisman'])
self.assertEquals(turn_info['money'], 6)
def test_ambassador_turn(self):
turn_info = parse_game.parse_turn(
u""" --- player8's turn 3 ---
player8 plays an <span class=card-none>Ambassador</span>.
... player8 reveals an <span class=card-victory>Estate</span>.
... returning 2 copies to the supply.
... player9 gains an <span class=card-victory>Estate</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p8')
self.assertEquals(turn_info['plays'], ['Ambassador'])
self.assertEquals(turn_info['returns'], ['Estate', 'Estate'])
self.assertEquals(turn_info['opp']['p9']['gains'],
['Estate'])
def test_ambassador_secret_chamber_response_turn(self):
input_str = u""" --- player0's turn 16 ---
player0 plays an <span class=card-none>Ambassador</span>.
... player1 reveals a <span class=card-reaction>Secret Chamber</span>.
... ... drawing 2 cards.
... ... returning 2 cards to the deck.
... player0 reveals a <span class=card-treasure>Copper</span>.
... returning 2 copies to the supply.
... player1 gains a <span class=card-treasure>Copper</span>."""
turn_info = parse_game.parse_turn(input_str, DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p0')
self.assertEquals(turn_info['plays'], ['Ambassador'])
self.assertEquals(turn_info['returns'], ['Copper', 'Copper'])
self.assertEquals(turn_info['opp']['p1']['gains'], ['Copper'])
def test_ambassador3(self):
turn_info = parse_game.parse_turn(
""" --- player0's turn 6 ---
player0 plays an <span class=card-none>Ambassador</span>.
... player0 reveals a <span class=card-treasure>Copper</span>.
... returning it to the supply.
... player1 gains a <span class=card-treasure>Copper</span>.""",
['f', 't'])
self.assertEquals(turn_info['returns'], ['Copper'])
self.assertEquals(turn_info['opp']['t']['gains'], ['Copper'])
def test_ambassador4(self):
turn_info = parse_game.parse_turn(
"""--- player0's turn 4 ---
player0 plays an <span class=card-none>Ambassador</span>.
... revealing 2 <span class=card-treasure>Coppers</span> and returning them to the supply.
... player1 gains a <span class=card-treasure>Copper</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['returns'], ['Copper', 'Copper'])
def test_ambassador5(self):
turn_info = parse_game.parse_turn("""--- player3's turn 8 ---
player3 plays a <span class=card-none>Worker's Village</span>.
... drawing 1 card and getting +2 actions and +1 buy.
player3 plays an <span class=card-none>Ambassador</span>.
... revealing a <span class=card-treasure>Copper</span> and returning it to the supply.
... player0 gains a <span class=card-treasure>Copper</span>.
player3 plays an <span class=card-none>Ambassador</span>.
... revealing nothing and returning them to the supply.
... player0 gains a <span class=card-treasure>Copper</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['returns'], ['Copper'])
self.assertEquals(turn_info['opp']['p0']['gains'],
['Copper', 'Copper'])
def test_ambassador6(self):
turn_info = parse_game.parse_turn("""--- player0's turn 8 ---
player0 plays a <span class=card-none>Scout</span>.
... player0 reveals a <span class=card-treasure>Silver</span>, 2 <span class=card-treasure>Coppers</span>, and a <span class=card-none>Spy</span>.
... putting nothing into the hand.
... putting 4 cards back on the deck.
player0 plays an <span class=card-none>Ambassador</span>.
... revealing an <span class=card-victory>Estate</span> and returning it to the supply.
... player1 gains an <span class=card-victory>Estate</span>.
""", ['foo', 'bar'])
self.assertEquals(turn_info['opp']['bar']['gains'], ['Estate'])
def test_ambassador_moat(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 10 ---
player0 plays an <span class=card-none>Ambassador</span>.
... player1 reveals a <span class=card-reaction>Moat</span>.
... revealing 2 <span class=card-victory>Estates</span> and returning them to the supply.""", DEF_NAME_LIST)
self.assertEquals(turn_info['returns'], ['Estate', 'Estate'])
def test_swindler_watchtower(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 8 ---</a>
player0 plays a <span class=card-none>Swindler</span>.
... player1 turns up a <span class=card-none>Steward</span> and trashes it.
... replacing player1's <span class=card-none>Steward</span> with a <span class=card-reaction>Watchtower</span>.
... ... revealing a <span class=card-reaction>Watchtower</span>.
... ... trashing the <span class=card-reaction>Watchtower</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['gains'], ['Watchtower'])
self.assertEquals(turn_info['opp']['p1']['trashes'],
['Steward', 'Watchtower'])
def test_trading_post_turn(self):
turn_info = parse_game.parse_turn(
"""--- player1's turn 11 ---
player1 plays a <span class=card-none>Trading Post</span>.
... player1 trashes a <span class=card-treasure>Copper</span> and an <span class=card-victory>Estate</span>, gaining a <span class=card-treasure>Silver</span> in hand.
player1 plays a <span class=card-treasure>Copper</span> and a <span class=card-treasure>Silver</span>.
player1 buys a <span class=card-treasure>Silver</span>.
(player1 reshuffles.)
<span class=logonly>(player1 draws: 2 <span class=card-curse>Curses</span>, a <span class=card-treasure>Copper</span>, a <span class=card-none>Trading Post</span>, and a <span class=card-none>Laboratory</span>.)</span>""",
DEF_NAME_LIST)
self.assertEquals(turn_info['trashes'], ['Copper', 'Estate'])
self.assertEquals(turn_info['gains'], ['Silver'])
self.assertEquals(turn_info['money'], 3)
def test_sea_hag_turn(self):
turn_info = parse_game.parse_turn(
"""--- player0's turn 14 ---
player0 plays a <span class=card-none>Sea Hag</span>.
... player1 discards a <span class=card-none>Courtyard</span> and gains a <span class=card-curse>Curse</span> on top of the deck.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['gains'], ['Curse'])
def test_sea_hag_turn2(self):
turn_info = parse_game.parse_turn("""
--- player0's turn 6 ---
player0 plays a <span class=card-none>Sea Hag</span>.
... player1 discards nothing and gains a <span class=card-curse>Curse</span> on top of the deck.
player0 plays a <span class=card-treasure>Copper</span> and a <span class=card-treasure>Quarry</span>.
player0 buys a <span class=card-none>Cutpurse</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['gains'], ['Curse'])
self.assertEquals(turn_info['money'], 2)
def test_pirate_ship_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player8's turn 7 ---
player8 plays a <span class=card-none>Pirate Ship</span>.
... attacking the other players.
... (player11 reshuffles.)
... player11 reveals a <span class=card-duration>Wharf</span> and a <span class=card
-treasure>Copper</span>.
... player8 trashes player11's <span class=card-treasure>Copper</span>.
... player8 gains a <span class=card-none>Pirate Ship</span> token.
player8 plays 2 <span class=card-treasure>Coppers</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p8')
self.assertTrue('gains' not in turn_info)
self.assertEquals(turn_info['money'], 2)
self.assertTrue('opp' in turn_info, turn_info)
self.assertEquals(turn_info['opp']['p11']['trashes'], ['Copper'])
self.assertTrue('trashes' not in turn_info)
self.assertEquals(turn_info['ps_tokens'], 1)
def test_noble_brigand_trash(self):
turn_info = parse_game.parse_turn(
"""--- player1's turn 10 ---
player1 plays a <span class=card-none>Noble Brigand</span>.
... getting +$1.
... player2 draws and reveals a <span class=card-none>Ghost Ship</span> and a <span class=card-treasure>Silver</span>, trashing a <span class=card-treasure>Silver</span>.
... player2 discards a <span class=card-none>Ghost Ship</span>.
... player1 gains the <span class=card-treasure>Silver</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['trashes'], ['Silver'])
def test_noble_brigand_3_p_trash(self):
turn_info = parse_game.parse_turn(
"""--- player1's turn 9 ---
player1 plays a <span class=card-none>Noble Brigand</span>.
... getting +$1.
... player2 reveals and discards a <span class=card-treasure>Copper</span> and a <span class=card-none>Warehouse</span>.
... player3 draws and reveals a <span class=card-treasure>Copper</span> and a <span class=card-treasure>Gold</span>, trashing a <span class=card-treasure>Gold</span>.
... player3 discards a <span class=card-treasure>Copper</span>.
... player1 gains the <span class=card-treasure>Gold</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p3']['trashes'], ['Gold'])
def test_bank_turn(self):
turn_info = parse_game.parse_turn(u"""
--- player2's turn 10 ---
player2 plays a <span class=card-treasure>Silver</span>, 2 <span class=card-treasure>Coppers</span>, and a <span class=card-treasure>Gold</span>.
player2 plays a <span class=card-treasure>Bank</span>.
... which is worth +$5.
player2 buys a <span class=card-victory>Province</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['money'], 12)
def test_philospher_stone_turn(self):
turn_info = parse_game.parse_turn(u"""
--- player4's turn 15 ---
player4 plays a <span class=card-none>Laboratory</span>.
... drawing 2 cards and getting +1 action.
player4 plays a <span class=card-none>Laboratory</span>.
... drawing 2 cards and getting +1 action.
player4 plays a <span class=card-none>University</span>.
... getting +2 actions.
... gaining a <span class=card-none>Laboratory</span>.
player4 plays an <span class=card-none>Herbalist</span>.
... getting +1 buy and +$1.
player4 plays a <span class=card-treasure>Silver</span>.
player4 plays a <span class=card-treasure>Copper</span>.
player4 plays a <span class=card-treasure>Copper</span>.
player4 plays a <span class=card-treasure>Copper</span>.
player4 plays a <span class=card-treasure>Philosopher's Stone</span>.
... which is worth +$4 (6 cards in deck, 17 cards in discard).
player4 buys a <span class=card-none>Laboratory</span>.
player4 buys a <span class=card-none>Minion</span>.
player4 returns a <span class=card-treasure>Philosopher's Stone</span> to the top of the deck.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['money'], 10)
def test_gain_via_workshop_turn(self):
turn_info = parse_game.parse_turn(u"""
--- player0's turn 4 ---
player0 plays a <span class=card-none>Workshop</span>.
... gaining a <span class=card-none>Bridge</span>.
player0 plays 2 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-none>Pawn</span>.
(player0 reshuffles.)
""", DEF_NAME_LIST)
self.assertEquals(turn_info['plays'], ['Workshop', 'Copper', 'Copper'])
self.assertEquals(turn_info['gains'], ['Bridge'])
self.assertEquals(turn_info['buys'], ['Pawn'])
self.assertEquals(turn_info['money'], 2)
def test_golem_chapel_moat_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 9 ---
player0 plays a <span class=card-none>Golem</span>.
... revealing a <span class=card-none>Witch</span>, and a <span class=card-none>Chapel</span>.
... playing the <span class=card-none>Witch</span> first.
... ... drawing 2 cards.
... ... player1 reveals a <span class=card-reaction>Moat</span>.
... playing the <span class=card-none>Chapel</span> second.
... ... trashing an <span class=card-victory>Estate</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['plays'], ['Golem', 'Witch', 'Chapel'])
self.assertEquals(turn_info['trashes'], ['Estate'])
def test_throneroom_throneroom_pirateship_chapel_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 20 ---
player0 plays a <span class=card-none>Throne Room</span>.
... and plays a <span class=card-none>Throne Room</span>.
... ... and plays a <span class=card-none>Pirate Ship</span>.
... ... ... attacking the other players.
... ... ... player1 reveals a <span class=card-victory>Province</span> and an <span class=card-victory>Estate</span>.
... ... and plays the <span class=card-none>Pirate Ship</span> again.
... ... ... attacking the other players.
... ... ... player1 reveals a <span class=card-none>Pirate Ship</span> and a <span class=card-none>Chapel</span>.
... and plays the <span class=card-none>Throne Room</span> again.
... ... and plays a <span class=card-none>Chapel</span>.
... ... ... trashing a <span class=card-victory>Gardens</span>.
... ... and plays the <span class=card-none>Chapel</span> again.
... ... ... trashing nothing.""", DEF_NAME_LIST)
self.assertEquals(turn_info['trashes'], ['Gardens'])
def test_throne_room_beaurcrat_turn(self):
turn_info = parse_game.parse_turn(u"""--- player1's turn 13 ---
player1 plays a <span class=card-none>Throne Room</span>.
... and plays a <span class=card-none>Bureaucrat</span>.
... ... gaining a <span class=card-treasure>Silver</span> and putting it on the deck.
... ... player2 puts an <span class=card-victory>Estate</span> back on the deck.
... and plays the <span class=card-none>Bureaucrat</span> again.
... ... gaining a <span class=card-treasure>Silver</span> and putting it on the deck.
... ... player2 reveals 4 <span class=card-treasure>Golds</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Silver', 'Silver'])
self.assertTrue(not 'opp' in turn_info, turn_info)
def test_witch_turn(self):
turn_info = parse_game.parse_turn(u"""
--- player0's turn 5 ---
player0 plays a <span class=card-none>Witch</span>.
... drawing 2 cards.
... player1 gains a <span class=card-curse>Curse</span>.
player0 plays 2 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-duration>Lighthouse</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['plays'], ['Witch', 'Copper', 'Copper'])
self.assertTrue('gains' not in turn_info)
self.assertEquals(turn_info['opp']['p1']['gains'], ['Curse'])
self.assertEquals(turn_info['money'], 2)
def test_swindler_turn(self):
turn_info = parse_game.parse_turn(u"""--- player1's turn 9 ---
player1 plays a <span class=card-none>Swindler</span>.
... getting +$2.
... player2 turns up a <span class=card-treasure>Silver</span> and trashes it.
... replacing player2's <span class=card-treasure>Silver</span> with a <span class=card-none>Shanty Town</span>.
... player3 turns up a <span class=card-none>Shanty Town</span> and trashes it.
... replacing player3's <span class=card-none>Shanty Town</span> with a <span class=card-none>Shanty Town</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['gains'], ['Shanty Town'])
self.assertEquals(turn_info['opp']['p2']['trashes'], ['Silver'])
self.assertEquals(turn_info['opp']['p3']['gains'], ['Shanty Town'])
self.assertEquals(turn_info['opp']['p3']['trashes'], ['Shanty Town'])
def test_swindler_turn2(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 10 ---
player0 plays a <span class=card-none>Worker's Village</span>.
... drawing 1 card and getting +2 actions and +1 buy.
player0 plays a <span class=card-none>Swindler</span>.
... getting +$2.
... player1 turns up a <span class=card-treasure>Copper</span> and trashes it.
... replacing player1's <span class=card-treasure>Copper</span> with a <span class=card-curse>Curse</span>.
player0 plays a <span class=card-none>Swindler</span>.
... getting +$2.
... player1 turns up an <span class=card-victory>Estate</span> and trashes it.
... replacing player1's <span class=card-victory>Estate</span> with an <span class=card-victory>Estate</span>.
player0 plays 2 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-treasure>Gold</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['trashes'],
['Copper', 'Estate'])
self.assertEquals(turn_info['opp']['p1']['gains'],
['Curse', 'Estate'])
def test_watchtower_mountebank_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 18 ---
player0 plays a <span class=card-none>Throne Room</span>.
... and plays a <span class=card-none>Mountebank</span>.
... ... getting +$2.
... ... player1 gains a <span class=card-curse>Curse</span> and a <span class=card-treasure>Copper</span>.
... ... ... revealing a <span class=card-reaction>Watchtower</span> and trashing the <span class=card-curse>Curse</span>.
... ... ... revealing a <span class=card-reaction>Watchtower</span> and trashing the <span class=card-treasure>Copper</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['trashes'],
['Curse', 'Copper'], turn_info)
def test_mountebank_traders_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player1's turn 6 ---
player1 plays a <span class=card-none>Mountebank</span>.
... getting +$2.
... player2 gains a <span class=card-curse>Curse</span> and a <span class=card-treasure>Copper</span>.
... ... player2 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... ... player2 gains a <span class=card-treasure>Silver</span>.
... ... player2 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... ... player2 gains a <span class=card-treasure>Silver</span>.
player1 plays 2 <span class=card-treasure>Silvers</span> and 2 <span class=card-treasure>Coppers</span>.
player1 buys a <span class=card-treasure>Bank</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['gains'],
['Silver', 'Silver'], turn_info)
def test_mountebank_traders_turn2(self):
# this test is broken because it's an unfixed bug.
turn_info = parse_game.parse_turn(
u"""--- player1's turn 12 ---</a>
player1 plays a <span class=card-none>Mountebank</span>.
... getting +$2.
... player2 gains a <span class=card-curse>Curse</span> and a <span class=card-treasure>Copper</span>.
... ... player2 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... ... player2 gains a <span class=card-treasure>Silver</span>.
... ... ... player2 reveals a <span class=card-reaction>Trader</span> to gain a <span class=card-treasure>Silver</span> instead.
... ... ... player2 gains a <span class=card-treasure>Silver</span>.""",
DEF_NAME_LIST)
# p2 only turned the curse gain into a silver, but then just
# repeatedly spammed that silver -> silver, never cancelled the
# copper though.
# TODO: fix it if you want an adventure?
#self.assertEquals(turn_info['opp']['p2']['gains'],
# ['Copper', 'Silver'], turn_info['opp']['p2'])
# similiar bug in
# http://councilroom.com/game?game_id=game-20111017-112224-14cd96f7.html&debug=1#Mick_Swagger-show-turn-8
# with develop/trader interaction.
# similiar bug in
# councilroom.com/game?game_id=game-20111017-111832-61528d54.html&debug=1#ChickenSedan-show-turn-13
# with trader/multiple hoard interaction.
def test_watchtower_buy_curse_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 11 ---
player0 buys a <span class=card-curse>Curse</span>.
... revealing a <span class=card-reaction>Watchtower</span> and trashing the <span class=card-curse>Curse</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['buys'], ['Curse'])
self.assertEquals(turn_info['trashes'], ['Curse'])
def test_thief_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 10 ---
player0 plays a <span class=card-none>Thief</span>.
... player1 reveals a <span class=card-treasure>Silver</span> and an <span class=card-victory>Estate</span>.
... player0 trashes one of player1's <span class=card-treasure>Silvers</span>.
... player0 gains the trashed <span class=card-treasure>Silver</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p1']['trashes'], ['Silver'])
self.assertEquals(turn_info['gains'], ['Silver'])
def test_mint_turn(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 16 ---
player0 plays a <span class=card-none>Mint</span>.
... revealing a <span class=card-treasure>Platinum</span> and gaining another one.""", DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Platinum'])
def test_explorer_turn(self):
turn_info = parse_game.parse_turn(u"""--- player1's turn 19 ---
player1 plays an <span class=card-none>Explorer</span>.
... revealing a <span class=card-victory>Province</span> and gaining a <span class=card-treasure>Gold</span> in hand.""", DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Gold'])
def test_mining_village_money(self):
turn_info = parse_game.parse_turn(u"""--- player1's turn 9 ---
player1 plays a <span class=card-none>Mining Village</span>.
... (player1 reshuffles.)
... drawing 1 card and getting +2 actions.
... trashing the <span class=card-none>Mining Village</span> for +$2.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['money'], 2)
def test_fools_gold_reveal_turn(self):
turn_info = parse_game.parse_turn(
u""" --- player1's turn 10 ---
player1 buys a <span class=card-victory>Province</span>.
... player2 reveals a <span class=card-treasure-reaction>Fool's Gold</span>.
... ... trashing it.
... ... gaining a <span class=card-treasure>Gold</span> on the deck.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['trashes'], ["Fool's Gold"])
self.assertEquals(turn_info['opp']['p2']['gains'], ["Gold"])
def test_saboteur_turn(self):
turn_info = parse_game.parse_turn(u"""--- player2's turn 7 ---
player2 plays an <span class=card-none>Ironworks</span>.
... gaining an <span class=card-victory-action>Island</span>.
... (player2 reshuffles.)
... drawing 1 card and getting +1 action.
player2 plays a <span class=card-none>Saboteur</span>.
... player3 reveals an <span class=card-victory>Estate</span> and a <span class=card-treasure>Copper</span> and then a <span class=card-none>Baron</span>.
... The <span class=card-none>Baron</span> is trashed.
... player3 gains nothing to replace it.
... player9 reveals a <span class=card-none>Baron</span> and trashes it.
... player9 gains nothing to replace it.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p3']['trashes'], ['Baron'])
self.assertEquals(turn_info['opp']['p9']['trashes'], ['Baron'])
def test_saboteur_turn2(self):
turn_info = parse_game.parse_turn("""--- player9's turn 14 ---
player9 plays a <span class=card-none>Saboteur</span>.
... player2 reveals a <span class=card-none>Saboteur</span> and trashes it.
... player2 gains a <span class=card-treasure>Silver</span> to replace it.
... player3 reveals 3 <span class=card-treasure>Coppers</span> and then an <span class=card-victory-action>Island</span>.
... The <span class=card-victory-action>Island</span> is trashed.
... player3 gains nothing to replace it.
player9 plays a <span class=card-treasure>Silver</span> and 3 <span class=card-treasure>Coppers</span>.
player9 buys a <span class=card-none>Saboteur</span>.""", DEF_NAME_LIST)
self.assertEquals(turn_info['opp']['p2']['trashes'], ['Saboteur'])
self.assertEquals(turn_info['opp']['p2']['gains'], ['Silver'])
self.assertEquals(turn_info['opp']['p3']['trashes'], ['Island'])
def test_lookout_turn(self):
turn_info = parse_game.parse_turn("""--- player2's turn 9 ---
player2 plays a <span class=card-none>Lookout</span>.
... getting +1 action.
... (player2 reshuffles.)
... drawing 3 cards.
... trashing a <span class=card-treasure>Copper</span>.
... discarding a <span class=card-treasure>Copper</span>.
... putting a card back on the deck.""", DEF_NAME_LIST)
self.assertEquals(turn_info['trashes'], ['Copper'])
def test_coppersmith(self):
turn_info = parse_game.parse_turn(u"""--- player0's turn 3 ---
player0 plays a <span class=card-none>Coppersmith</span>.
... making each <span class=card-treasure>Copper</span> worth $2.
player0 plays a <span class=card-treasure>Silver</span> and 2 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-victory-action>Nobles</span>.
""", DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p0')
self.assertEquals(turn_info['plays'],
['Coppersmith', 'Silver', 'Copper', 'Copper'])
self.assertEquals(turn_info['money'], 6)
def test_UTF8_name(self):
turn_info = parse_game.parse_turn(u"""--- player1's turn 1 ---
player1 plays 3 <span class=card-treasure>Coppers</span>.
player1 buys a <span class=card-none>Workshop</span>.
""", ['', u'Görling'])
self.assertEquals(turn_info['name'], u'Görling')
self.assertEquals(turn_info['money'], 3)
def test_possessed_turn(self):
turn_info = parse_game.parse_turn(
u"""--- player0's turn (possessed by player1) ---
player0 plays a <span class=card-none>University</span>.
... gaining a <span class=card-none>Mint</span>.
... ... player1 gains the <span class=card-none>Mint</span>.
player0 plays a <span class=card-none>University</span>.
... gaining a <span class=card-none>Bazaar</span>.
... ... player1 gains the <span class=card-none>Bazaar</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p1')
self.assertEquals(turn_info['gains'], ['Mint', 'Bazaar'])
self.assertTrue(turn_info['poss'])
self.assertFalse('opp' in turn_info)
def test_possessed_turn2(self):
turn_info = parse_game.parse_turn(
u"""--- player0's turn (possessed by player1) ---
player0 plays a <span class=card-none>Remodel</span>.
... trashing a <span class=card-none>Mountebank</span>.
... gaining a <span class=card-treasure>Gold</span>.
... ... player1 gains the <span class=card-treasure>Gold</span>.
player0 plays 2 <span class=card-treasure>Silvers</span>.
player0 buys a <span class=card-none>Remodel</span>.
... player1 gains the <span class=card-none>Remodel</span>.
(player0 reshuffles.)
player0 discards the "trashed" card (a <span class=card-none>Mountebank</span>).""", DEF_NAME_LIST)
self.assertEquals(turn_info['name'], 'p1')
self.assertEquals(turn_info['gains'], ['Gold', 'Remodel'])
self.assertFalse('buys' in turn_info)
def test_possession_ambassador(self):
turn_info = parse_game.parse_turn(u"""
--- player0's turn (possessed by player1) ---</a>
player0 plays an <span class=card-none>Ambassador</span>.
... revealing 2 <span class=card-victory>Duchies</span> and returning them to the supply.
... player1 gains a <span class=card-victory>Duchy</span>.
player0 plays a <span class=card-treasure>Silver</span>.
player0 buys an <span class=card-victory>Estate</span>.
... player1 gains the <span class=card-victory>Estate</span>.""",
DEF_NAME_LIST)
self.assertEquals(turn_info['gains'], ['Duchy', 'Estate'])
self.assertEquals(turn_info['opp']['p0']['returns'], [
'Duchy', 'Duchy'])
class CanonicalizeNamesTest(unittest.TestCase):
def test_canonicalize_names(self):
replaced = parse_game.canonicalize_names(
"""--- Zor Prime's turn 1 ---
Zor Prime plays 3 <span class=card-treasure>Coppers</span>.""",
['Zor Prime'])
self.assertEquals(replaced,
"""--- player0's turn 1 ---
player0 plays 3 <span class=card-treasure>Coppers</span>.""")
def test_name_as_substring(self):
replaced = parse_game.canonicalize_names(
"""--- contain ed's turn 9 ---
contain ed plays a <span class=card-none>Swindler</span>.
... getting +$2.
... contain turns up a <span class=card-treasure>Silver</span> and trashes it.""", ['contain', 'contain ed'])
self.assertEquals(replaced,
"""--- player1's turn 9 ---
player1 plays a <span class=card-none>Swindler</span>.
... getting +$2.
... player0 turns up a <span class=card-treasure>Silver</span> and trashes it.""")
def test_evil_short_name(self):
replaced = parse_game.canonicalize_names(
""" --- d's turn 2 ---
d plays 3 <span class=card-treasure>Coppers</span>.
d buys a <span class=card-none>Masquerade</span>.
(d reshuffles.)""", ['d'])
self.assertEquals(replaced,
""" --- player0's turn 2 ---
player0 plays 3 <span class=card-treasure>Coppers</span>.
player0 buys a <span class=card-none>Masquerade</span>.
(player0 reshuffles.)""")
class SplitTurnsTest(unittest.TestCase):
def test_split_simple(self):
split_turns = parse_game.split_turns(
"""--- player1's turn 1 ---
Foo
--- player2's turn 2 ---
Bar""")
self.assertEquals(len(split_turns), 2)
self.assertEquals(split_turns[0], "--- player1's turn 1 ---\nFoo\n")
self.assertEquals(split_turns[1], "--- player2's turn 2 ---\nBar\n")
def test_possesion_split(self):
split_turns = parse_game.split_turns(
"""--- player0's turn (possessed by player1) ---
player0 plays an <span class=card-duration>Outpost</span>.
--- player2's turn 2 ---
Bar
--- player3's turn 1 ---
Ick""")
self.assertEquals(len(split_turns), 3)
self.assertEquals(split_turns[0],
"--- player0's turn (possessed by player1) ---\n"
"player0 plays an <span class=card-duration>Outpost</span>.\n")
def test_outpost_split(self):
split_turns = parse_game.split_turns(
"""--- player0's turn 1 ---
... foo
--- player0's extra turn (from <span class=card-duration>Outpost</span>) ---
bar""")
self.assertEquals(len(split_turns), 2)
def test_curious_split(self):
split_turns = parse_game.split_turns(
u"""--- player3's turn 1 ---
player3 plays 3 <span class=card-treasure>Coppers</span>.
player3 buys a <span class=card-treasure>Silver</span>.
<span class=logonly>(player3 draws: an <span class=card-victory>Estate</span> and 4 <span class=card-treasure>Coppers</span>.)</span>
--- player2's turn 1 ---
player2 plays 5 <span class=card-treasure>Coppers</span>.
player2 buys a <span class=card-none>Festival</span>.
<span class=logonly>(player2 draws: 3 <span class=card-victory>Estates</span> and 2 <span class=card-treasure>Coppers</span>.)</span>
--- player3's turn 2 ---
player3 plays 4 <span class=card-treasure>Coppers</span>.
player3 buys a <span class=card-treasure>Silver</span>.
(player3 reshuffles.)""")
self.assertEquals(len(split_turns), 3)
class ParseTurnsTest(unittest.TestCase):
def test_simple_input(self):
turns_info = parse_game.parse_turns(u"""--- player3's turn 1 ---
player3 plays 3 <span class=card-treasure>Coppers</span>.
player3 buys a <span class=card-treasure>Silver</span>.
<span class=logonly>(player3 draws: an <span class=card-victory>Estate</span> and 4 <span class=card-treasure>Coppers</span>.)</span>
--- player2's turn 1 ---
player2 plays 5 <span class=card-treasure>Coppers</span>.
player2 buys a <span class=card-none>Festival</span>.
<span class=logonly>(player2 draws: 3 <span class=card-victory>Estates</span> and 2 <span class=card-treasure>Coppers</span>.)</span>
--- player3's turn 2 ---
player3 plays 4 <span class=card-treasure>Coppers</span>.
player3 buys a <span class=card-treasure>Silver</span>.
(player3 reshuffles.)
""", DEF_NAME_LIST)
turn1Z = turns_info[0]
self.assertEquals(turn1Z['name'], 'p3')
self.assertEquals(turn1Z['plays'], ['Copper'] * 3)
self.assertEquals(turn1Z['buys'], ['Silver'])
turn1A = turns_info[1]
self.assertEquals(turn1A['name'], 'p2')
self.assertEquals(turn1A['plays'], ['Copper'] * 5)
self.assertEquals(turn1A['buys'], ['Festival'])
turn2Z = turns_info[2]
self.assertEquals(turn2Z['name'], 'p3')
self.assertEquals(turn2Z['plays'], ['Copper'] * 4)
self.assertEquals(turn2Z['buys'], ['Silver'])
def test_possesion_output_turns(self):
turns = parse_game.parse_turns(u"""--- player0's turn (possessed by player1) ---
player0 plays an <span class=card-duration>Outpost</span>.
player0 plays 3 <span class=card-treasure>Golds</span>.
player0 buys a <span class=card-treasure>Gold</span>.
... player1 gains the <span class=card-treasure>Gold</span>.
<span class=logonly>(player0 draws: a <span class=card-treasure>Gold</span>, a <span class=card-none>Village</span>, and an <span class=card-duration>Outpost</span>.)</span>
--- player0's extra turn (from <span class=card-duration>Outpost</span>) ---
player0 plays a <span class=card-none>Village</span>.
... (player0 reshuffles.)
... drawing 1 card and getting +2 actions.
player0 plays an <span class=card-duration>Outpost</span>.
player0 plays 2 <span class=card-treasure>Golds</span>.
player0 buys a <span class=card-treasure>Gold</span>.
<span class=logonly>(player0 draws: 2 <span class=card-treasure>Golds</span> and a <span class=card-none>Chapel</span>.)</span> """, DEF_NAME_LIST)
self.assertEquals(len(turns), 2)
self.assertTrue('outpost' in turns[1])
self.assertEqual(turns[1]['buys'], ['Gold'])
class ParseDeckTest(unittest.TestCase):
def test_deck(self):
parsed_deck = parse_game.parse_deck(u"""<b>Snead: 75 points</b> (7 <span class=card-victory>Colonies</span>, 2 <span class=card-victory-action>Islands</span>, and an <span class=card-victory>Estate</span>); 22 turns
opening: <span class=card-victory-action>Island</span> / <span class=card-treasure>Silver</span>
[15 cards] 2 <span class=card-victory-action>Islands</span>, 1 <span class=card-none>Chapel</span>, 1 <span class=card-duration>Tactician</span>, 1 <span class=card-treasure>Silver</span>, 2 <span class=card-treasure>Platinums</span>, 1 <span class=card-victory>Estate</span>, 7 <span class=card-victory>Colonies</span>""")
self.assertEquals(parsed_deck['name'], 'Snead')
self.assertEquals(parsed_deck['points'], 75)
self.assertEquals(parsed_deck['vp_tokens'], 0)
self.assertEquals(parsed_deck['deck'],
{'Island': 2,
'Chapel': 1,
'Tactician': 1,
'Silver': 1,
'Platinum': 2,
'Estate': 1,
'Colony': 7})
def test_deck_with_resign(self):
parsed_deck = parse_game.parse_deck(u"""<b>#1 kiwi</b>: resigned (1st); 13 turns
opening: <span class=card-none>Shanty Town</span> / <span class=card-none>Baron</span>
[23 cards] 8 <span class=card-none>Shanty Towns</span>, 5 <span class=card-none>Rabbles</span>, 2 <span class=card-none>Expands</span>, 1 <span class=card-none>Market</span>, 6 <span class=card-treasure>Coppers</span>, 1 <span class=card-victory>Estate</span> """)
self.assertEquals(parsed_deck['resigned'], True)
def test_20101213_style_deck(self):
parsed_deck = parse_game.parse_deck(u"""<b>#1 zorkkorz</b>: 43 points (4 <span class=card-victory>Provinces</span>, 3 <span class=card-victory>Duchies</span>, 2 <span class=card-victory>Dukes</span>, and 2 <span class=card-victory-treasure>Harems</span>); 21 turns
opening: <span class=card-none>Upgrade</span> / <span class=card-duration>Lighthouse</span>
[25 cards] 2 <span class=card-victory>Dukes</span>, 2 <span class=card-victory-treasure>Harems</span>, 2 <span class=card-none>Upgrades</span>, 1 <span class=card-none>Expand</span>, 1 <span class=card-duration>Lighthouse</span>, 4 <span class=card-treasure>Silvers</span>, 6 <span class=card-treasure>Golds</span>, 3 <span class=card-victory>Duchies</span>, 4 <span class=card-victory>Provinces</span> """)
self.assertEquals(parsed_deck['name'], 'zorkkorz')
def test20101213_style_deck_with_paren_name(self):
parsed_deck = parse_game.parse_deck(u"""<b>#1 Foo (Bar)</b>: 43 points (4 <span class=card-victory>Provinces</span>, 3 <span class=card-victory>Duchies</span>, 2 <span class=card-victory>Dukes</span>, and 2 <span class=card-victory-treasure>Harems</span>); 21 turns
opening: <span class=card-none>Upgrade</span> / <span class=card-duration>Lighthouse</span>
[25 cards] 2 <span class=card-victory>Dukes</span>, 2 <span class=card-victory-treasure>Harems</span>, 2 <span class=card-none>Upgrades</span>, 1 <span class=card-none>Expand</span>, 1 <span class=card-duration>Lighthouse</span>, 4 <span class=card-treasure>Silvers</span>, 6 <span class=card-treasure>Golds</span>, 3 <span class=card-victory>Duchies</span>, 4 <span class=card-victory>Provinces</span> """)
self.assertEquals(parsed_deck['name'], 'Foo (Bar)')
def test_20101226_evil_fing_name(self):
parsed_deck = parse_game.parse_deck(u"""<b>#1 20 points</b>: 43 points (4 <span class=card-victory>Provinces</span>, 3 <span class=card-victory>Duchies</span>, 2 <span class=card-victory>Dukes</span>, and 2 <span class=card-victory-treasure>Harems</span>); 21 turns
opening: <span class=card-none>Upgrade</span> / <span class=card-duration>Lighthouse</span>
[25 cards] 2 <span class=card-victory>Dukes</span>, 2 <span class=card-victory-treasure>Harems</span>, 2 <span class=card-none>Upgrades</span>, 1 <span class=card-none>Expand</span>, 1 <span class=card-duration>Lighthouse</span>, 4 <span class=card-treasure>Silvers</span>, 6 <span class=card-treasure>Golds</span>, 3 <span class=card-victory>Duchies</span>, 4 <span class=card-victory>Provinces</span> """)
self.assertEquals(parsed_deck['name'], '20 points')
self.assertEquals(parsed_deck['points'], 43)
def test_deck_with_VP(self):
parsed_deck = parse_game.parse_deck(u"""<b>Jon: 19 points</b> (16 ▼ and a <span class=card-victory>Duchy</span>); 20 turns
opening: <span class=card-none>Salvager</span> / <span class=card-none>Black Market</span>
[7 cards] 2 <span class=card-none>Bishops</span>, 1 <span class=card-duration>Tactician</span>, 1 <span class=card-treasure>Silver</span>, 2 <span class=card-treasure>Golds</span>, 1 <span class=card-victory>Duchy</span>""")
self.assertEquals(parsed_deck['vp_tokens'], 16)
def test_deck_with_VP2(self):
parsed_deck = parse_game.parse_deck(u"""<b>Chrome: 12 points</b> (a <span class=card-victory>Province</span> and 6 ▼); 13 turns
opening: <span class=card-none>Ironworks</span> / <span class=card-none>Black Market</span>
[25 cards] 5 <span class=card-duration>Merchant Ships</span>, 5 <span class=card-none>Universities</span>, 2 <span class=card-none>Apprentices</span>, 2 <span class=card-none>Warehouses</span>, 1 <span class=card-none>Bishop</span>, 1 <span class=card-none>Black Market</span>, 1 <span class=card-none>Explorer</span>, 1 <span class=card-none>Worker's Village</span>, 6 <span class=card-treasure>Coppers</span>, 1 <span class=card-victory>Province</span>""")
self.assertEquals(parsed_deck['vp_tokens'], 6)
def test_parse_old_deck_with_paren(self):
parsed_deck = parse_game.parse_deck(u"""<b>Jeremy (player1): 66 points</b> (8 <span class=card-victory>Provinces</span>, 4 <span class=card-victory>Duchies</span>, and 6 <span class=card-victory>Estates</span>); 28 turns
opening: <span class=card-none>Smithy</span> / <span class=card-treasure>Silver</span>
[38 cards] 2 <span class=card-none>Smithies</span>, 7 <span class=card-treasure>Coppers</span>, 5 <span class=card-treasure>Silvers</span>, 6 <span class=card-treasure>Golds</span>, 6 <span class=card-victory>Estates</span>, 4 <span class=card-victory>Duchies</span>, 8 <span class=card-victory>Provinces</span> """)
self.assertEquals(parsed_deck['name'], 'Jeremy (player1)')
def test_deck_with_VP3(self):
parsed_deck = parse_game.parse_deck(u"""<b>Chrome: 12 points</b> (a <span class=card-victory>Province</span> and 26 ▼); 13 turns
opening: <span class=card-none>Ironworks</span> / <span class=card-none>Black Market</span>
[25 cards] 5 <span class=card-duration>Merchant Ships</span>, 5 <span class=card-none>Universities</span>, 2 <span class=card-none>Apprentices</span>, 2 <span class=card-none>Warehouses</span>, 1 <span class=card-none>Bishop</span>, 1 <span class=card-none>Black Market</span>, 1 <span class=card-none>Explorer</span>, 1 <span class=card-none>Worker's Village</span>, 6 <span class=card-treasure>Coppers</span>, 1 <span class=card-victory>Province</span>""")
self.assertEquals(parsed_deck['vp_tokens'], 26)
def test_parse_empty_deck(self):
# it's random BS like this that makes writing a dominion log parser
# a pain.
parsed_deck = parse_game.parse_deck(u"""<b>torchrat: 0 points</b> (nothing); 24 turns
opening: <span class=card-none>Moneylender</span> / <span class=card-treasure>Silver</span>
[0 cards] """)
self.assertEquals(parsed_deck['vp_tokens'], 0)
self.assertEquals(parsed_deck['deck'], {})
class AssignWinPointsTest(unittest.TestCase):
def test_assign_win_points_simple(self):
g = {'decks': [
{'points': 2, 'turns': [{}, {}]},
{'points': 1, 'turns': [{}, {}]}
]}
parse_game.assign_win_points(g)
self.assertEquals(g['decks'][0]['win_points'], 2.0)
self.assertEquals(g['decks'][1]['win_points'], 0.0)
def test_assign_win_points_break_ties_by_turns(self):
g = {'decks': [
{'points': 2, 'turns': [{}, {}]},
{'points': 2, 'turns': [{}]}
]}
parse_game.assign_win_points(g)
self.assertEquals(g['decks'][0]['win_points'], 0.0)
self.assertEquals(g['decks'][1]['win_points'], 2.0)
def test_tie(self):
g = {'decks': [
{'points': 2, 'turns': [{}, {}]},
{'points': 2, 'turns': [{}, {}]}
]}
parse_game.assign_win_points(g)
self.assertEquals(g['decks'][0]['win_points'], 1.0)
self.assertEquals(g['decks'][1]['win_points'], 1.0)
def test_partial_tie(self):
g = {'decks': [
{'points': 2, 'turns': [{}, {}]},
{'points': 2, 'turns': [{}, {}]},
{'points': 1, 'turns': [{}, {}]}
]}
parse_game.assign_win_points(g)
self.assertEquals(g['decks'][0]['win_points'], 1.5)
self.assertEquals(g['decks'][1]['win_points'], 1.5)
def test_outpost_turn(self):
g = {'decks': [
{'points': 2, 'turns': [{}, {}, {'outpost': True}]},
{'points': 2, 'turns': [{}, {}]},
]}
parse_game.assign_win_points(g)
self.assertEquals(g['decks'][0]['win_points'], 1.0)
def test_possession_turn(self):
g = {'decks': [