#!/usr/bin/env python3
import os
import chess, chess.svg
game = (
"6n1/8/2K5/5N2/4k3/8/3Pq3/2Q2R2 b - - 0 1",
"6n1/8/2K5/5N1q/4k3/8/3P4/2Q2R2 w - - 1 2",
"6n1/8/2K5/5N1q/3Pk3/8/8/2Q2R2 b - - 0 2",
"6n1/8/2K5/5N1q/2QPk3/8/8/5R2 b - - 0 2",
"6n1/8/2K5/2Q2N1q/3Pk3/8/8/5R2 b - - 0 2",
"6n1/8/2K5/2QP1N1q/4k3/8/8/5R2 b - - 0 2",
"5Qn1/8/2K5/3P1N1q/4k3/8/8/5R2 b - - 1 2",
"5Qn1/8/2KP4/5N1q/4k3/8/8/5R2 b - - 0 2",
"2Q3n1/8/2KP4/5N1q/4k3/8/8/5R2 b - - 1 2",
"2Q3n1/3P4/2K5/5N1q/4k3/8/8/5R2 b - - 0 2",
"2Q5/3Pn3/2K5/5N1q/4k3/8/8/5R2 w - - 1 3",
"2Q5/3PN3/2K5/7q/4k3/8/8/5R2 b - - 0 3",
"2Q5/3P4/2K5/5N1q/4k3/8/8/5R2 b - - 1 3",
"2QQ4/8/2K5/5N1q/4k3/8/8/5R2 b - - 0 3",
"2QQq3/8/2K5/5N2/4k3/8/8/5R2 w - - 1 4",
"3Qq3/8/Q1K5/5N2/4k3/8/8/5R2 w - - 1 4",
"4Q3/8/Q1K5/5N2/4k3/8/8/5R2 b - - 0 4",
)
arrows = (
(chess.E2, chess.H5),
(chess.D2, chess.D4),
(chess.C1, chess.C4),
(chess.C4, chess.C5),
(chess.D4, chess.D5),
(chess.C5, chess.F8),
(chess.D5, chess.D6),
(chess.F8, chess.C8),
(chess.D6, chess.D7),
(chess.G8, chess.E7),
(chess.F5, chess.E7),
(chess.E7, chess.F5),
(chess.D7, chess.D8),
(chess.H5, chess.E8),
(chess.C8, chess.A6),
(chess.D8, chess.E8),
)
def svg(i):
board = chess.Board(game[i - 1])
if i > 1:
a = [arrows[i - 2]]
else:
a = []
s = chess.svg.board(board, arrows = a, size = 800)
f1 = "g_%04u.svg" % i
f2 = "g_%04u.png" % i
with open(f1, 'w') as f:
f.write(s)
os.system("convert %s %s" % (f1, f2))
os.system("rm %s" % f1)
i = 1
for m in range(len(game)):
svg(i)
i += 1
# create animation with
# convert -delay 150 g_*.png -loop 0 g.gif