Xmaster6y commited on
Commit
d053bab
·
unverified ·
1 Parent(s): dd4125a

random move play

Browse files
Files changed (1) hide show
  1. src/play_interface.py +8 -3
src/play_interface.py CHANGED
@@ -61,13 +61,11 @@ def play_user_move(
61
  def play_ai_move(
62
  current_board: chess.Board,
63
  temperature: float = 0.1,
64
- top_k: int = 3,
65
  ):
66
  print(f"Playing AI move with temperature {temperature}")
67
  uci_move = inference_fn(
68
  prompt=f"FEN: {current_board.fen()}\nMOVE:",
69
  temperature=temperature,
70
- top_k=top_k,
71
  )
72
  current_board.push_uci(uci_move.strip())
73
  return current_board
@@ -108,7 +106,9 @@ def try_play_move(
108
  gr.Warning(f"AI move failed with temperature {temperature}")
109
  else:
110
  gr.Warning("AI move failed with all temperatures")
111
- current_board.pop()
 
 
112
  return *render_board(current_board), current_board
113
  return *render_board(current_board), current_board
114
 
@@ -165,6 +165,11 @@ with gr.Blocks() as interface:
165
  inputs=[*static_inputs, state_board],
166
  outputs=[*static_outputs, state_board],
167
  )
 
 
 
 
 
168
 
169
  def reset_board():
170
  board = chess.Board()
 
61
  def play_ai_move(
62
  current_board: chess.Board,
63
  temperature: float = 0.1,
 
64
  ):
65
  print(f"Playing AI move with temperature {temperature}")
66
  uci_move = inference_fn(
67
  prompt=f"FEN: {current_board.fen()}\nMOVE:",
68
  temperature=temperature,
 
69
  )
70
  current_board.push_uci(uci_move.strip())
71
  return current_board
 
106
  gr.Warning(f"AI move failed with temperature {temperature}")
107
  else:
108
  gr.Warning("AI move failed with all temperatures")
109
+ random_move = random.choice(list(current_board.legal_moves))
110
+ gr.Warning(f"Playing random move {random_move}")
111
+ current_board.push(random_move)
112
  return *render_board(current_board), current_board
113
  return *render_board(current_board), current_board
114
 
 
165
  inputs=[*static_inputs, state_board],
166
  outputs=[*static_outputs, state_board],
167
  )
168
+ move_to_play.submit(
169
+ try_play_move,
170
+ inputs=[*static_inputs, state_board],
171
+ outputs=[*static_outputs, state_board],
172
+ )
173
 
174
  def reset_board():
175
  board = chess.Board()