A self-learning chess artificial intelligence
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.
virtualenv -p <pypy binary location here> venv
to set up your virtual environment.source venv/bin/activate
to activate your virtual environment.pip install -r requirements.txt
to install dependencies.pypy main.py
to play against the AI and pypy self_play.py
to watch the AI play against itself.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.
config.py
, set GAMES_FILE_NAME
to the name of the .pgn file. Feel free to tweak with other parameters too.pypy learn.py
to learn.