There's a line in Michael Lewis' 'Flash Boys': It's not just like chess, but like solving a particular problem in chess. The more challenging problem is not to play chess but to write the code that will play chess. I surely am not Bobby Fischer nor Alex Gerko, but I thought it can be a fun experience to at least try.
Alpha-beta search engine running in your browser.
No server required.
I decided to play with two engine designs:
- A standard tree search including: alpha-beta pruning* or
- An Alpha-Zero inspired neural net
*I was surprised that the original idea was already proposed by McCarthy during the Dartmouth Seminar here.
The goal of the neural net was to improve my tree search, not replace it. Instead of valuing an exponential number of configurations, I wanted to train a 'smart' neural-net to find the best possible scenarios, as well as to teach some specific playing style. To bootstrap the system, I first downloaded historical games of some of the chess grandmasters (the idea was to train the engine to replicate a more aggressive style of playing by introducing games by Fisher, Tal or Murphy). The engine would parse the PGN files and pretrain on these and move to a next, self-improvement step. A candidate model would be created which would then train against itself and, ideally, improve by minimising the loss function (via the standard gradient descent). Chessprogramming.org and dedicated papers, such as this one and by Google Deepmind were of great help.
It was far more challenging to design it than I thought. For example, the first version wanted to constantly play Nf3 - memorizing, not generalizing I guess. Most surprisingly, when training the model against itself, I constantly stuck upon at a nearly 100% draw rate (and hence no improvement). I tried to implement noise in the training process (and hence introduce variance in decisions taken between competing models) but it was quite hard. I downloaded Lichess' puzzles (more like 5,751,400 chess puzzles) but it also failed - the neural net would sacrifice too many pieces (even to my preference) and constantly try to engage in really aggressive plays. In the end, I decided to first force it to play against the 'alpha-beta' model and see how it goes - for now I need to get my hands on GPUs before deploying it here.
Along with the project, it was quite fun to read pre-computer chess textbooks:


'The Chess Mind' by Gerald Abrahams (1951)
I guess now Stockfish has the most pure vision!