A chess AI that uses lichess.org as a front end.
knAIghtedBishop is the successor to BishopAI. It is a complete rewrite with a few goals:
- Cleaner modernized code
- More accurate prediction
- Faster evaluation
The primary ways knAIghtedBishop differentiates itself are:
- Rebuilt to use TensorFlow 2
- Support for batched predictions
- Support for faster low precision inference using TFLite
- Tree paths remembered between moves
- Cached board predictions to prevent unnecessary inferences
knAIghtedBishop operates by building a tree representing the possible states for the game. The tree begins as a single node representing the starting position. The AI then performs simulations of future game paths and builds out the tree accordingly. The number of simulations is predefined and the path the simulation chooses is dictated by an Upper Confidence Bounds algorithm with parameters provided by the policy and value outputs of a convolutional neural network.
- Python 3.8
- Tensorflow (GPU optional but highly recommended)
- The following pip installable python packages: python-chess, numpy, keras, tensorflow, berserk, dotenv
- a Lichess.com account and API token
Make sure all the requirements have been met. The setup steps for the requirements differ heavily between systems so this guide will only cover information assuming the requirements have already been properly met.
- Clone the GitHub project to a file location of your choosing.
- cd into the downloaded directory.
- Create a
.env
file in the root of the project and set your Lichess API tokenLICHESS_TOKEN = 'XXXX'
To play Chess:
- Start the Lichess server with
py run.py play
- Log into Lichess.com, go to your bot page, and play the bot.
To train a net from scratch:
- In the file
brain.py
change this line to point to the.pgn
file you want to train onpgn = open("D:/Chess Datasets/big.pgn")
- Start training with
py run.py train -n
- The model auto saves at the end of every epoch. Training can be resumed by excluding the
-n
.