Spaces:
Runtime error
Runtime error
File size: 1,798 Bytes
90166f0 483a71b ab97e59 90166f0 ab97e59 90166f0 ab97e59 90166f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import chess
import gradio as gr
from stockfish import Stockfish
# Use local stockfish binary included in the repo (make sure it's chmod +x)
stockfish = Stockfish(path="./stockfish", depth=18, parameters={
"Threads": 2,
"Minimum Thinking Time": 30
})
board = chess.Board()
def make_move(move_uci):
global board
if board.is_game_over():
return board.fen(), "Game over. Reset to play again."
try:
move = chess.Move.from_uci(move_uci)
if move in board.legal_moves:
board.push(move)
return board.fen(), "Move played"
else:
return board.fen(), "Illegal move"
except:
return board.fen(), "Invalid move format (e.g., e2e4)"
def get_cheat_move():
stockfish.set_fen_position(board.fen())
best = stockfish.get_best_move()
return best
def reset_board():
global board
board = chess.Board()
return board.fen(), "Board reset"
with gr.Blocks() as demo:
gr.Markdown("## ♟️ Chess Wizard: Grandmaster Cheat Assistant")
gr.Markdown("Play legal chess with discreet Stockfish-powered move suggestions.")
move_input = gr.Textbox(label="Your Move (e.g., e2e4)")
move_btn = gr.Button("Make Move")
cheat_btn = gr.Button("Suggest Best Move")
reset_btn = gr.Button("Reset Board")
board_output = gr.Textbox(label="Current Board FEN", value=board.fen(), interactive=False)
status_output = gr.Textbox(label="Status", interactive=False)
cheat_output = gr.Textbox(label="Cheat Move Suggestion", interactive=False)
move_btn.click(fn=make_move, inputs=move_input, outputs=[board_output, status_output])
cheat_btn.click(fn=get_cheat_move, outputs=cheat_output)
reset_btn.click(fn=reset_board, outputs=[board_output, status_output])
demo.launch()
|