|
@@ -13,10 +13,6 @@ class IllegalMove(Exception):
|
|
|
pass
|
|
|
|
|
|
|
|
|
-def outcome_to_str(outcome):
|
|
|
- return f"{outcome.result()}: {outcome.termination.name}"
|
|
|
-
|
|
|
-
|
|
|
class ChessSession:
|
|
|
def __init__(self, engine):
|
|
|
self.engine = engine
|
|
@@ -27,11 +23,13 @@ class ChessSession:
|
|
|
|
|
|
def check_game_over(self):
|
|
|
if self.board.is_game_over():
|
|
|
- raise GameOver(f"{outcome_to_str(self.board.outcome())} [{len(self.board.move_stack)}]")
|
|
|
+ outcome = self.board.outcome()
|
|
|
+
|
|
|
+ raise GameOver(f"{outcome.result()} {outcome.termination.name}")
|
|
|
elif self.board.status() & chess.STATUS_NO_WHITE_KING:
|
|
|
- raise GameOver(f"0-1 CHECKMATE [{len(self.board.move_stack)}]")
|
|
|
+ raise GameOver(f"0-1 CHECKMATE")
|
|
|
elif self.board.status() & chess.STATUS_NO_BLACK_KING:
|
|
|
- raise GameOver(f"1-0 CHECKMATE [{len(self.board.move_stack)}]")
|
|
|
+ raise GameOver(f"1-0 CHECKMATE")
|
|
|
elif not self.board.is_valid():
|
|
|
raise GameOver(f"Некорректное состояние доски.")
|
|
|
|
|
@@ -133,10 +131,15 @@ class ChessManager:
|
|
|
if len(session.board.move_stack) > 1 and session.board.move_stack[-2] != chess.Move.null():
|
|
|
arrows.append((session.board.move_stack[-2].from_square, session.board.move_stack[-2].to_square))
|
|
|
|
|
|
+ move = None
|
|
|
+
|
|
|
+ if self.board.attackers_mask(chess.WHITE, self.board.king(chess.BLACK)) != 0:
|
|
|
+ move = self.board.king(chess.BLACK)
|
|
|
+
|
|
|
if session.board.is_check():
|
|
|
- return chess.svg.board(session.board, size=size, arrows=arrows, fill={checker: "#cc0000cc" for checker in session.board.checkers()}, check=session.board.king(session.board.turn))
|
|
|
+ return chess.svg.board(session.board, size=size, lastmove=move, arrows=arrows, fill={checker: "#cc0000cc" for checker in session.board.checkers()}, check=session.board.king(session.board.turn))
|
|
|
|
|
|
- return chess.svg.board(session.board, size=size, arrows=arrows)
|
|
|
+ return chess.svg.board(session.board, size=size, lastmove=move, arrows=arrows)
|
|
|
|
|
|
def ascii(self, id):
|
|
|
session = self.sessions.get(id)
|
|
@@ -169,4 +172,4 @@ class ChessManager:
|
|
|
else:
|
|
|
moves = session.board.move_stack
|
|
|
|
|
|
- return " ".join(map(str, moves))
|
|
|
+ return " ".join(map(lambda m: "пропуск" if m == chess.Move.null() else str(m), moves))
|