an AlphaZero-style chess engine in Python that learns from self-play
It is taught by nobody. It is only ever played against itself.
AZ-Lite is an AlphaZero-inspired chess engine written in Python. It is deliberately small. The point was never to build something that beats a real engine, it was to build the AlphaZero idea end to end and be able to read every part of it afterwards.
The search is Monte Carlo tree search using PUCT, which is the rule that decides which move to explore next. Left alone, tree search is a brute-force method that has to look at everything. Here it is guided: a small neural network suggests which moves are worth considering, the policy, and how good a position looks, the value. The search spends its effort where the network points, and the network gets better because the search keeps finding moves it did not expect. Move scoring is done on the fly through learned move embeddings, which is what keeps the implementation compact enough to read.
It learns from nothing but itself. The engine plays its own games, writes them out as JSONL replay data, trains on that data, and saves a checkpoint. Then it does it again, now slightly stronger, and the games it generates are slightly better than the ones it trained on. There is no opening book, no database of grandmaster games, and no human evaluation function. It is handed the rules and left with them.
The whole pipeline is driven from one command line with three modes: selfplay to generate games, train to learn from them, and play to sit down against it. That matters more than it sounds. A lot of reinforcement learning code exists as fragments that only the author can assemble, and a project you cannot run end to end in a single afternoon is a project nobody else will ever learn from.