|
@@ -658,6 +658,34 @@ async def chess_start_handler(chess, id):
|
|
|
return [svg2png(chess.svg(id))]
|
|
|
|
|
|
|
|
|
+async def chess_from_handler(chess, id, moves):
|
|
|
+ try:
|
|
|
+ await chess.begin(id, moves)
|
|
|
+ except GameOver as e:
|
|
|
+ board = svg2png(chess.svg(id))
|
|
|
+
|
|
|
+ await chess.end(id)
|
|
|
+
|
|
|
+ return [
|
|
|
+ board,
|
|
|
+ f"Конец игры: {str(e)}",
|
|
|
+ ]
|
|
|
+ except IllegalMove as e:
|
|
|
+ move = str(e)
|
|
|
+
|
|
|
+ if move:
|
|
|
+ return [f"Некорректный ход: {move}"]
|
|
|
+
|
|
|
+ return ["Некорректный последовательность ходов."]
|
|
|
+
|
|
|
+ reply = [svg2png(chess.svg(id))]
|
|
|
+
|
|
|
+ if chess.is_check(id):
|
|
|
+ reply.append("Шах!")
|
|
|
+
|
|
|
+ return reply
|
|
|
+
|
|
|
+
|
|
|
async def chess_stop_handler(chess, id):
|
|
|
if await chess.end(id):
|
|
|
return ["Игра завершена."]
|
|
@@ -784,6 +812,7 @@ async def chess_moves_handler(chess, id):
|
|
|
|
|
|
CHESS_COMMANDS = {
|
|
|
"start": (chess_start_handler, "Начать новую игру", 0),
|
|
|
+ "from": (chess_from_handler, "Начать новую игру с доской в указанном состоянии", 1),
|
|
|
"end": (chess_stop_handler, "Завершить игру", 0),
|
|
|
"move": (chess_move_handler, "Сделать ход", 1),
|
|
|
"undo": (chess_undo_handler, "Отменить ход", 0),
|