FlameF0X commited on
Commit
af8e4a4
·
verified ·
1 Parent(s): 21f27c9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +14 -14
src/streamlit_app.py CHANGED
@@ -18,8 +18,6 @@ import io
18
  import base64
19
  import chess.pgn
20
  import random
21
- import tempfile
22
- import shutil
23
  from huggingface_hub import hf_hub_download
24
 
25
  # Hugging Face model config
@@ -70,21 +68,22 @@ def parse_move_input(move_input, board):
70
 
71
  # Try UCI
72
  try:
73
- move = chess.Move.from_uci(move_input.lower())
74
- if move in board.legal_moves:
75
- return move
76
- except Exception as e:
77
- st.info(f"UCI parsing failed: {e}")
 
78
 
79
  # Try SAN
80
  try:
81
  move = board.parse_san(move_input)
82
  if move in board.legal_moves:
83
  return move
84
- except Exception as e:
85
- st.info(f"SAN parsing failed: {e}")
86
 
87
- # Try castling aliases
88
  castling_variations = {
89
  '0-0': 'O-O', '0-0-0': 'O-O-O',
90
  'oo': 'O-O', 'ooo': 'O-O-O',
@@ -96,8 +95,8 @@ def parse_move_input(move_input, board):
96
  move = board.parse_san(normalized)
97
  if move in board.legal_moves:
98
  return move
99
- except Exception as e:
100
- st.info(f"Castling parsing failed: {e}")
101
 
102
  return None
103
 
@@ -189,7 +188,7 @@ if not board.is_game_over() and board.turn == chess.WHITE:
189
  render_pgn()
190
  st.rerun()
191
  else:
192
- st.warning("Invalid move. Try again using SAN (e.g., `e4`, `Nf3`, `O-O`) or UCI (e.g., `e2e4`).")
193
  if st.button("Random Move"):
194
  move = random.choice(legal_moves)
195
  board.push(move)
@@ -207,9 +206,10 @@ if not board.is_game_over() and board.turn == chess.BLACK:
207
  else:
208
  move = random.choice(list(board.legal_moves))
209
  if move:
 
210
  board.push(move)
211
  history.append(move.uci())
212
- st.success(f"o2 played: {board.san(move)}")
213
  st.rerun()
214
  except Exception as e:
215
  st.error(f"AI error: {e}")
 
18
  import base64
19
  import chess.pgn
20
  import random
 
 
21
  from huggingface_hub import hf_hub_download
22
 
23
  # Hugging Face model config
 
68
 
69
  # Try UCI
70
  try:
71
+ if len(move_input) in (4, 5):
72
+ move = chess.Move.from_uci(move_input.lower())
73
+ if move in board.legal_moves:
74
+ return move
75
+ except:
76
+ pass
77
 
78
  # Try SAN
79
  try:
80
  move = board.parse_san(move_input)
81
  if move in board.legal_moves:
82
  return move
83
+ except:
84
+ pass
85
 
86
+ # Castling aliases
87
  castling_variations = {
88
  '0-0': 'O-O', '0-0-0': 'O-O-O',
89
  'oo': 'O-O', 'ooo': 'O-O-O',
 
95
  move = board.parse_san(normalized)
96
  if move in board.legal_moves:
97
  return move
98
+ except:
99
+ pass
100
 
101
  return None
102
 
 
188
  render_pgn()
189
  st.rerun()
190
  else:
191
+ st.warning("Invalid move. Use standard algebraic notation (e.g., `e4`, `Nf3`, `O-O`) or UCI (e.g., `e2e4`).")
192
  if st.button("Random Move"):
193
  move = random.choice(legal_moves)
194
  board.push(move)
 
206
  else:
207
  move = random.choice(list(board.legal_moves))
208
  if move:
209
+ san_move = board.san(move) # FIX: Get SAN before pushing
210
  board.push(move)
211
  history.append(move.uci())
212
+ st.success(f"o2 played: {san_move}")
213
  st.rerun()
214
  except Exception as e:
215
  st.error(f"AI error: {e}")