Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def engine_limit(state):
|
|
| 69 |
return chess.engine.Limit(time=max(0.05, state["movetime_ms"]/1000.0))
|
| 70 |
|
| 71 |
def render(state):
|
| 72 |
-
svg = board_svg(state["board"], last_move=state["last_move
|
| 73 |
return svg_to_data_url(svg), state["board"].fen()
|
| 74 |
|
| 75 |
# -------- Acties --------
|
|
@@ -84,7 +84,6 @@ def make_move(state, user_move):
|
|
| 84 |
return state, *render(state), f"Partij is al afgelopen: {board.result()}."
|
| 85 |
|
| 86 |
try:
|
| 87 |
-
# UCI notatie (b.v. e2e4 of e7e8q)
|
| 88 |
mv = chess.Move.from_uci(user_move.strip())
|
| 89 |
if mv not in board.legal_moves:
|
| 90 |
return state, *render(state), "Ongeldige zet (niet legaal in deze stelling)."
|
|
@@ -97,7 +96,6 @@ def make_move(state, user_move):
|
|
| 97 |
img, fen = render(state)
|
| 98 |
return state, img, fen, f"Partij afgelopen: {board.result()}."
|
| 99 |
|
| 100 |
-
# engine aan zet?
|
| 101 |
side_to_move = "white" if board.turn == chess.WHITE else "black"
|
| 102 |
if side_to_move == state["engine_color"]:
|
| 103 |
msg = engine_move(state)
|
|
@@ -126,7 +124,6 @@ def undo_move(state):
|
|
| 126 |
board: chess.Board = state["board"]
|
| 127 |
if len(board.move_stack) == 0:
|
| 128 |
return state, *render(state), "Geen zetten om terug te nemen."
|
| 129 |
-
# Neem 1 of 2 zetten terug zodat jij weer aan zet bent
|
| 130 |
board.pop()
|
| 131 |
if state["engine_color"] == ("white" if board.turn == chess.WHITE else "black") and len(board.move_stack) > 0:
|
| 132 |
board.pop()
|
|
@@ -171,14 +168,12 @@ with gr.Blocks(title="Boss Chess (Stockfish)") as demo:
|
|
| 171 |
|
| 172 |
state = gr.State()
|
| 173 |
|
| 174 |
-
# Callbacks
|
| 175 |
btn_new.click(new_game, [engine_color, movetime, depth, threads, hash_mb],
|
| 176 |
[state, board_html, fen_out, status])
|
| 177 |
btn_move.click(make_move, [state, user_move], [state, board_html, fen_out, status])
|
| 178 |
btn_undo.click(undo_move, [state], [state, board_html, fen_out, status])
|
| 179 |
btn_resign.click(resign, [state], [state, board_html, fen_out, status])
|
| 180 |
|
| 181 |
-
# Auto-start een partij
|
| 182 |
demo.load(new_game, [engine_color, movetime, depth, threads, hash_mb],
|
| 183 |
[state, board_html, fen_out, status])
|
| 184 |
|
|
|
|
| 69 |
return chess.engine.Limit(time=max(0.05, state["movetime_ms"]/1000.0))
|
| 70 |
|
| 71 |
def render(state):
|
| 72 |
+
svg = board_svg(state["board"], last_move=state["last_move"])
|
| 73 |
return svg_to_data_url(svg), state["board"].fen()
|
| 74 |
|
| 75 |
# -------- Acties --------
|
|
|
|
| 84 |
return state, *render(state), f"Partij is al afgelopen: {board.result()}."
|
| 85 |
|
| 86 |
try:
|
|
|
|
| 87 |
mv = chess.Move.from_uci(user_move.strip())
|
| 88 |
if mv not in board.legal_moves:
|
| 89 |
return state, *render(state), "Ongeldige zet (niet legaal in deze stelling)."
|
|
|
|
| 96 |
img, fen = render(state)
|
| 97 |
return state, img, fen, f"Partij afgelopen: {board.result()}."
|
| 98 |
|
|
|
|
| 99 |
side_to_move = "white" if board.turn == chess.WHITE else "black"
|
| 100 |
if side_to_move == state["engine_color"]:
|
| 101 |
msg = engine_move(state)
|
|
|
|
| 124 |
board: chess.Board = state["board"]
|
| 125 |
if len(board.move_stack) == 0:
|
| 126 |
return state, *render(state), "Geen zetten om terug te nemen."
|
|
|
|
| 127 |
board.pop()
|
| 128 |
if state["engine_color"] == ("white" if board.turn == chess.WHITE else "black") and len(board.move_stack) > 0:
|
| 129 |
board.pop()
|
|
|
|
| 168 |
|
| 169 |
state = gr.State()
|
| 170 |
|
|
|
|
| 171 |
btn_new.click(new_game, [engine_color, movetime, depth, threads, hash_mb],
|
| 172 |
[state, board_html, fen_out, status])
|
| 173 |
btn_move.click(make_move, [state, user_move], [state, board_html, fen_out, status])
|
| 174 |
btn_undo.click(undo_move, [state], [state, board_html, fen_out, status])
|
| 175 |
btn_resign.click(resign, [state], [state, board_html, fen_out, status])
|
| 176 |
|
|
|
|
| 177 |
demo.load(new_game, [engine_color, movetime, depth, threads, hash_mb],
|
| 178 |
[state, board_html, fen_out, status])
|
| 179 |
|