A chess artificial intelligence using the MTD-f algorithm for move selection and that can learn from old games. It uses the python-chess library for board representation, move generation, zobrist hashing and reading .pgn files.
Temporal difference learning, a type of reinforcement learning, was used to train the AI. The inspiration for this work was this paper.
This is a match played by the AI against itself. White has a search depth of 2, and black has a search depth of 3. Black wins.
- Clone the repo.
- Install python and virtualenv.
- Download pypy binary.
- Run
virtualenv -p <pypy binary location here> venv
to set up your virtual environment. - Run
source venv/bin/activate
to activate your virtual environment. - Run
pip install -r requirements.txt
to install dependencies. - Run
pypy main.py
to play against the AI andpypy self_play.py
to watch the AI play against itself. - Run
deactivate
to deactivate the virtual environment.
Note: main.py
and self_play.py
both have MAX_DEPTH
constants that can be adjusted to change the AI's strength. Increase it to increase the strength and decrease it to decrease the strength.
- Find and download a database of chess games in PGN format, or use this.
- Place the downloaded .pgn file in the project root.
- In
config.py
, setGAMES_FILE_NAME
to the name of the .pgn file. Feel free to tweak with other parameters too. - Run
pypy learn.py
to learn.