templates.chess_test_game1

  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 - Adams Michael vs Sedgwick David", main)
 11        c1 = main.Chess(player1.address, player2.address)
 12
 13        sc.h1(
 14            " Adams, Michael vs. Sedgwick, David 1-0 London: Lloyds Bank op: 1984.??.??"
 15        )
 16        sc += c1
 17        # Adams, Michael vs. Sedgwick, David 1-0
 18        # London: Lloyds Bank op: 1984.??.??
 19        sc.verify(
 20            build_fen(c1) == "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
 21        )
 22        c1.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=4)), _sender=player1)
 23        sc.verify(
 24            build_fen(c1)
 25            == "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"
 26        )
 27        c1.play(play(f=sp.record(i=6, j=4), t=sp.record(i=5, j=4)), _sender=player2)
 28        sc.verify(
 29            build_fen(c1)
 30            == "rnbqkbnr/pppp1ppp/4p3/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2"
 31        )
 32        c1.play(play(f=sp.record(i=1, j=3), t=sp.record(i=3, j=3)), _sender=player1)
 33        sc.verify(
 34            build_fen(c1)
 35            == "rnbqkbnr/pppp1ppp/4p3/8/3PP3/8/PPP2PPP/RNBQKBNR b KQkq d3 0 2"
 36        )
 37        c1.play(play(f=sp.record(i=6, j=3), t=sp.record(i=4, j=3)), _sender=player2)
 38        sc.verify(
 39            build_fen(c1)
 40            == "rnbqkbnr/ppp2ppp/4p3/3p4/3PP3/8/PPP2PPP/RNBQKBNR w KQkq d6 0 3"
 41        )
 42        c1.play(play(f=sp.record(i=0, j=1), t=sp.record(i=1, j=3)), _sender=player1)
 43        sc.verify(
 44            build_fen(c1)
 45            == "rnbqkbnr/ppp2ppp/4p3/3p4/3PP3/8/PPPN1PPP/R1BQKBNR b KQkq - 1 3"
 46        )
 47        c1.play(play(f=sp.record(i=7, j=6), t=sp.record(i=5, j=5)), _sender=player2)
 48        sc.verify(
 49            build_fen(c1)
 50            == "rnbqkb1r/ppp2ppp/4pn2/3p4/3PP3/8/PPPN1PPP/R1BQKBNR w KQkq - 2 4"
 51        )
 52        c1.play(play(f=sp.record(i=3, j=4), t=sp.record(i=4, j=4)), _sender=player1)
 53        sc.verify(
 54            build_fen(c1)
 55            == "rnbqkb1r/ppp2ppp/4pn2/3pP3/3P4/8/PPPN1PPP/R1BQKBNR b KQkq - 0 4"
 56        )
 57        c1.play(play(f=sp.record(i=5, j=5), t=sp.record(i=6, j=3)), _sender=player2)
 58        sc.verify(
 59            build_fen(c1)
 60            == "rnbqkb1r/pppn1ppp/4p3/3pP3/3P4/8/PPPN1PPP/R1BQKBNR w KQkq - 1 5"
 61        )
 62        c1.play(play(f=sp.record(i=1, j=5), t=sp.record(i=3, j=5)), _sender=player1)
 63        sc.verify(
 64            build_fen(c1)
 65            == "rnbqkb1r/pppn1ppp/4p3/3pP3/3P1P2/8/PPPN2PP/R1BQKBNR b KQkq f3 0 5"
 66        )
 67        c1.play(play(f=sp.record(i=6, j=2), t=sp.record(i=4, j=2)), _sender=player2)
 68        sc.verify(
 69            build_fen(c1)
 70            == "rnbqkb1r/pp1n1ppp/4p3/2ppP3/3P1P2/8/PPPN2PP/R1BQKBNR w KQkq c6 0 6"
 71        )
 72        c1.play(play(f=sp.record(i=1, j=2), t=sp.record(i=2, j=2)), _sender=player1)
 73        sc.verify(
 74            build_fen(c1)
 75            == "rnbqkb1r/pp1n1ppp/4p3/2ppP3/3P1P2/2P5/PP1N2PP/R1BQKBNR b KQkq - 0 6"
 76        )
 77        c1.play(play(f=sp.record(i=7, j=1), t=sp.record(i=5, j=2)), _sender=player2)
 78        sc.verify(
 79            build_fen(c1)
 80            == "r1bqkb1r/pp1n1ppp/2n1p3/2ppP3/3P1P2/2P5/PP1N2PP/R1BQKBNR w KQkq - 1 7"
 81        )
 82        c1.play(play(f=sp.record(i=1, j=3), t=sp.record(i=2, j=5)), _sender=player1)
 83        sc.verify(
 84            build_fen(c1)
 85            == "r1bqkb1r/pp1n1ppp/2n1p3/2ppP3/3P1P2/2P2N2/PP4PP/R1BQKBNR b KQkq - 2 7"
 86        )
 87        c1.play(play(f=sp.record(i=4, j=2), t=sp.record(i=3, j=3)), _sender=player2)
 88        sc.verify(
 89            build_fen(c1)
 90            == "r1bqkb1r/pp1n1ppp/2n1p3/3pP3/3p1P2/2P2N2/PP4PP/R1BQKBNR w KQkq - 0 8"
 91        )
 92        c1.play(play(f=sp.record(i=2, j=2), t=sp.record(i=3, j=3)), _sender=player1)
 93        sc.verify(
 94            build_fen(c1)
 95            == "r1bqkb1r/pp1n1ppp/2n1p3/3pP3/3P1P2/5N2/PP4PP/R1BQKBNR b KQkq - 0 8"
 96        )
 97        c1.play(play(f=sp.record(i=6, j=5), t=sp.record(i=5, j=5)), _sender=player2)
 98        sc.verify(
 99            build_fen(c1)
100            == "r1bqkb1r/pp1n2pp/2n1pp2/3pP3/3P1P2/5N2/PP4PP/R1BQKBNR w KQkq - 0 9"
101        )
102        c1.play(play(f=sp.record(i=0, j=5), t=sp.record(i=2, j=3)), _sender=player1)
103        sc.verify(
104            build_fen(c1)
105            == "r1bqkb1r/pp1n2pp/2n1pp2/3pP3/3P1P2/3B1N2/PP4PP/R1BQK1NR b KQkq - 1 9"
106        )
107        c1.play(play(f=sp.record(i=7, j=5), t=sp.record(i=3, j=1)), _sender=player2)
108        sc.verify(
109            build_fen(c1)
110            == "r1bqk2r/pp1n2pp/2n1pp2/3pP3/1b1P1P2/3B1N2/PP4PP/R1BQK1NR w KQkq - 2 10"
111        )
112        #     sc.verify(c1.data.board_state.check == True)
113        c1.play(play(f=sp.record(i=0, j=2), t=sp.record(i=1, j=3)), _sender=player1)
114        #     sc.verify(c1.data.board_state.check == False)
115        sc.verify(
116            build_fen(c1)
117            == "r1bqk2r/pp1n2pp/2n1pp2/3pP3/1b1P1P2/3B1N2/PP1B2PP/R2QK1NR b KQkq - 3 10"
118        )
119        c1.play(play(f=sp.record(i=7, j=3), t=sp.record(i=5, j=1)), _sender=player2)
120        sc.verify(
121            build_fen(c1)
122            == "r1b1k2r/pp1n2pp/1qn1pp2/3pP3/1b1P1P2/3B1N2/PP1B2PP/R2QK1NR w KQkq - 4 11"
123        )
124        c1.play(play(f=sp.record(i=0, j=6), t=sp.record(i=1, j=4)), _sender=player1)
125        sc.verify(
126            build_fen(c1)
127            == "r1b1k2r/pp1n2pp/1qn1pp2/3pP3/1b1P1P2/3B1N2/PP1BN1PP/R2QK2R b KQkq - 5 11"
128        )
129        c1.play(play(f=sp.record(i=5, j=5), t=sp.record(i=4, j=4)), _sender=player2)
130        sc.verify(
131            build_fen(c1)
132            == "r1b1k2r/pp1n2pp/1qn1p3/3pp3/1b1P1P2/3B1N2/PP1BN1PP/R2QK2R w KQkq - 0 12"
133        )
134        c1.play(play(f=sp.record(i=3, j=5), t=sp.record(i=4, j=4)), _sender=player1)
135        sc.verify(
136            build_fen(c1)
137            == "r1b1k2r/pp1n2pp/1qn1p3/3pP3/1b1P4/3B1N2/PP1BN1PP/R2QK2R b KQkq - 0 12"
138        )
139        c1.play(
140            play(f=sp.record(i=7, j=4), t=sp.record(i=7, j=6)), _sender=player2
141        )  # Castle
142        sc.verify(
143            build_fen(c1)
144            == "r1b2rk1/pp1n2pp/1qn1p3/3pP3/1b1P4/3B1N2/PP1BN1PP/R2QK2R w KQ - 1 13"
145        )
146        c1.play(play(f=sp.record(i=1, j=0), t=sp.record(i=2, j=0)), _sender=player1)
147        c1.play(play(f=sp.record(i=3, j=1), t=sp.record(i=6, j=4)), _sender=player2)
148        c1.play(play(f=sp.record(i=0, j=3), t=sp.record(i=1, j=2)), _sender=player1)
149        c1.play(play(f=sp.record(i=7, j=5), t=sp.record(i=2, j=5)), _sender=player2)
150        c1.play(play(f=sp.record(i=1, j=6), t=sp.record(i=2, j=5)), _sender=player1)
151        c1.play(play(f=sp.record(i=5, j=2), t=sp.record(i=3, j=3)), _sender=player2)
152        c1.play(play(f=sp.record(i=1, j=4), t=sp.record(i=3, j=3)), _sender=player1)
153        c1.play(play(f=sp.record(i=5, j=1), t=sp.record(i=3, j=3)), _sender=player2)
154        c1.play(
155            play(f=sp.record(i=0, j=4), t=sp.record(i=0, j=2)), _sender=player1
156        )  # O-O-O
157        sc.verify(
158            build_fen(c1)
159            == "r1b3k1/pp1nb1pp/4p3/3pP3/3q4/P2B1P2/1PQB3P/2KR3R b - - 1 17"
160        )
161        c1.play(play(f=sp.record(i=6, j=3), t=sp.record(i=4, j=4)), _sender=player2)
162        c1.play(
163            play(f=sp.record(i=2, j=3), t=sp.record(i=6, j=7)), _sender=player1
164        )  # check
165        sc.verify(
166            build_fen(c1) == "r1b3k1/pp2b1pB/4p3/3pn3/3q4/P4P2/1PQB3P/2KR3R b - - 0 18"
167        )
168        sc.verify(c1.data.board_state.check == True)
169        c1.play(play(f=sp.record(i=7, j=6), t=sp.record(i=7, j=7)), _sender=player2)
170        sc.verify(c1.data.board_state.check == False)
171        c1.play(play(f=sp.record(i=0, j=2), t=sp.record(i=0, j=1)), _sender=player1)
172        c1.play(play(f=sp.record(i=3, j=3), t=sp.record(i=3, j=7)), _sender=player2)
173        c1.play(play(f=sp.record(i=1, j=3), t=sp.record(i=2, j=2)), _sender=player1)
174        c1.play(play(f=sp.record(i=6, j=4), t=sp.record(i=5, j=5)), _sender=player2)
175        c1.play(play(f=sp.record(i=2, j=5), t=sp.record(i=3, j=5)), _sender=player1)
176        c1.play(play(f=sp.record(i=4, j=4), t=sp.record(i=3, j=2)), _sender=player2)
177        c1.play(play(f=sp.record(i=2, j=2), t=sp.record(i=5, j=5)), _sender=player1)
178        c1.play(play(f=sp.record(i=3, j=7), t=sp.record(i=5, j=5)), _sender=player2)
179        c1.play(play(f=sp.record(i=6, j=7), t=sp.record(i=2, j=3)), _sender=player1)
180        c1.play(play(f=sp.record(i=6, j=1), t=sp.record(i=4, j=1)), _sender=player2)
181        c1.play(play(f=sp.record(i=1, j=2), t=sp.record(i=1, j=4)), _sender=player1)
182        c1.play(play(f=sp.record(i=7, j=2), t=sp.record(i=6, j=3)), _sender=player2)
183        c1.play(play(f=sp.record(i=0, j=7), t=sp.record(i=0, j=6)), _sender=player1)
184        c1.play(play(f=sp.record(i=6, j=3), t=sp.record(i=7, j=4)), _sender=player2)
185        c1.play(play(f=sp.record(i=0, j=3), t=sp.record(i=0, j=4)), _sender=player1)
186        c1.play(play(f=sp.record(i=7, j=4), t=sp.record(i=6, j=5)), _sender=player2)
187        sc.verify(
188            build_fen(c1) == "r6k/p4bp1/4pq2/1p1p4/2n2P2/P2B4/1P2Q2P/1K2R1R1 w - - 6 27"
189        )
190        c1.play(play(f=sp.record(i=0, j=6), t=sp.record(i=2, j=6)), _sender=player1)
191        c1.play(play(f=sp.record(i=7, j=0), t=sp.record(i=7, j=2)), _sender=player2)
192        c1.play(play(f=sp.record(i=0, j=4), t=sp.record(i=0, j=6)), _sender=player1)
193        c1.play(play(f=sp.record(i=3, j=2), t=sp.record(i=5, j=3)), _sender=player2)
194        c1.play(play(f=sp.record(i=2, j=6), t=sp.record(i=6, j=6)), _sender=player1)
195        c1.play(play(f=sp.record(i=5, j=3), t=sp.record(i=4, j=5)), _sender=player2)
196        c1.play(play(f=sp.record(i=6, j=6), t=sp.record(i=4, j=6)), _sender=player1)
197        c1.play(play(f=sp.record(i=7, j=2), t=sp.record(i=6, j=2)), _sender=player2)
198        c1.play(play(f=sp.record(i=2, j=3), t=sp.record(i=4, j=5)), _sender=player1)
199        c1.play(play(f=sp.record(i=5, j=4), t=sp.record(i=4, j=5)), _sender=player2)
200        c1.play(
201            play(f=sp.record(i=4, j=6), t=sp.record(i=4, j=7)), _sender=player1
202        )  # Abandon
203        sc.show(build_fen(c1))
204        sc.verify(
205            build_fen(c1) == "7k/p1r2b2/5q2/1p1p1p1R/5P2/P7/1P2Q2P/1K4R1 b - - 1 32"
206        )
207        sc.verify(c1.data.board_state.check == True)
208        c1.play(play(f=sp.record(i=6, j=5), t=sp.record(i=4, j=7)), _sender=player2)
209        c1.play(play(f=sp.record(i=1, j=4), t=sp.record(i=4, j=7)), _sender=player1)
210        sc.show(build_fen(c1))
211        c1.play(play(f=sp.record(i=5, j=5), t=sp.record(i=5, j=7)), _sender=player2)
212        c1.play(play(f=sp.record(i=4, j=7), t=sp.record(i=5, j=7)), _sender=player1)
213        c1.play(play(f=sp.record(i=6, j=2), t=sp.record(i=6, j=7)), _sender=player2)
214        c1.play(play(f=sp.record(i=5, j=7), t=sp.record(i=7, j=5)), _sender=player1)