Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- 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 |
-
|
256 |
-
st.
|
257 |
-
with st.spinner(f"{ai_name} is thinking..."):
|
258 |
try:
|
259 |
if agent_loaded and agent:
|
260 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
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(
|
274 |
except Exception as e:
|
275 |
-
st.error(f"Error during
|
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!")
|