make it use a different stockfish, because I do not have the capability to install…
- User
make it use a different stockfish, because I do not have the capability to install stockfish
- Assistant
Absolutely! If you cannot install Stockfish on PythonAnywhere (which is common for free accounts), you have two main options:
1. Use the Lichess Cloud Analysis API as a Stockfish replacement
Lichess provides a free API to get Stockfish evaluations and best moves.
You can send a FEN and get the best move at a given depth.Example: Using Lichess Cloud Analysis in Flask
Add this endpoint to your
flask_app.py:import requests @app.route("/play_stockfish", methods=["POST"]) def play_stockfish(): fen = request.json["fen"] # Lichess API: https://lichess.org/api/cloud-eval?fen=<FEN>&multiPv=1&depth=12 url = f"https://lichess.org/api/cloud-eval?fen={fen}&multiPv=1&depth=12" resp = requests.get(url) if resp.status_code == 200: data = resp.json() # Get the best move in UCI format best_move = data.get("pvs", [{}])[0].get("moves", "").split()[0] return jsonify({"move": best_move}) else: return jsonify({"move": None, "error": "Lichess API error"}), 500- You can adjust
depth=12todepth=2for faster but weaker moves. - This does not require Stockfish installed locally.
Don't forget to add
requeststo your requirements:pip install requests
2. Remove Stockfish and only use your bot
If you only want to play against your bot, just remove all Stockfish code and endpoints.
3. How to use the Lichess API from your frontend
Add a button in your
index.html:<button onclick="playStockfish()">Play Stockfish Move</button>And add this JS function:
function playStockfish() { fetch('/play_stockfish', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fen: game.fen() }) }) .then(response => response.json()) .then(data => { if (data.move) { game.move(data.move); board.position(game.fen()); } else { alert("Stockfish move not available."); } }); }
Summary
- No Stockfish install needed.
- Use the
/play_stockfishendpoint as above. - Use the Lichess API for strong engine moves.
Let me know if you want the full, ready-to-paste code for your Flask app and frontend!
- You can adjust
- User
i still can't see the board.
- Assistant
Let's fix your chessboard display!
The most common reasons for a blank board on PythonAnywhere are:- Missing or incorrect JavaScript/CSS includes (especially for
chessboard.jsandchess.js) - Not using HTTPS for CDN links (PythonAnywhere serves your site over HTTPS)
- Not having a container for the board
- JavaScript errors (check browser console)
Below is a minimal, working HTML example for PythonAnywhere, using the official chessboard.js CDN and chess.js.
Copy and paste this as yourindex.htmland it should work.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Chessboard Demo</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Official chessboard.js CDN --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css" /> <style> #board { width: 400px; margin: 20px auto; } </style> </head> <body> <h1>Chessboard.js Demo</h1> <div id="board"></div> <button onclick="resetBoard()">Reset</button> <!-- chess.js for game logic --> <script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.13.4/chess.min.js"></script> <!-- chessboard.js for board display --> <script src="https://cdn.jsdelivr.net/npm/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.js"></script> <script> var board = Chessboard('board', { draggable: true, dropOffBoard: 'snapback', position: 'start' }); function resetBoard() { board.start(); } </script> </body> </html>
Checklist
- Use the above code as your
index.html. - Make sure your Flask route is:
@app.route("/") def home(): return render_template("index.html") - Reload your PythonAnywhere web app after saving changes.
- Open your site in a new browser tab (sometimes cache can interfere).
If you still don't see the board:
- Open your browser's developer console (F12) and check for errors.
- Make sure your
index.htmlis in the correct templates folder (usually/home/nogra/mysite/templates/on PythonAnywhere). - Make sure your Flask app is running and serving the correct template.
If you want the board to interact with your Flask backend, you can build on this working example.
Let me know if you want a full working Flask+chessboard.js+chess.js example! - Missing or incorrect JavaScript/CSS includes (especially for
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.