FlameF0X commited on
Commit
ce00937
·
verified ·
1 Parent(s): e6c9190

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -9
src/streamlit_app.py CHANGED
@@ -252,12 +252,15 @@ if not board.is_game_over() and board.turn == chess.WHITE:
252
  st.rerun()
253
 
254
  if not board.is_game_over() and board.turn == chess.BLACK:
255
- ai_name = "o2" if agent_loaded else "Random AI"
256
- st.write(f"### {ai_name}'s Turn (Black)")
257
- with st.spinner(f"{ai_name} is thinking..."):
258
  try:
259
  if agent_loaded and agent:
260
- move = agent.select_move(board, use_mcts=True, simulations=30)
 
 
 
 
261
  else:
262
  legal_moves = list(board.legal_moves)
263
  move = random.choice(legal_moves) if legal_moves else None
@@ -265,14 +268,12 @@ if not board.is_game_over() and board.turn == chess.BLACK:
265
  move_san = board.san(move)
266
  board.push(move)
267
  history.append(move.uci())
268
- render_board() # Update board immediately
269
- render_pgn() # Update PGN immediately
270
- st.success(f"{ai_name} played: {move_san} ({move.uci()})")
271
  st.rerun()
272
  else:
273
- st.error(f"{ai_name} couldn't find a valid move")
274
  except Exception as e:
275
- st.error(f"Error during {ai_name} move: {e}")
276
 
277
  if board.is_game_over():
278
  st.write("### Game Over!")
 
252
  st.rerun()
253
 
254
  if not board.is_game_over() and board.turn == chess.BLACK:
255
+ st.write("### o2's Turn (Black)")
256
+ with st.spinner("o2 is thinking..."):
 
257
  try:
258
  if agent_loaded and agent:
259
+ # Use temperature sampling for first 10 moves, then greedy
260
+ if len(history) < 20: # 10 moves per side
261
+ move = agent.select_move(board, use_mcts=True, simulations=30, temperature=1.2)
262
+ else:
263
+ move = agent.select_move(board, use_mcts=True, simulations=30, temperature=0.0)
264
  else:
265
  legal_moves = list(board.legal_moves)
266
  move = random.choice(legal_moves) if legal_moves else None
 
268
  move_san = board.san(move)
269
  board.push(move)
270
  history.append(move.uci())
271
+ st.success(f"o2 played: {move_san} ({move.uci()})")
 
 
272
  st.rerun()
273
  else:
274
+ st.error("o2 couldn't find a valid move")
275
  except Exception as e:
276
+ st.error(f"Error during o2 move: {e}")
277
 
278
  if board.is_game_over():
279
  st.write("### Game Over!")