StockfishWeb is high level wrapper with a Web layer on top of Stockfish, the world strongest UCI chess engine. Implemented as a Spring Boot app, StockfishWeb exposes internal Stockfish functionality through REST API. Additionally, it allows to validate chess positions represented by FEN string, and build your own FEN string by positioning pieces on the virtual chess board.
To build and run StockfishWeb, maven (3.9+) and java (17+) are required.
mvn package
or to speed things up by skipping all tests
mvn -DskipTests package
if there are no error during the build, you can proceed with
mvn spring-boot:run
If you see a Spring logo with the Spring Boot version (i.e. 3.2.3) at the end of your console output, you can proceed with
In your browser, hit your localhost URL i.e.
http://localhost
and you should see the page below:
Now you can do the following:
- Executing REST queries
- Validating FENs
- Building FENs from scratch or modifying existing ones
Queries can be executed via the app front-end (FE) as well as via any http client capable of sending POST requests e.g. curl, postman etc
You have a choice of either copy/pasting an existing FEN into the FEN input field or building a position on the virtual chess board from scratch by dragging&dropping chess pieces on/off the board. Please note while you are doing this, the value of the 'Request' text area changes accordingly to reflect the position on the board. You can also use 'Clear Board' or 'Start Position' buttons below the board to either start with an empty board or the initial board setup. After you are done setting a position, choose which side is to move in 'Side to move' selector, if need be, and a desired move depth in 'Depth' combo (the default is 1 and the maximum 15) and, and then press 'Submit' button. If the position is valid, 'Response' text area will be populated with a Json response in the following format:
{
"bestMove": "c4f7",
"eval": "0.83",
"continuation": "c4f7 e8f7 d1h5 g7g6 h5c5 d4d3 c5d4 g8f6 e4e5 f6d5 d4d3 d7d6 d3f3 f7g7 d2d4 h7h5 f1e1 h5h4 h2h3",
"mate": ""
}
where
eval
indicates position evaluation with minus sign indicating that position is in favor of black;
mate
indicates the number of moves till a forced checkmate, when applicable.
curl -X POST -H "Accept: application/json" -H "Content-Type:application/json" --data "{\"depth\":15, \"fen\": \"r1bqk1nr/p2p1ppp/2p5/1pb5/2BpP3/2P5/PP1P1PPP/RNBQ1RK1 w - - 0 1\"}" http://localhost
Just an fyi: maximum depth is defaulted to 15 i.e. any depth exceeding 15 will be truncated to 15 to avoid extremely long execution.
The FEN validation is reusing validation rules of chess.js with addition of extra validation rules on top of it.
The chess board is implemented using chessboardjs.
Back end makes use of a revamped version of Stockfish-Java.
GNU General Public License V3 except for chess.js and chessboardjs which have their own licences on the top of their respective file headers.