Implementation of the AlphaZero algorithm.
Feature highlights:
- Fast generation of legal moves using custom chess library libchess.
- Distributed training with one training process and multiple self-play processes.
- Batched Monte Carlo tree search.
- Communication with user interfaces and lichess.org using UCI.
Originally a group project in TDDE19 at Linköping University.
First time:
# clone repository
git clone --recurse-submodules git@gitlab.liu.se:TDDE19-2021-1/tjack.git
# or `git submodule init && git submodule update` after regular clone
# use virtual environment (optional)
python3 -m venv venv
source venv/bin/activate
# install requirements
pip install -r requirements.txt
# setup build directory
meson build
# to choose non-default compiler like clang, do `CXX=clang++ meson <builddir>`
# to select build type, do `meson <builddir> --buildtype={debug,release}`
# if the build fails with some torch error, try `meson <builddir> -D_GLIBCXX_USE_CXX11_ABI=0To build:
cd build
ninjaRun one selfplayer and one trainer:
model=model.pt
./selfplay $model | ./training $modelRun multiple selfplayers and one trainer:
model=model.pt
./training $model <(./selfplay $model) <(./selfplay $model) <(./selfplay $model)Play with bot on lichess via lichess-bot:
# download lichess-bot somewhere
git clone https://github.com/ShailChoksi/lichess-bot.git <path/to/lichess-bot>
# export bot token token
export LICHESS_BOT_TOKEN=<token>
# run engine
cd <engine>
python3 <path/to/lichess-bot>/lichess-bot.pyThen challenge here:
https://lichess.org/?user=tjack-bot#friend
Estimate Elo rating of of engine:
python3 scripts/elo_est.py build/<engine>