← All work
Machine Learning

Chess Engine

A chess engine that combines a neural network with a Monte Carlo Tree Search (MCTS) algorithm to play chess at a 1600 Elo level.

CategoryMachine Learning
Updated5. 9. 2026
Repositoryhttps://github.com/martinledl/chess-engine
Stack
C++PythonPyTorchNumPyNeural NetworksMonte Carlo Tree Search

Overview

I am not much of a chess player, but seeing the success of engines like Stockfish, I wanted to see if I could build something, that would be able to play chess better than me. Apparently, that's exactly what I did and it beats me by a large margin.

Results

The engine reaches 1600 Elo when playing against engines with known Elo ratings (20+0.1s time control). No question, this is not a world-class engine, but I am very satisfied with the result, given that I am not a chess player.

Searching for the best move evaluates just under 3 million positions per second on my MacBook Pro M1. This number may not look impressive, but considering the neural network evaluation is included, it is not a bad result.

Project details

The engine combines a neural network with a Monte Carlo Tree Search (MCTS) algorithm. The tree search evaluates the possible moves, but since there are so many of them, it can only get so far in reasonable time. That's where the neural network comes in. When the tree search reaches a leaf node ("search has looked deep enough"), the neural network evaluates the position and gives a score for it, based on how advantageous it is for the player.

The neural network uses a NNUE architecture, which is a pretty small network, that can quickly evaluate inputs, which differ ever so slightly from one another. The network is trained on the Lichess evaluation dataset, which contains millions of positions and their evaluations. The network is trained to predict the evaluation of a position, given the board state as input and the side to play.

To make the tree search more efficient, I implemented optimizations such as transposition tables, move ordering, and alpha-beta pruning.

In order to speed up the inference of the neural network, I utilized quantization, which reduces the precision of the weights and activations, allowing for faster computation without significant loss in accuracy. Inference was run in C++ using manual code for loading the quantized weights and performing the forward pass.

Technologies used

  • C++
  • Python
  • PyTorch
  • NumPy