templates.chess_test_checkmate

 1import smartpy as sp
 2from smartpy.templates.chess import main, play
 3
 4
 5if "main" in __name__:
 6    player1 = sp.test_account("player1")
 7    player2 = sp.test_account("player2")
 8
 9    @sp.add_test()
10    def test():
11        sc = sp.test_scenario("Chess - Checkmate", main)
12        sc.h1("Checkmate")
13
14        sc.h2("Scholar's mate")
15        c1 = main.Chess(player1.address, player2.address)
16        sc += c1
17
18        c1.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
19        c1.play(play(f=sp.record(i=6, j=4), t=sp.record(i=4, j=4)), _sender=player2)
20        c1.play(play(f=sp.record(i=0, j=5), t=sp.record(i=3, j=2)), _sender=player1)
21        c1.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
22        c1.play(play(f=sp.record(i=0, j=3), t=sp.record(i=4, j=7)), _sender=player1)
23        c1.claim_checkmate(_valid=False)
24        c1.play(play(f=sp.record(i=6, j=0), t=sp.record(i=4, j=0)), _sender=player2)
25        c1.claim_checkmate(_valid=False)
26        c1.play(play(f=sp.record(i=4, j=7), t=sp.record(i=6, j=5)), _sender=player1)
27        c1.claim_checkmate()
28
29        sc.h2("King captures the attacking piece")
30        c2 = main.Chess(player1.address, player2.address)
31        sc += c2
32
33        c2.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
34        c2.play(play(f=sp.record(i=6, j=4), t=sp.record(i=4, j=4)), _sender=player2)
35        c2.play(play(f=sp.record(i=0, j=3), t=sp.record(i=2, j=5)), _sender=player1)
36        c2.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
37        c2.play(play(f=sp.record(i=2, j=5), t=sp.record(i=6, j=5)), _sender=player1)
38        c2.claim_checkmate(_valid=False)
39
40        sc.h2("Suffocating King")
41        c3 = main.Chess(player1.address, player2.address)
42        sc += c3
43
44        c3.play(play(f=sp.record(i=0, j=1), t=sp.record(i=2, j=2)), _sender=player1)
45        c3.play(play(f=sp.record(i=6, j=4), t=sp.record(i=4, j=4)), _sender=player2)
46        c3.play(play(f=sp.record(i=2, j=2), t=sp.record(i=4, j=3)), _sender=player1)
47        c3.play(play(f=sp.record(i=7, j=6), t=sp.record(i=6, j=4)), _sender=player2)
48        c3.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
49        c3.play(play(f=sp.record(i=6, j=6), t=sp.record(i=5, j=6)), _sender=player2)
50        c3.play(play(f=sp.record(i=4, j=3), t=sp.record(i=5, j=5)), _sender=player1)
51        sc.show(c3.build_fen())
52        c3.claim_checkmate()
53
54        sc.h2("Obstructing column")
55        c4 = main.Chess(player1.address, player2.address)
56        sc += c4
57
58        c4.play(play(f=sp.record(i=0, j=1), t=sp.record(i=2, j=2)), _sender=player1)
59        c4.play(play(f=sp.record(i=6, j=4), t=sp.record(i=4, j=4)), _sender=player2)
60        c4.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
61        c4.play(play(f=sp.record(i=6, j=0), t=sp.record(i=4, j=0)), _sender=player2)
62        c4.play(play(f=sp.record(i=0, j=3), t=sp.record(i=4, j=7)), _sender=player1)
63        c4.play(play(f=sp.record(i=4, j=0), t=sp.record(i=3, j=0)), _sender=player2)
64        c4.play(play(f=sp.record(i=4, j=7), t=sp.record(i=4, j=4)), _sender=player1)
65        c4.claim_checkmate(_valid=False)
66
67        sc.h2("Obstructing diagonal")
68        c5 = main.Chess(player1.address, player2.address)
69        sc += c5
70
71        c5.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
72        c5.play(play(f=sp.record(i=6, j=5), t=sp.record(i=4, j=5)), _sender=player2)
73        c5.play(play(f=sp.record(i=0, j=3), t=sp.record(i=4, j=7)), _sender=player1)
74        c5.claim_checkmate(_valid=False)
75        c5.play(play(f=sp.record(i=6, j=6), t=sp.record(i=5, j=6)), _sender=player2)
76        c5.play(play(f=sp.record(i=1, j=7), t=sp.record(i=2, j=7)), _sender=player1)
77        c5.play(play(f=sp.record(i=6, j=7), t=sp.record(i=5, j=7)), _sender=player2)
78        c5.play(play(f=sp.record(i=4, j=7), t=sp.record(i=5, j=6)), _sender=player1)
79        c5.claim_checkmate()
80        sc.verify_equal(c5.data.status, sp.variant.finished("player_1_won"))