AZ-Lite is a compact, AlphaZero-inspired chess engine implemented in Python.
It combines Monte-Carlo Tree Search (MCTS) with a lightweight neural network (policy + value) and learns from self-play.
The project is designed to be readable, reproducible, and runnable locally
Quick Demo of bot live in action. Current GIF Showcases Output with 20 games to train on.
- MCTS (PUCT) guided by neural priors and values.
- On-the-fly move scoring via learned move embeddings (keeps the implementation compact).
- End-to-end pipeline: self-play → JSONL replay data → training loop → checkpoints.
- Interactive CLI to
selfplay,train, andplay. - Lightweight and modular so you can extend (GUI, distributed self-play, larger nets).
Assumes Linux/macOS or WSL, Python 3.8+.
First, create a virtual environment and install the dependencies:
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txtThis makes the AI play against itself to create game data for training. The data is saved in the selfplay_data/ directory.
With the helper script (recommended):
# Usage: ./run_selfplay.sh [episodes] [sims_per_move] [player_id]
./run_selfplay.sh 5 80 demoOr, directly with Python:
# The first argument 'selfplay' is the required mode.
python azlite_portfolio_clean.py selfplay --episodes 5 --sims 80 --pid demoThis loads the data from selfplay_data/ to train the AI. Checkpoints are saved in az_checkpoints/.
Decrease low due to small dataset
With the helper script:
./run_train.shOr, directly with Python:
# The first argument 'train' is the required mode.
python azlite_portfolio_clean.py trainThis lets you play a game of chess against the engine.
With the helper script:
# The script will automatically load the latest checkpoint.
# The argument is the number of MCTS simulations per move.
./run_play.sh 200Or, directly with Python:
# The first argument 'play' is the required mode.
# You must specify which checkpoint to use.
LATEST_CHECKPOINT=$(ls -t az_checkpoints | head -n 1)
python azlite_portfolio_clean.py play --sims 200 --checkpoint "az_checkpoints/$LATEST_CHECKPOINT"During play, enter moves like e4, Nf3, e2 e4, or quit to exit.
# quick demo: create venv, install, run 3 selfplay games
python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt
./run_selfplay.sh 3 80 demo
# train (reads all JSONL in selfplay_data)
./run_train.sh
# play with 200 MCTS sims (load checkpoint with --checkpoint flag if desired)
./run_play.sh 200- State encoder — small 3-layer CNN producing a compact state embedding from a 12×8×8 board tensor (6 piece types × 2 colors).
- Policy head — learned embeddings for
from,to, andpromotioncombined with state embedding to score legal moves on the fly. - Value head — scalar predicting game outcome (−1..1).
- MCTS (PUCT) — neural priors bias search, Dirichlet noise added at root, value backups produce the training target
z. - Self-play — saves
(state, π, z)examples as JSONL inselfplay_data/. - Training loop — samples replay, optimizes
MSE(value,z) + CE(policy,π), saves checkpoints to az_checkpoints/.
For more details, see docs/architecture.md and docs/hyperparams.md.
azlite-portfolio/
├─ azlite_portfolio_clean.py # main engine & CLI
├─ run_selfplay.sh # wrapper for self-play
├─ run_train.sh # wrapper for training
├─ run_play.sh # wrapper to play interactively
├─ requirements.txt
├─ selfplay_data/ # generated JSONL examples
├─ az_checkpoints/ # saved PyTorch checkpoints
├─ docs/ # architecture, hyperparams
├─ tests/ # unit tests (parse + tensor)
├─ Makefile
├─ README.md
└─ LICENSEHere's a look at the planned features and improvements for AZ-Lite. Contributions are welcome!
- GUI for Gameplay: Develop a simple graphical user interface to make playing against the AI more intuitive.
- Configuration File: Move hyperparameters and settings into a
config.yamlfile for easier tuning. - Expanded Test Suite: Add more unit and integration tests to ensure robustness.
- Performance Profiling: Profile the self-play and training loops to identify and optimize bottlenecks.
- UCI Protocol Support: Implement the Universal Chess Interface (UCI) protocol to allow the engine to be used with standard chess GUIs (e.g., Arena, Cute Chess).
- Advanced Network Architectures: Experiment with more complex neural network designs (e.g., ResNets, Squeeze-and-Excitation Networks).
- Opening Book: Integrate a basic opening book to guide the first few moves of the game.
- Distributed Self-Play: Implement a framework for running self-play games in parallel across multiple machines.
- Web-Based Interface: Create a simple web app where users can play against the trained engine.
- Elo Rating Estimation: Set up a pipeline to continuously evaluate the engine's strength and estimate its Elo rating.
Check out the open issues:
on GitHub Issues
Thank You For Reading Through This.
