Chess Neural Network

Chess engines are perhaps my most favorite application of artificial intelligence on board games. This project is my attempt to develop an AI based chess engine that is skilled enough to beat me. It consists of a chess engine that utilizes a convolutional neural network to rapidly evaluate thousands of positions along with the minimax algorithm with alpha-beta pruning to explore potential positions and determine the optimal move. In Chess, the term "adoption" refers to the concept of winning against a person for 10 consecutive games. With that in mind, my primary goal for this project is to create a chess engine that is good enough to "adopt" the average player.

Some useful papers that helped me throughout the process of developing this project is "DeepChess: End-to-End Deep Neural Network for Automatic Learning in Chess" by Barak Oshri and Nishith Khandwala and "Learning to Play Chess with Minimal Lookahead and Deep Value Neural Networks" by Matthia Sabatelli.

This project was inspired by Sebastian Lague and his chess series as well as from my CMSC 320 Data Science class at UMD. Thank you!

Table of Contents

Features

  • Neural network-based position evaluation.
  • Minimax algorithm with alpha beta pruning for searching optimal moves.
  • Training on large datasets with historical chess games.
  • Also trained a model based on my own Lichess games.

Data Source

The game data used in this project was obtained from lichess open databases. I used May 2023 in order to have a data set size of over 100 million games. I also included a smaller Lichess dataset of ~100 thousand games from January 2013 which is used a sample for experimenting with the data and ensuring the program works as expected before training the larger model.

I also data obtained all my games that I played on my Lichess account, SteveMAlt to build a model based on my playing style. However, my data set is much smaller than the open databases.

Data Preprocessing

In order to provide each chess board with a corresponding evaluation score that will be use as training features for the neural netowrk, I used the latest stockfish engine as of August 2023 to evaluate the position and manually add the evaluation score as a label. Essentially, for every board state for each game in the PGN, I used the stockfish engine and manually added the labels to the data. By doing so, I was able to get several hundreds of thousands of chess boards along with their evaluation. The scores and boards are stored in a separate numpy files but have the same number of records.

Installation

Clone the repository and install the required dependencies:

git clone https://github.com/rodzamor/chess-neural-network.git
cd chess-neural-network
pip install -r requirements.txt

Neural Network Architecture

Still a WIP 1000 epochs Early Stopping Conv2D

Play the Chess Engine

You can play the Chess Neural Network with differing levels of difficulty on my website, RodzAmor.com/chess.

Contributing

Contributions are welcome, feel free to clone the repository and make your own changes!