Jupyter and chess analysis

Jupyter notebooks are awesome and widely used in data science. You typically share Web documents that contain live code and visualizations. In fact, you can do much more: I bet Jupyter will be the new Emacs and an operating system per se ;) So what about reading chess games inside Jupyter?

With a few lines of code, you can read a PGN (portable game notation) file, loads the game you want, and visualize the moves (you can get back, move forward, etc.). It’s like a Web application, but within Jupyter. Below is a demonstration:

Extraction process

I’ve also shared a notebook that offers facilities to produce a GIF of a game, to analyze a whole game with Stockfish. As a proof of concept, I used the games of Alpazero against… Stockfish to visualize when Stockfish changed its evaluation (aka when AlphaZero lost the mind of Stockfish… and certainly many chess players).

Extraction process

We can certainly consider a feature-rich chess reader with live streaming (you can embed Youtube videos!), online analysis with chess engines, etc. Code is available on Github here

What’s the point of having a chess reader inside Jupyter? Obviously, there are better chess readers (go to the awesome and open source lichess!). But technically I found impressive to build a shareable, Web application only with a few lines of Python and its very strong ecosystem (thanks to libraries like python-chess, CairoSVG, etc.). You can easily and programmatically plug data analysis on top of it. For me, this short experiment mostly shows the potential of Jupyter: I’m not saying it’s good to play games or read your emails inside Jupyter, but it seems feasible ;-)

Written on June 24, 2019
[ chess | python | data | stockfish | jupyter ]