This project uses Monte Carlo Tree Search (MCTS) and a deep learning model to create a chess AI. The code is organized into four main Python scripts: beta_chess.py
, MCTS.py
, pipeline.py
, and encoding.py
.
beta_chess.py
contains the following classes and functions:
BoardData
: A custom dataset class for chess board positions.ConvBlock
, ResBlock
, OutBlock
: Neural network building blocks.ChessNet
: The main neural network architecture.ChessLoss
: Custom loss function for training the network.train()
: Function for training the neural network.These are inspired by the AlphaZero paper and take a similar approach to the neural network architecture and training.
MCTS.py
is a Python script that contains a customized implementation of the Monte Carlo Tree Search algorithm. It includes the following key features:
encoding.py
only contains helper functions to encode and decode the board and any move on the board.
pipeline.py
is a Python script that combines the chess AI training and Monte Carlo Tree Search (MCTS) self-play into a single pipeline.
It simply contains 2 functions:
run_MCTS()
: Function to run MCTS self-play for a given iteration.run_net_training()
: Function to train the neural network for a given iteration.To run the pipeline, execute the pipeline.py
script. It will create the necessary directories if they don't exist and run the MCTS and neural network training for the specified number of iterations.
pip install -r requirements.txt
pipeline.py
script to run the entire pipeline with the specified number of iterations.python pipeline.py
This will run the MCTS self-play and neural network training for the specified number of iterations.
pipeline.py
script.NUM_PROCESSES
parameter in the pipeline.py
script based on your system's capabilities.