Update app.py
Browse files
app.py
CHANGED
@@ -86,17 +86,21 @@ def step_episode(inputs):
|
|
86 |
gr.Info(f"Environment ended game: ILLEGAL_MOVE", duration=None)
|
87 |
svg_string = create_chess_board_svg()
|
88 |
return svg_string, START_POSITION, "", [START_POSITION, []]
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
91 |
if not svg_string:
|
92 |
svg_string = create_chess_board_svg()
|
93 |
return svg_string, [START_POSITION, []], START_POSITION, ""
|
94 |
return svg_string, new_state, ", ".join(history), [new_state, history]
|
95 |
|
96 |
-
def create_chess_board_svg(fen=None):
|
97 |
try:
|
98 |
board = chess.Board(fen) if fen else chess.Board()
|
99 |
-
return chess.svg.board(board, size=400)
|
100 |
except:
|
101 |
gr.Info(f"Python-Chess board visualization cannot be rendered from FEN: {fen}", duration=None)
|
102 |
return ""
|
|
|
86 |
gr.Info(f"Environment ended game: ILLEGAL_MOVE", duration=None)
|
87 |
svg_string = create_chess_board_svg()
|
88 |
return svg_string, START_POSITION, "", [START_POSITION, []]
|
89 |
+
|
90 |
+
try:
|
91 |
+
mv = chess.Move.from_uci(action)
|
92 |
+
svg_string = create_chess_board_svg(new_state, lastmove=mv)
|
93 |
+
except:
|
94 |
+
svg_string = create_chess_board_svg(new_state)
|
95 |
if not svg_string:
|
96 |
svg_string = create_chess_board_svg()
|
97 |
return svg_string, [START_POSITION, []], START_POSITION, ""
|
98 |
return svg_string, new_state, ", ".join(history), [new_state, history]
|
99 |
|
100 |
+
def create_chess_board_svg(fen=None, lastmove=None):
|
101 |
try:
|
102 |
board = chess.Board(fen) if fen else chess.Board()
|
103 |
+
return chess.svg.board(board, lastmove=lastmove, size=400)
|
104 |
except:
|
105 |
gr.Info(f"Python-Chess board visualization cannot be rendered from FEN: {fen}", duration=None)
|
106 |
return ""
|