-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
1703 lines (1434 loc) · 70.7 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import unittest
from JanggiGame import JanggiGame, print_board
class TestJanggiGame(unittest.TestCase):
def setUp(self):
self.unfinished = 'UNFINISHED'
self.red_won = 'RED_WON'
self.blue_won = 'BLUE_WON'
self.invalid_move = False
self.valid_move = True
# @visibility('visible')
def test_game_can_be_instantiated(self):
"""test that we can create a JanggiGame object"""
g = JanggiGame()
self.assertIsInstance(g, JanggiGame)
# @visibility('visible')
def test_that_blue_can_start_the_game(self):
"""RULES: Blue can start the game"""
g = JanggiGame()
blue_move = g.make_move('c7', 'c6')
self.assertIs(blue_move, True)
# @visibility('after_due_date')
def test_that_red_cannot_start_the_game(self):
"""RULES: Red cannot start the game"""
g = JanggiGame()
red_move = g.make_move('c4', 'c5')
self.assertIs(red_move, False)
# @visibility('visible')
def test_passing_the_turn(self):
"""RULES: test that a player can pass the turn"""
g = JanggiGame()
g.make_move('a7', 'b7') # first move by Blue
move_result = g.make_move('a4', 'a4') # passing move by Red
self.assertIs(move_result, True)
move_result = g.make_move('b7', 'b7') # passing move by Blue
self.assertIs(move_result, True)
# @visibility('after_due_date')
def test_passing_the_turn_after_capturing(self):
"""RULES: test that a player can pass the turn, a turn after capturing another player's piece"""
g = JanggiGame()
g.make_move('a7', 'a6') # first move by Blue
g.make_move('a4', 'a4') # passing move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('e4', 'e5') # valid move by Red
g.make_move('a5', 'a4') # capturing move by Blue
g.make_move('c4', 'c5') # valid move by Red
passing_move = g.make_move('a4', 'a4') # passing move by Blue
self.assertIs(passing_move, True)
valid_move_after_passing = g.make_move('c5', 'c6') # valid move by Red
self.assertIs(valid_move_after_passing, True)
# @visibility('after_due_date')
def test_passing_the_turn_after_being_captured(self):
"""RULES: test that a player can pass the turn, after their piece has been captured"""
g = JanggiGame()
g.make_move('a7', 'a6') # first move by Blue
g.make_move('a4', 'a4') # passing move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('e4', 'e5') # valid move by Red
g.make_move('a5', 'a4') # capturing move by Blue
passing_move = g.make_move('c4', 'c4') # passing move by Red
self.assertIs(passing_move, True)
valid_move_after_passing = g.make_move('a4', 'a3') # valid move by Blue
self.assertIs(valid_move_after_passing, True)
# @visibility('visible')
def test_valid_forward_move_for_red_soldier(self):
"""SOLDIER: test in the beginning of the game that a red soldier can perform a valid forward move"""
#take a soldier for red
g = JanggiGame()
first_move = g.make_move('c7','c6') #because blue moves first
red_soldier_forward_move = g.make_move('c4','c5')
self.assertIs(red_soldier_forward_move, True)
# @visibility('visible')
def test_valid_sideway_move_for_red_soldier(self):
"""SOLDIER: test in the beginning of the game that a red soldier can perform a valid sideway move"""
# take a soldier for red
g = JanggiGame()
first_move = g.make_move('c7', 'c6') # because blue moves first
red_soldier_sideway_move = g.make_move('c4', 'd4')
self.assertIs(red_soldier_sideway_move, True)
# @visibility('visible')
def test_valid_forward_move_for_blue_soldier(self):
"""SOLDIER: test in the beginning of the game that a blue soldier can perform a valid forward move"""
g = JanggiGame()
blue_soldier_forward_move = g.make_move('c7', 'c6') # because blue moves first
self.assertIs(blue_soldier_forward_move, True)
# @visibility('visible')
def test_valid_sideway_move_for_blue_soldier(self):
"""SOLDIER: test in the beginning of the game that a blue soldier can perform a valid sideway move"""
g = JanggiGame()
blue_soldier_sideway_move = g.make_move('c7', 'b7') # because blue moves first
self.assertIs(blue_soldier_sideway_move, True)
# @visibility('after_due_date')
def test_invalid_backward_move_for_blue_soldier(self):
"""SOLDIER: test in the beginning of the game that a blue soldier cannot perform an backward move"""
g = JanggiGame()
blue_soldier_backward_move = g.make_move('c7', 'c8') # try backward move which is illegal
self.assertIs(blue_soldier_backward_move, False)
pass
# @visibility('after_due_date')
def test_invalid_diagonal_move_for_blue_soldier(self):
"""SOLDIER: test in the beginning of the game that a blue soldier cannot perform an diagonal move"""
g = JanggiGame()
blue_soldier_diagonal_move = g.make_move('c7', 'd6') # try diagonal which is illegal
self.assertIs(blue_soldier_diagonal_move, False)
pass
# @visibility('after_due_date')
def test_invalid_backward_move_for_red_soldier(self):
"""SOLDIER: test in the beginning of the game that a red soldier cannot perform an backward move"""
g = JanggiGame()
g.make_move('c7', 'c6') # because blue moves first
red_soldier_backward_move = g.make_move('c4', 'c3') # try backward move which is illegal
self.assertIs(red_soldier_backward_move, False)
pass
# @visibility('after_due_date')
def test_invalid_diagonal_move_for_red_soldier(self):
"""SOLDIER: test in the beginning of the game that a red soldier cannot perform an diagonal move"""
g = JanggiGame()
g.make_move('c7', 'c6') # because blue moves first
red_soldier_backward_move = g.make_move('c4', 'd5') # try diagonal move which is illegal
self.assertIs(red_soldier_backward_move, False)
# @visibility('visible')
def test_a_soldier_can_capture_a_piece(self):
"""SOLDIER: test that a soldier can capture another piece"""
g = JanggiGame()
g.make_move('a7', 'a6') # because blue moves first
g.make_move('i4', 'i5') # first move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('i5', 'i6') # valid move by Red
capturing_move = g.make_move('a5', 'a4') # capturing move by Blue
self.assertIs(capturing_move, True) #move should be succesful
# @visibility('after_due_date')
def test_that_a_captured_piece_cannot_be_moved(self):
"""RULES: test that once a piece has been captured, it no longer exists for movement"""
g = JanggiGame()
g.make_move('a7', 'a6') # because blue moves first
g.make_move('i4', 'i5') # first move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('i5', 'i6') # valid move by Red
capturing_move = g.make_move('a5', 'a4') # capturing move by Blue
move_on_a_non_existent_piece = g.make_move('a4', 'a5') # move from a location owned by Red
self.assertIs(move_on_a_non_existent_piece, False)
# @visibility('after_due_date')
def test_that_after_a_piece_is_captured_the_game_can_still_continue(self):
"""RULES: test that after a capture, the other player can still move"""
g = JanggiGame()
g.make_move('a7', 'a6') # because blue moves first
g.make_move('i4', 'i5') # first move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('i5', 'i6') # valid move by Red
capturing_move = g.make_move('a5', 'a4') # capturing move by Blue
move_on_a_non_existent_piece = g.make_move('a4', 'a5') # move from a location owned by Red
valid_move_by_red = g.make_move('e4', 'e5') # valid move by Red
self.assertIs(valid_move_by_red, True)
# @visibility('visible')
def test_passing_the_turn(self):
"""RULES: test that a player can pass the turn"""
g = JanggiGame()
move_result = g.make_move('a7', 'b7') # first move by Blue
self.assertIs(move_result, True)
move_result = g.make_move('a4', 'a4') # passing move by Red
self.assertIs(move_result, True)
move_result = g.make_move('b7', 'b6') # valid move by Blue
self.assertIs(move_result, True)
# @visibility('after_due_date')
def test_passing_the_turn_after_capturing(self):
"""RULES: test that a player can pass the turn, a turn after capturing another player's piece"""
g = JanggiGame()
g.make_move('a7', 'a6') # first move by Blue
g.make_move('a4', 'a4') # passing move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('e4', 'e5') # valid move by Red
g.make_move('a5', 'a4') # capturing move by Blue
g.make_move('c4', 'c5') # valid move by Red
passing_move = g.make_move('a4', 'a4') # passing move by Blue
self.assertIs(passing_move, True)
valid_move_after_passing = g.make_move('c5', 'c6') # valid move by Red
self.assertIs(valid_move_after_passing, True)
# @visibility('after_due_date')
def test_passing_the_turn_after_being_captured(self):
"""RULES: test that a player can pass the turn, after their piece has been captured"""
g = JanggiGame()
g.make_move('a7', 'a6') # first move by Blue
g.make_move('a4', 'a4') # passing move by Red
g.make_move('a6', 'a5') # valid move by Blue
g.make_move('e4', 'e5') # valid move by Red
g.make_move('a5', 'a4') # capturing move by Blue
passing_move = g.make_move('c4', 'c4') # passing move by Red
self.assertIs(passing_move, True)
valid_move_after_passing = g.make_move('a4', 'a3') # valid move by Blue
self.assertIs(valid_move_after_passing, True)
# @visibility('visible')
def test_valid_forward_move_for_red_chariot(self):
"""CHARIOT: test in the beginning of the game that a red chariot can perform a valid forward move"""
#take a soldier for red
g = JanggiGame()
first_move = g.make_move('c7','c6') #because blue moves first
red_chariot_forward_move = g.make_move('a1','a3')
self.assertIs(red_chariot_forward_move, True)
# @visibility('visible')
def test_valid_sideway_move_for_red_chariot(self):
"""CHARIOT: test in the beginning of the game that a red chariot can perform a valid sideway move"""
# take a soldier for red
g = JanggiGame()
g.make_move('c7', 'c6') # because blue moves first
g.make_move('a1', 'a2') # move the red chariot ahead
g.make_move('g7', 'g6') # blue moves
red_chariot_sideway_move = g.make_move('a2', 'c2') #chariot moves sideway
self.assertIs(red_chariot_sideway_move, True)
# @visibility('visible')
def test_valid_forward_move_for_blue_chariot(self):
"""CHARIOT: test in the beginning of the game that a blue chariot can perform a valid forward move"""
g = JanggiGame()
blue_chariot_forward_move = g.make_move('a10', 'a8') # because blue moves first
self.assertIs(blue_chariot_forward_move, True)
# @visibility('visible')
def test_valid_sideway_move_for_blue_chariot(self):
"""CHARIOT: test in the beginning of the game that a blue chariot can perform a valid sideway move"""
g = JanggiGame()
g.make_move('a10', 'a9') # because blue moves first
g.make_move('a1', 'a2') # move the red chariot ahead
blue_chariot_sideway_move = g.make_move('a9','c9')
self.assertIs(blue_chariot_sideway_move, True)
# @visibility('visible')
def test_valid_backward_move_for_blue_chariot_in_south(self):
"""CHARIOT: test in the beginning of the game that a blue chariot can perform a backward move to south"""
g = JanggiGame()
g.make_move('a10', 'a8') # because blue moves first
g.make_move('a1', 'a2') # move the red chariot ahead
blue_chariot_backward_move = g.make_move('a8', 'a9') #chariot moves backward
self.assertIs(blue_chariot_backward_move, True)
pass
# @visibility('visible')
def test_valid_backward_move_for_blue_chariot_in_west(self):
"""CHARIOT: test in the beginning of the game that a blue chariot can perform a backward move to west"""
g = JanggiGame()
g.make_move('a10', 'a9') # because blue moves first
g.make_move('a1', 'a2') # move the red chariot ahead
g.make_move('a9','c9') #blue chariot moves east
g.make_move('a2','a3') #move the red chariot ahead
blue_chariot_backward_move = g.make_move('c9','b9')
self.assertIs(blue_chariot_backward_move, True)
pass
# @visibility('after_due_date')
def test_invalid_diagonal_move_for_blue_chariot_in_northeast(self):
"""CHARIOT: test in the beginning of the game that a blue chariot cannot perform a diagonal move"""
g = JanggiGame()
g.make_move('a10', 'a8') # because blue moves first
g.make_move('a1', 'a3') # move the red chariot ahead
invalid_chariot_diagonal_move = g.make_move('a8','b7') #blue chariot moves east
self.assertIs(invalid_chariot_diagonal_move, False)
pass
# @visibility('after_due_date')
def test_invalid_diagonal_move_for_red_chariot_to_southeast(self):
"""CHARIOT: test in the beginning of the game that a red chariot cannot perform a diagonal move"""
g = JanggiGame()
g.make_move('a10', 'a8') # because blue moves first
g.make_move('a1', 'a3') # move the red chariot ahead
g.make_move('a7','b7') # blue soldier moves ahead
invalid_chariot_diagonal_move = g.make_move('a3', 'b4') #red chariot moves southeast
self.assertIs(invalid_chariot_diagonal_move, False)
pass
# @visibility('visible')
def test_valid_north_move_for_blue_cannon(self):
"""CANNON: test blue cannon can perform a valid north move"""
g = JanggiGame()
g.make_move('a7','b7') # blue soldier move sideway
g.make_move('a4','a5') # red move
cannon_valid_move = g.make_move('b8','b4') # blue cannon jumps over blue soldier
self.assertIs(cannon_valid_move, True)
# @visibility('visible')
def test_valid_east_move_for_blue_cannon(self):
"""CANNON: test blue cannon can perform a valid east move"""
g = JanggiGame()
g.make_move('c7', 'c6') # blue soldier move ahead
g.make_move('a4', 'a5') # red move
g.make_move('a7', 'b7') # blue soldier move sideway
g.make_move('a5', 'a6') # red move
g.make_move('b8', 'b6') # blue cannon jumps north
g.make_move('a6', 'a7') # red move
cannon_valid_move = g.make_move('b6', 'e6') # blue cannon jumps over blue soldier east two steps
self.assertIs(cannon_valid_move, True)
# @visibility('after_due_date')
def test_valid_west_move_for_blue_cannon(self):
"""CANNON: test blue cannon can perform a valid west move"""
g = JanggiGame()
g.make_move('g7','h7') #blue soldier moves to make a screen
g.make_move('g4','g5') #red soldier moves to make a future screen
g.make_move('h8','h5') #blue cannon moves front
g.make_move('g5','g5') #red passes
cannon_valid_west_move = g.make_move('h5','a5') #blue cannon jumps west
self.assertIs(cannon_valid_west_move, True)
#now try moving that cannon again back to make sure it was actually placed there
g.make_move('g5','g5') #red passes
valid_cannon_move_back = g.make_move('a5','h5') #blue cannon moves east
self.assertIs(valid_cannon_move_back, True)
# @visibility('after_due_date')
def test_valid_south_move_for_blue_cannon(self):
"""CANNON: test blue cannon can perform a valid south move"""
g = JanggiGame()
g.make_move('g7','h7') #blue soldier moves to make a screen
g.make_move('g4','g5') #red soldier moves to make a future screen
g.make_move('h8','h5') #blue cannon moves front
g.make_move('g5','g5') #red passes
g.make_move('h5','a5') #blue cannon jumps west
g.make_move('g5','g5') #red passes
valid_cannon_move_south = g.make_move('a5','a9') #blue cannon moves south
self.assertIs(valid_cannon_move_south, True)
#now try moving that cannon again back to make sure it was actually placed there
g.make_move('g5','g5') #red passes
valid_cannon_move_back = g.make_move('a9','a6') #blue cannon moves north
self.assertIs(valid_cannon_move_back, True)
# @visibility('visible')
def test_invalid_diagonal_move_for_blue_cannon_with_a_screen(self):
"""CANNON: test blue cannon cannot perform an invalid diagonal move with a screen"""
g = JanggiGame()
cannon_invalid_move = g.make_move('b8', 'd6') # blue cannon jumps northwest
self.assertIs(cannon_invalid_move, False)
# @visibility('visible')
def test_invalid_forward_move_for_blue_cannon_without_a_screen(self):
"""CANNON: test blue cannon cannot perform an invalid forward move without a screen"""
g = JanggiGame()
cannon_invalid_move = g.make_move('b8', 'b7') # blue cannon move forward without a screen
self.assertIs(cannon_invalid_move, False)
# @visibility('after_due_date')
def test_invalid_forward_move_for_blue_cannon_capturing_another_cannon(self):
"""CANNON: test blue cannon cannot perform an invalid capture of red cannon"""
g = JanggiGame()
g.make_move('c7', 'c6') # blue soldier move ahead
g.make_move('a4', 'a5') # red move
g.make_move('a7', 'b7') # blue soldier move sideway
g.make_move('a5', 'a6') # red move
g.make_move('b8', 'b6') # blue cannon jumps north
g.make_move('c4', 'b4') # red move
invalid_cannon_move = g.make_move('b6', 'b3') # cannon jumps over red soldier to capture red cannon
self.assertIs(invalid_cannon_move, False)
# @visibility('after_due_date')
def test_invalid_forward_move_for_blue_cannon_jumping_over_red_cannon(self):
"""CANNON: test blue cannon cannot perform an invalid jump over red cannon"""
g = JanggiGame()
g.make_move('c7', 'c6') # blue soldier move ahead
g.make_move('a4', 'a5') # red move
g.make_move('a7', 'b7') # blue soldier move sideway
g.make_move('a5', 'a6') # red move
g.make_move('b8', 'b6') # blue cannon jumps north
g.make_move('c4', 'c5') # red move
invalid_cannon_move = g.make_move('b6', 'b2') # blue cannon jumps over red cannon
self.assertIs(invalid_cannon_move, False)
# @visibility('after_due_date')
def test_valid_forward_move_for_blue_cannon_capturing_red_soldier(self):
"""CANNON: test blue cannon can capture red soldier successfully"""
g = JanggiGame()
g.make_move('c7', 'c6') # blue soldier move ahead
g.make_move('a4', 'a5') # red move
g.make_move('a7', 'b7') # blue soldier move sideway
g.make_move('a5', 'b5') # red move
capturing_move = g.make_move('b8', 'b5') # blue cannon jumps north to capture red soldier
self.assertIs(capturing_move, True)
move_on_a_non_existent_piece = g.make_move('b5', 'b6')
self.assertIs(move_on_a_non_existent_piece, False)
valid_move_by_red = g.make_move('e4', 'e5') # valid move by Red
self.assertIs(valid_move_by_red, True)
"""HORSES"""
# @visibility('visible')
def test_valid_forward_move_for_blue_horse_on_west_side(self):
"""HORSE: test blue horse from west can make a valid move forward"""
g = JanggiGame()
valid_move = g.make_move('c10', 'd8')
self.assertIs(valid_move, True)
# @visibility('visible')
def test_valid_forward_move_for_blue_horse_on_east_side(self):
"""HORSE: test blue horse from east can make a valid move forward"""
g = JanggiGame()
valid_move = g.make_move('h10', 'g8')
self.assertIs(valid_move, True)
# @visibility('visible')
def test_invalid_forward_move_for_blue_horse_on_west_side(self):
"""HORSE: test blue horse from west cannot make an invalid move forward"""
g = JanggiGame()
invalid_move = g.make_move('c10', 'd7')
self.assertIs(invalid_move, False)
# @visibility('visible')
def test_invalid_forward_move_for_blue_horse_on_east_side(self):
"""HORSE: test blue horse from east cannot make an invalid move forward"""
g = JanggiGame()
valid_move = g.make_move('h10', 'f8')
self.assertIs(valid_move, False)
# @visibility('visible')
def test_horse_is_blocked_by_a_piece(self):
"""HORSE: test horse cannot jump over their own piece"""
g = JanggiGame()
g.make_move('c10', 'd8') #blue horse moves
g.make_move('c1','d3') #red horse move
g.make_move('c7','d7') #blue soldier moves to block the blue horse
g.make_move('c4','d4') #red soldier moves to block the red horse
try:
invalid_move_because_of_block = g.make_move('d8','c6') #invalid move because blocked by own soldier
self.assertIs(invalid_move_because_of_block, False)
except:
self.fail("Blue horse from west should not be able to jump over a blue piece")
g.make_move('d8','d8') # blue passes the turn
try:
invalid_move_because_of_block = g.make_move('d3','d6') #invalid move by red because blocked by own soldier
self.assertIs(invalid_move_because_of_block, False)
except:
self.fail("Red horse from west should not be able to jump over a red piece")
g.make_move('d3','d3') #red passes the turn
g.make_move('h10', 'g8') #blue horse move
g.make_move('h2','g3') #red horse move
try:
invalid_move_because_of_block = g.make_move('g8','h6') #invalid move by blue because blocked by own soldier
self.assertIs(invalid_move_because_of_block, False)
except:
self.fail("Blue horse from east should not be able to jump over a blue piece")
g.make_move('g8','g8') #blue passes the turn
try:
invalid_move_because_of_block = g.make_move('g3','g5') #invalid move because blocked by own soldier
self.assertIs(invalid_move_because_of_block, False)
except:
self.fail("Red horse from east should not be able to jump over a red piece")
# @visibility('visible')
def test_horse_can_capture_a_piece(self):
"""HORSE: test that a horse can capture another player's piece"""
g = JanggiGame()
g.make_move('c10','d8') #blue horse moves
g.make_move('c1','d3') #red horse moves
g.make_move('e7','e6') #blue soldier
g.make_move('e4','e5') #red
g.make_move('c7','c6') #blue
g.make_move('c4','c5') #red
g.make_move('c6','c5') #blue soldier captures red
g.make_move('e5','e6') #red soldier captures blue
try:
capturing_move = g.make_move('d8','e6')
self.assertIs(capturing_move, True)
except:
self.fail("Blue Horse from West should be able to capture a Red soldier")
try:
capturing_move = g.make_move('d3','c5') #red capture
self.assertIs(capturing_move, True)
except:
self.fail("Red Horse from West should be able to capture a Blue Soldier")
g.make_move('h10', 'g8') # blue horse from east
g.make_move('h1', 'i3') #red horse from east
g.make_move('g7','h7') #blue
g.make_move('g4', 'f4') #red
g.make_move('h7', 'h6') #blue
g.make_move('i4','i5') #red
g.make_move('h6','h5') #blue
g.make_move('i5','i6') #red
g.make_move('g8','g8') #blue passes
try:
valid_capture_move = g.make_move('i3','h5')
self.assertIs(valid_capture_move, True)
except:
self.fail("Red Horse from East should be able to capture a Blue Soldier")
g.make_move('g8','g8') #blue passes
g.make_move('i6','h6') #red moves
try:
valid_capture_move = g.make_move('g8', 'h6')
self.assertIs(valid_capture_move, True)
except:
self.fail("Blue Horse from East should be able to capture a Red soldier")
# @visibility('after_due_date')
def test_horse_cannot_capture_own_piece(self):
"""HORSE: test that a horse cannot capture same player's piece"""
g = JanggiGame()
try:
invalid_capturing_move = g.make_move('c10', 'b8') # blue horse tries to get at the same place as Cannon
self.assertIs(invalid_capturing_move, False)
except:
self.fail("Blue Horse from west should not be able to capture a blue piece")
g.make_move('g7', 'g7') # blue passing move
try:
invalid_capturing_move = g.make_move('c1', 'b3') # red horse tries to get at the same place as Cannon
self.assertIs(invalid_capturing_move, False)
except:
self.fail("Red Horse from west should not be able to capture a red piece")
try:
g.make_move('h1', 'g3') #red horse moves
g.make_move('g7', 'g7') #blue passes
invalid_capturing_move = g.make_move('g3', 'f1') #red horse tries to get at the same place as red guard
self.assertIs(invalid_capturing_move, False)
except:
self.fail("Red Horse from west should not be able to capture a red piece")
g.make_move('f1','f1') #red passing move
try:
g.make_move('h10', 'g8') # blue horse moves
g.make_move('f1', 'f1') # red passes
invalid_capturing_move = g.make_move('g8', 'f10') # blue horse tries to get at the same place as blue guard
self.assertIs(invalid_capturing_move, False)
except:
self.fail("Blue Horse from east should not be able to capture a blue piece")
"""GUARDS"""
# @visibility('visible')
def test_valid_move_for_guard(self):
"""GUARD: test valid moves for guard"""
g = JanggiGame()
try:
valid_move = g.make_move('d10','d9') #blue guard moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Guard from west should be able to make a valid move")
try:
valid_move = g.make_move('d1','d2') #red guard moves
self.assertIs(valid_move, True)
except:
self.fail("Red Guard from west should be able to make a valid move")
try:
valid_move = g.make_move('f10','f9') #blue guard moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Guard from east should be able to make a valid move")
try:
valid_move = g.make_move('f1','f2') #red guard moves
self.assertIs(valid_move, True)
except:
self.fail("Red Guard from east should be able to make a valid move")
try:
valid_move = g.make_move('d9','d8') #blue guard moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Guard from west should be able to make a valid move")
try:
valid_move = g.make_move('d2','d3') #red guard moves
self.assertIs(valid_move, True)
except:
self.fail("Red Guard from west should be able to make a valid move")
try:
valid_move = g.make_move('f9','f8') #blue guard moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Guard from east should be able to make a valid move")
try:
valid_move = g.make_move('f2','f3') #red guard moves
self.assertIs(valid_move, True)
except:
self.fail("Red Guard from east should be able to make a valid move")
#perform diagonal moves
g.make_move('e9','e10') #blue general moves
g.make_move('e2','e1') #red general moves
try:
valid_diagonal_move = g.make_move('d8','e9') #blue guard moves
self.assertIs(valid_diagonal_move, True)
except:
self.fail("Blue Guard should be able to make a diagonal move")
try:
valid_diagonal_move = g.make_move('d3','e2') #red guard moves
self.assertIs(valid_diagonal_move, True)
except:
self.fail("Red Guard should be able to make a diagonal move")
# @visibility('after_due_date')
def test_invalid_move_for_guard(self):
"""GUARD: test invalid moves for guard"""
g = JanggiGame()
g.make_move('d10','d9') #blue moves
g.make_move('d1','d2') #red moves
g.make_move('f10','f9') #blue moves
g.make_move('f1','f2') #red moves
g.make_move('d9','d8') #blue moves
g.make_move('d2','d3') #red moves
g.make_move('f9','f8') #blue moves
g.make_move('f2','f3') #red moves
try:
invalid_move = g.make_move('d8','c8') #blue guard tries to move outside the palace
self.assertIs(invalid_move, False)
except:
self.fail("Blue Guard should not be able to move outside the palace")
g.make_move('d8','d8') #blue passes
try:
invalid_move = g.make_move('d3','c3') #red guard tries to move outside the palace
self.assertIs(invalid_move, False)
except:
self.fail("Red Guard should not be able to move outside the palace")
g.make_move('d3','d3') #red passes
try:
invalid_move = g.make_move('f8','g8') #blue guard tries to move outside the palace
self.assertIs(invalid_move, False)
except:
self.fail("Blue Guard should not be able to move outside the palace")
g.make_move('f8','f8') #blue passes
try:
invalid_move = g.make_move('f3','g3') #red guard tries to move outside the palace
self.assertIs(invalid_move, False)
except:
self.fail("Red Guard should not be able to move outside the palace")
# @visibility('visible')
def test_valid_move_for_elephant(self):
"""ELEPHANT: test elephants can make valid moves"""
g = JanggiGame()
try:
valid_move = g.make_move('b10','d7') #blue elephant moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Elephant from west should be able to make a valid move")
try:
valid_move = g.make_move('b1','d4') #red elephant moves
self.assertIs(valid_move, True)
except:
self.fail("Red Elephant from west should be able to make a valid move")
g.make_move('e7', 'e6') # blue soldier moves to make place for eastern blue elephant
g.make_move('e4', 'e5') # red soldier moves to make place for eastern red elephant
try:
valid_move = g.make_move('g10','e7') #blue elephant moves
self.assertIs(valid_move, True)
except:
self.fail("Blue Elephant from east should be able to make a valid move")
try:
valid_move = g.make_move('g1','e4') #red elephant moves
self.assertIs(valid_move, True)
except:
self.fail("Red Elephant from east should be able to make a valid move")
# @visibility('after_due_date')
def test_invalid_move_for_elephant(self):
"""ELEPHANT: test elephant cannot make invalid moves"""
g = JanggiGame()
invalid_move = g.make_move('b10','c8') #blue
self.assertIs(invalid_move, False)
invalid_move = g.make_move('b10','b9') #moves forward like a soldier
self.assertIs(invalid_move, False)
invalid_move = g.make_move('b10','b9') #move one diagonal
self.assertIs(invalid_move, False)
invalid_move = g.make_move('b10','b7') #tries to jump over cannon
self.assertIs(invalid_move, False)
g.make_move('b10','b10') #blue passes
#try on red
invalid_move = g.make_move('g1','g2') #red move like a soldier
self.assertIs(invalid_move, False)
invalid_move = g.make_move('g1','f2') #move one diagonal
self.assertIs(invalid_move, False)
invalid_move = g.make_move('g1','g5') #tries to jump over the soldier
self.assertIs(invalid_move, False)
# @visibility('visible')
def test_valid_moves_for_general(self):
"""GENERAL: test general can perform valid moves"""
g = JanggiGame()
valid_move = g.make_move('e9', 'f8') # blue
self.assertIs(valid_move, True)
valid_move = g.make_move('e2', 'f3') # red
self.assertIs(valid_move, True)
valid_move = g.make_move('f8','e8') # blue
self.assertIs(valid_move, True)
valid_move = g.make_move('f3','e3') # red
self.assertIs(valid_move, True)
valid_move = g.make_move('e8','d8') # blue
self.assertIs(valid_move, True)
valid_move = g.make_move('e3', 'd3') # red
self.assertIs(valid_move, True)
valid_move = g.make_move('d8', 'd9') # blue
self.assertIs(valid_move, True)
valid_move = g.make_move('d3', 'd2') # red
self.assertIs(valid_move, True)
valid_move = g.make_move('d9','e9') #blue
self.assertIs(valid_move, True)
valid_move = g.make_move('d2','e2') #red
self.assertIs(valid_move, True)
valid_move = g.make_move('e9', 'e10') #blue
self.assertIs(valid_move, True)
valid_move = g.make_move('e2','e1') #red
self.assertIs(valid_move, True)
# @visibility('visible')
def test_invalid_moves_for_general(self):
"""GENERAL: test general cannot perform invalid moves"""
g = JanggiGame()
valid_move = g.make_move('e9', 'f8') # blue
valid_move = g.make_move('e2', 'f3') # red
#moving outside the palace
invalid_move = g.make_move('f8','g8') #blue
self.assertIs(invalid_move, False)
#blue passes
g.make_move('f8','f8')
invalid_move = g.make_move('f3', 'f4') # red
self.assertIs(invalid_move, False)
# red passes
g.make_move('f3', 'f3')
#prepare for the move
g.make_move('f10','e10') #blue
g.make_move('f1','e1') #red
#moving two spaces
invalid_move = g.make_move('f8','f10')
self.assertIs(invalid_move, False)
g.make_move('f8','f8') #blue passes
# moving two spaces
invalid_move = g.make_move('f3', 'f1')
self.assertIs(invalid_move, False)
g.make_move('f3','f3') #red passes
g.make_move('e10','e9') #blue moves
g.make_move('e1','e2') #red moves
#moving at a place where another piece already exists
invalid_move = g.make_move('f8','e9') #blue
self.assertIs(invalid_move, False)
g.make_move('f8','f8') #blue passes
invalid_move = g.make_move('f3', 'e2') # blue
self.assertIs(invalid_move, False)
# @visibility('visible')
def test_unfinished_game_state(self):
"""RULES: test that get_game_state returns UNFINISHED correctly"""
g = JanggiGame()
g.make_move('e7','f7') #blue
self.assertEqual(g.get_game_state().upper(),'UNFINISHED')
g.make_move('e4','e5')#red
self.assertEqual(g.get_game_state().upper(), 'UNFINISHED')
# @visibility('after_due_date')
def test_unfinished_game_state_after_capture(self):
"""RULES: test that get_game_state returns UNFINISHED correctly after a piece is captured"""
g = JanggiGame()
g.make_move('c7','c6') #blue moves
g.make_move('e4','f4') #red moves
g.make_move('b10','d7') #blue elephant moves
g.make_move('d1','d2') #red
g.make_move('c10','c9') #blue
g.make_move('g4','h4') #red
g.make_move('i10','i8')
g.make_move('e2','f2') #red
g.make_move('g7','h7')
g.make_move('h3','h5') #red
g.make_move('h7','g7')
g.make_move('c1','e2') #red
g.make_move('i7','i6')
g.make_move('g1','e4') #red
g.make_move('i6','h6') #blue captures red cannon
try:
self.assertEqual(g.get_game_state().upper(),'UNFINISHED')
except:
self.fail("Game state should be UNFINISHED if no one has won")
# @visibility('visible')
def test_is_in_check_blue(self):
"""RULES: test that is_in_check detects check correctly for blue"""
g = JanggiGame()
g.make_move('c7','c6') #blue
g.make_move('c1','d3') #red
g.make_move('b10','d7') #blue
g.make_move('b3','e3') #red
g.make_move('c10','d8') #blue
g.make_move('h1','g3') #red
g.make_move('e7','e6') # blue
g.make_move('e3', 'e6') #red cannon captures soldier -- check here
try:
self.assertEqual(g.get_game_state().upper(), 'UNFINISHED')
except:
self.fail("Game state should be unfinished before an actual check")
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for red")
try:
self.assertIs(g.is_in_check('blue'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for blue")
g.make_move('h8','c8') #blue cannon moves -- check here
g.make_move('d3','e5') #red
g.make_move('c8','c4') #blue cannon captures red soldier -- check here
try:
self.assertEqual(g.get_game_state().upper(), 'UNFINISHED')
except:
self.fail("Game state should be unfinished before an actual check")
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for red")
try:
self.assertIs(g.is_in_check('blue'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for blue")
g.make_move('e5','c4') #red horse captures blue cannon
g.make_move('i10','i8') #blue chariot moves
g.make_move('g4','f4')
g.make_move('i8','f8') #blue chariot moves sideway
g.make_move('g3','h5')
g.make_move('h10','g8') #blue horse
self.assertTrue(g.make_move('e6','e3')) #red CHECKS blue using a cannon -- special test for checks using a cannon -- check here
try:
self.assertEqual(g.get_game_state().upper(),'UNFINISHED')
except:
self.fail("Game state should be UNFINISHED when a general is in check but not checkmated")
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("Red General is not in check and yet is_in_check returns True for red")
try:
self.assertIs(g.is_in_check('blue'), True)
except:
self.fail("Blue General is in check and is_in_check should return True for blue")
g.make_move('e9','d9') #general moves to avoid check -- check here
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for red")
try:
self.assertIs(g.is_in_check('blue'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for blue")
try:
self.assertEqual(g.get_game_state().upper(),'UNFINISHED')
except:
self.fail("Game state should be UNFINISHED when a general is in check")
# @visibility('after_due_date')
def test_is_in_check_red(self):
"""RULES: test that is_in_check detects check correctly for red"""
g = JanggiGame()
g.make_move('c7','c6') #blue
g.make_move('c1','d3') #red
g.make_move('b10','d7') #blue
g.make_move('b3','e3') #red
g.make_move('c10','d8')
g.make_move('h1','g3')
g.make_move('e7','e6')
g.make_move('e3', 'e6') #red cannon captures soldier -- check here
try:
self.assertEqual(g.get_game_state().upper(), 'UNFINISHED')
except:
self.fail("Game state should be unfinished before an actual check")
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for Red")
try:
self.assertIs(g.is_in_check('blue'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for Blue")
g.make_move('h8','c8') #blue moves -- check here
g.make_move('d3','e5') #red
g.make_move('c8','c4') #blue cannon captures red soldier -- check here
try:
self.assertEqual(g.get_game_state().upper(), 'UNFINISHED')
except:
self.fail("Game state should be unfinished before an actual win")
try:
self.assertIs(g.is_in_check('red'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for Red")
try:
self.assertIs(g.is_in_check('blue'), False)
except:
self.fail("General is not in check and yet is_in_check returns True for Blue")
g.make_move('e5','c4') #red horse captures blue cannon
g.make_move('i10','i8') #blue chariot moves
g.make_move('g4','f4')
g.make_move('i8','f8') #blue chariot moves sideway
g.make_move('g3','h5')
g.make_move('h10','g8') #blue horse
g.make_move('e6','e3') #red CHECKS blue using a cannon -- special test for checks using a cannon -- check here