|
@@ -663,12 +663,6 @@ def chess_render(chess, id, as_list=True):
|
|
|
return board
|
|
|
|
|
|
|
|
|
-async def chess_start_handler(chess, id):
|
|
|
- await chess.begin(id)
|
|
|
-
|
|
|
- return chess_render(chess, id)
|
|
|
-
|
|
|
-
|
|
|
def chess_game_stats(chess, id):
|
|
|
if not chess.has_moves(id):
|
|
|
return "Ходов ещё не сделано."
|
|
@@ -691,6 +685,12 @@ def chess_game_over(chess, id, e):
|
|
|
]
|
|
|
|
|
|
|
|
|
+async def chess_start_handler(chess, id):
|
|
|
+ await chess.begin(id)
|
|
|
+
|
|
|
+ return chess_render(chess, id)
|
|
|
+
|
|
|
+
|
|
|
async def chess_from_handler(chess, id, moves):
|
|
|
try:
|
|
|
await chess.begin(id, moves, strict=not isinstance(id, str))
|
|
@@ -763,6 +763,8 @@ async def chess_undo_handler(chess, id):
|
|
|
return ["Нет активной игры."]
|
|
|
except IndexError:
|
|
|
return ["Нечего отменять."]
|
|
|
+ except GameOver as e:
|
|
|
+ return chess_game_over(chess, id, e)
|
|
|
|
|
|
return ["Последний ход отменён.", svg2png(chess.svg(id))]
|
|
|
|
|
@@ -809,8 +811,12 @@ async def chess_pass_handler(chess, id):
|
|
|
return reply
|
|
|
|
|
|
|
|
|
-async def chess_board_handler(chess, id):
|
|
|
+async def chess_board_handler(chess, id):
|
|
|
try:
|
|
|
+ e = chess.game_over(id)
|
|
|
+ if e is not None:
|
|
|
+ return chess_game_over(chess, id, e)
|
|
|
+
|
|
|
reply = chess_render(chess, id)
|
|
|
except KeyError:
|
|
|
return ["Нет активной игры."]
|
|
@@ -826,6 +832,10 @@ async def chess_board_handler(chess, id):
|
|
|
|
|
|
async def chess_moves_handler(chess, id):
|
|
|
try:
|
|
|
+ e = chess.game_over(id)
|
|
|
+ if e is not None:
|
|
|
+ return chess_game_over(chess, id, e)
|
|
|
+
|
|
|
text = chess_game_stats(chess, id)
|
|
|
except KeyError:
|
|
|
return ["Нет активной игры."]
|