This is an app to play & study chess. It lies upon powerful tools:
- The R library rchess, that wraps:
- the chess engine chess.js. It ensures the game playability and rules integrity.
- the chess graphical board chessboardjs. The board design comes from there.
- The chess solver stockfish, wrapped into the eponymous R package. This is the AI that is used to analyse the parties and predict the next best move.
- The web framework shiny. It supports the user interface and allow for web deployment.
Install shinyChess without the need for an R environment using Docker. Installation with Docker can be performed from GNU/Linux or Windows.
git clone --recurse-submodules https://github.com/almarch/shinyChess.git
cd shinyChess
docker build -t chess .
The container can then be launched with Docker:
docker run -d -p 1997:80 chess
The app now runs at http://127.0.0.1:1997/
Installation as an R package can only be performed on GNU/Linux because of the Stockfish compilation step.
Start by cloning the repository.
git clone https://github.com/almarch/shinyChess.git
The app uses Stockfish. Make sure the submodule is properly fetched.
cd shinyChess
git submodule init
git submodule update
Also install all R depedencies. From R:
install.packages(c("bsplus","shinyWidgets","shinyjs"))
install.packages('https://cran.r-project.org/src/contrib/Archive/rchess/rchess_0.1.tar.gz', repos = NULL, type = 'source')
install.packages('https://cran.r-project.org/src/contrib/Archive/stockfish/stockfish_1.0.0.tar.gz', repos = NULL, type = 'source')
install.packages('bigchess', version = '1.9.1')
shinyChess can be installed as an R package:
R CMD INSTALL shinyChess
It may then be launched from R:
library(shinyChess)
app(shiny.port = 1997)
The app now runs at http://127.0.0.1:1997/
Have a look to this project for web deployment.
A demo version is kindly hosted on Posit Cloud at this adress. Deployment on the Posit Cloud is realized from RStudio calling app/app.R
of the posit branch from RStudio. The posit branch uses the version of stockfish embedded in the eponymous R package i.e. version 14, instead of the latest one as dynamically built in the main branch.
The game can be played and is recorded using the Portable Game Notation (PGN). Select the next move using the drop list, and confirm with Play.
Navigate back and forth through the party using the navigation arrows.
The party PGN is displayed on the first element of the lateral accordion. Save it to your clipboard using the Copy button; or load a new party from your clipboard using Paste.
For instance, copy the following PGN and load it in the app:
1.e4 c5 2.c3 d5 3.exd5 Qxd5 4.d4 Nf6 5.Nf3 Bg4 6.Be2 e6 7.h3 Bh5 8.O-O Nc6 9.Be3 cxd4 10.cxd4 Bb4 11.a3 Ba5 12.Nc3 Qd6 13.Nb5 Qe7 14.Ne5 Bxe2 15.Qxe2 O-O 16.Rac1 Rac8 17.Bg5 Bb6 18.Bxf6 gxf6 19.Nc4 Rfd8 20.Nxb6 axb6 21.Rfd1 f5 22.Qe3 Qf6 23.d5 Rxd5 24.Rxd5 exd5 25.b3 Kh8 26.Qxb6 Rg8 27.Qc5 d4 28.Nd6 f4 29.Nxb7 Ne5 30.Qd5 f3 31.g3 Nd3 32.Rc7 Re8 33.Nd6 Re1+ 34.Kh2 Nxf2 35.Nxf7+ Kg7 36.Ng5+ Kh6 37.Rxh7+
The R package rchess comes with a collection of openings. They are gathered in the drop list of the second element of the lateral accordion.
If an opening is played, its name will appear selected in the drop list. An opening may also be selected and played at any time. It then replaces the current party.
To analyze the game, from the third element or the lateral accordion: select the analysis time per move and click the launcher button. Be careful, even a few seconds make a long time for a long party.
The party is analyzed using Stockfish, one of the most powerful chess solver. The result is yielded as a plot.
The analysis plot takes all analyzed moves as x and the advantage in centipawn (cp) as y. The y axis is presented on a sigmoid scale. A positive value is an advantage for White and a negative value is an advantage for Black.
The vertical red line identifies the current move. On top, the exact advantage and the best next move are displayed. The party can be explored using the game navigation arrows.
This work is licensed under CC0 1.0 Universal.
Favicon: en:User:Cburnett (knight); Francois-Pier (zebra), CC BY-SA 3.0, Link