Xmaster6y commited on
Commit
c82f95d
·
unverified ·
1 Parent(s): 43bfbc6

orientation last

Browse files
Files changed (1) hide show
  1. src/play_interface.py +9 -3
src/play_interface.py CHANGED
@@ -1,6 +1,8 @@
1
  """Interface to play against the model.
2
  """
3
 
 
 
4
  import huggingface_hub
5
  import chess
6
  import chess.svg
@@ -22,6 +24,7 @@ inference_fn = client.text_generation
22
 
23
  def plot_board(
24
  board: chess.Board,
 
25
  ):
26
  try:
27
  last_move = board.peek()
@@ -34,7 +37,7 @@ def plot_board(
34
  check = None
35
  svg_board = chess.svg.board(
36
  board,
37
- orientation=board.turn,
38
  check=check,
39
  size=350,
40
  arrows=arrows,
@@ -46,10 +49,13 @@ def plot_board(
46
 
47
  def render_board(
48
  current_board: chess.Board,
 
49
  ):
50
  fen = current_board.fen()
51
  pgn = current_board.root().variation_san(current_board.move_stack)
52
- image_board = plot_board(current_board)
 
 
53
  return fen, pgn, "", image_board
54
 
55
  def play_user_move(
@@ -91,7 +97,7 @@ def try_play_move(
91
  }
92
  )
93
  run.finish()
94
- return *render_board(current_board), current_board
95
  except:
96
  gr.Warning("Invalid move")
97
  return *render_board(current_board), current_board
 
1
  """Interface to play against the model.
2
  """
3
 
4
+ from typing import Optional
5
+
6
  import huggingface_hub
7
  import chess
8
  import chess.svg
 
24
 
25
  def plot_board(
26
  board: chess.Board,
27
+ orientation: bool = chess.WHITE,
28
  ):
29
  try:
30
  last_move = board.peek()
 
37
  check = None
38
  svg_board = chess.svg.board(
39
  board,
40
+ orientation=orientation,
41
  check=check,
42
  size=350,
43
  arrows=arrows,
 
49
 
50
  def render_board(
51
  current_board: chess.Board,
52
+ orientation: Optional[bool] = chess.WHITE,
53
  ):
54
  fen = current_board.fen()
55
  pgn = current_board.root().variation_san(current_board.move_stack)
56
+ if orientation is None:
57
+ orientation = current_board.turn
58
+ image_board = plot_board(current_board, orientation=orientation)
59
  return fen, pgn, "", image_board
60
 
61
  def play_user_move(
 
97
  }
98
  )
99
  run.finish()
100
+ return *render_board(current_board, orientation=not current_board.turn), current_board
101
  except:
102
  gr.Warning("Invalid move")
103
  return *render_board(current_board), current_board