templates.chess_test_3_repeat

 1import smartpy as sp
 2from smartpy.templates.chess import main, play, build_fen
 3
 4if "main" in __name__:
 5    player1 = sp.test_account("player1")
 6    player2 = sp.test_account("player2")
 7
 8    @sp.add_test()
 9    def test():
10        sc = sp.test_scenario("Chess - 3 times repeat", main)
11        c1 = main.Chess(player1.address, player2.address)
12
13        sc.h1("3 times repeat")
14        sc.h2("After move")
15        sc += c1
16
17        c1.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
18        c1.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
19        c1.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
20        c1.play(play(f=sp.record(i=5, j=2), t=sp.record(i=7, j=1)), _sender=player2)
21        c1.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
22        c1.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
23        c1.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
24        c1.play(play(f=sp.record(i=5, j=2), t=sp.record(i=7, j=1)), _sender=player2)
25        c1.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
26        c1.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
27        c1.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
28        c1.play(
29            play(
30                f=sp.record(i=5, j=2),
31                t=sp.record(i=7, j=1),
32                claim_repeat=sp.Some((0, 3)),
33            ),
34            _sender=player2,
35            _valid=False,
36            _exception=sp.pair("NotSameMove", sp.record(fullMove=3)),
37        )
38        c1.play(
39            play(
40                f=sp.record(i=5, j=2),
41                t=sp.record(i=7, j=1),
42                claim_repeat=sp.Some((0, 4)),
43            ),
44            _sender=player2,
45        )
46        sc.verify(c1.data.status == sp.variant.finished("draw"))
47
48        sc.h2("Previous move")
49        c2 = main.Chess(player1.address, player2.address)
50        sc += c2
51
52        c2.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
53        c2.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
54        c2.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
55        c2.play(play(f=sp.record(i=5, j=2), t=sp.record(i=7, j=1)), _sender=player2)
56        c2.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
57        c2.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
58        c2.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
59        c2.play(play(f=sp.record(i=5, j=2), t=sp.record(i=7, j=1)), _sender=player2)
60        c2.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=5)), _sender=player1)
61        c2.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
62        c2.play(play(f=sp.record(i=2, j=5), t=sp.record(i=0, j=6)), _sender=player1)
63        c2.play(play(f=sp.record(i=5, j=2), t=sp.record(i=7, j=1)), _sender=player2)
64        c2.threefold_repetition_claim(
65            fullMove1=0,
66            fullMove2=5,
67            _sender=player1,
68            _valid=False,
69            _exception=sp.pair("NotSameMove", sp.record(fullMove=5)),
70        )
71        c2.threefold_repetition_claim(fullMove1=0, fullMove2=4, _sender=player1)
72        sc.verify(c2.data.status == sp.variant.finished("draw"))