|
@@ -14,7 +14,10 @@ class IllegalMove(Exception):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
-def board2svg(board, size=256, shallow=False):
|
|
|
|
|
|
+def board2svg(board, size=256, shallow=False, orientation=None):
|
|
|
|
+ if orientation is None:
|
|
|
|
+ orientation = board.turn
|
|
|
|
+
|
|
arrows = []
|
|
arrows = []
|
|
if board.move_stack and board.move_stack[-1] != chess.Move.null():
|
|
if board.move_stack and board.move_stack[-1] != chess.Move.null():
|
|
arrows.append((board.move_stack[-1].from_square, board.move_stack[-1].to_square))
|
|
arrows.append((board.move_stack[-1].from_square, board.move_stack[-1].to_square))
|
|
@@ -23,9 +26,9 @@ def board2svg(board, size=256, shallow=False):
|
|
arrows.append((board.move_stack[-2].from_square, board.move_stack[-2].to_square))
|
|
arrows.append((board.move_stack[-2].from_square, board.move_stack[-2].to_square))
|
|
|
|
|
|
if board.is_check():
|
|
if board.is_check():
|
|
- return chess.svg.board(board, orientation=board.turn, size=size, arrows=arrows, fill={checker: "#cc0000cc" for checker in board.checkers()}, check=board.king(board.turn))
|
|
|
|
|
|
+ return chess.svg.board(board, orientation=orientation, size=size, arrows=arrows, fill={checker: "#cc0000cc" for checker in board.checkers()}, check=board.king(board.turn))
|
|
|
|
|
|
- return chess.svg.board(board, orientation=board.turn, size=size, arrows=arrows)
|
|
|
|
|
|
+ return chess.svg.board(board, orientation=orientation, size=size, arrows=arrows)
|
|
|
|
|
|
|
|
|
|
class ChessSession:
|
|
class ChessSession:
|
|
@@ -219,7 +222,7 @@ class ChessManager:
|
|
|
|
|
|
return session.board.turn
|
|
return session.board.turn
|
|
|
|
|
|
- def animate(self, id, count=2, size=256, shallow=False):
|
|
|
|
|
|
+ def animate(self, id, count=None, size=256, shallow=False):
|
|
session = self.sessions.get(id)
|
|
session = self.sessions.get(id)
|
|
if not session:
|
|
if not session:
|
|
raise KeyError(id)
|
|
raise KeyError(id)
|
|
@@ -227,11 +230,14 @@ class ChessManager:
|
|
board = chess.Board()
|
|
board = chess.Board()
|
|
frames = []
|
|
frames = []
|
|
|
|
|
|
- frames.append(board2svg(board, size=size, shallow=shallow))
|
|
|
|
|
|
+ frames.append(board2svg(board, size=size, shallow=shallow, orientation=chess.WHITE))
|
|
|
|
|
|
for move in session.board.move_stack:
|
|
for move in session.board.move_stack:
|
|
board.push(move)
|
|
board.push(move)
|
|
|
|
|
|
- frames.append(board2svg(board, size=size, shallow=shallow))
|
|
|
|
|
|
+ frames.append(board2svg(board, size=size, shallow=shallow, orientation=chess.WHITE))
|
|
|
|
+
|
|
|
|
+ if count is not None and len(frames) >= count:
|
|
|
|
+ break
|
|
|
|
|
|
return frames
|
|
return frames
|