jrahn commited on
Commit
47944b0
·
verified ·
1 Parent(s): d0e30f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
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
- svg_string = create_chess_board_svg(new_state)
 
 
 
 
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 ""