Yohan Chalier Projects Portfolio Blog

Chess Openings Learning Assistant


Openy

Openy is a Django application dedicated to learning chess openings.

Motivations

With a growing interest for chess, the topic of openings is expected to be brought up. When I tried to come up with a beginner's repertoire, I watched a lot of video material on YouTube; but the accumulation of knowledge rapidly grew out of hand. Remembering all the variations is not an easy task, especially for my defective memory. I started taking notes, but my data-oriented education made me look for a sensible representation of such knowledge. But that was not enough: repetition is said to be one main principle of learning, but I had no easy way of "training" memory with those notes. This lead me to developping Openy, an application taking my notes as input and converting them into playable chess exercises.

Note System

I started with the PGN notation, noting moves in Standard Algebraic Notation with full turns integer notation. Comments are inserted after a colon :. Line evaluation can be specified between parenthesis. Thus, I would open a text editor while watching a YouTube video, taking notes of moves and position comments along the way. Here is an example:

1. e4
    1... e5 2. Nf3
        2... Nc6 3. Bc4 : Italian opening
        2... d6 3. Bc4 : Philidor's defense

Openy's Backend

A first script parses those textual notes and produces a JSON file where positions are precisely expressed as FEN strings, and positions are evaluated via a chess engine such as Stockfish or Komodo. This parsing is done thanks to the python-chess module and has to be done locally: the server being hosted on a Raspberry Pi, it does not have enough power to support chess engine processing.

The JSON file is then uploaded to the server, and stored in a SQL database. Each position is stored as an entry is a SQL table, and a tree-like structure is build with references to the parent positions. Visualisation is one thing I like for sure. Here, I first tried the combination of Matplotlib and NetworkX, but it was both too slow and not easily customizable. I therefore implemented my own SVG renderer; here is how it looks:

Exercises are then generated by exploring the tree, and for each leaf, re-build the path leading to that leaf. The move sequence is stored in the database as an exercise. Remembering exercises allow for an analysis of how well the user performs on each exercises, and which lines must be focused in learning. An ELO based algorithm estimates the difficulty of each exercise. When the user desires to train, a random exercise is selected, but this sampling is weighted by how well does the user perform on that exercise (the worse the more frequent the exercise should be selected) and how long has it been since the last training of that line.

Openy's Frontend

A first major step has been the implementation of a javascript library allowing for the display of chess boards and pieces manipulation. For the style, I copied the Chess.com default style. I implemented a manual drag and drop system for moving pieces around, since default drag-and-drops capabilities are actually designed for very specific use cases. Then I added a logical representation of the game, for the script to understand which moves were legal and which were not, filtering out most of the missclicks, and allowing for automatic pieces capture, castling, en-passant and promotion moves.

You may try it yourself on this demonstration board.

Then, I was able to built the remaining of the website with simple interface elements. The exercise view is simple board where the user has to play white moves while the black moves are automatically played. If the user fails to perform the expected move, it is redirected to the database explorer, showing the comments and the possible moves that should be played.

Here is a screenshot of the said interface.