# ConvChess

**ConvChess**,

a didactic convolutional neural network (CNN) chess playing entity designed and implemented by Barak Oshri and Nishith Khandwala during their 2015 project work at Stanford University ^{[2]}.
ConvChess was likely the first chess playing entity using a CNN, as mentioned by Matthia Sabatelli et al. ^{[3]}.
ConvChess is implemented in Python, using the python-chess and NumPy libraries, source code and datasets available on GitHub ^{[4]}.

## Contents

# Idea

Inspired by the supervised learning approach of Christopher Clark and Amos Storkey to predict moves in Go without any search,
to defeat the traditional search program Gnu Go in 86% of the games ^{[5]},
Oshri and Khandwala tried a similar idea to implement a move predictor or policy network in Chess. They were well aware that such winning rates without search as reported in Go are not possible in Chess, first due to the tactical nature of the game,
and also due to move classification aspect that chess moves require origin square and target square, instead of a single coordinate for a 19x19 grid to drop a stone.
Therefore in this novel approach, the classification was divided into two parts. The first part trains a piece-selector CNN to predict the origin square a piece moves from,
while the second part trains six move-selector CNNs to encode which target squares would be advantageous for each of the six possible piece types.
These seven CNNs take the board representation as input and output a probability distribution for 64 origin and 6x64 target squares.
The predicted move is then obtained by composing the piece-selector CNN by multiplying its values by the highest value in the corresponding move-selector CNN,
clipping all illegal origins and targets to zero, and taking the arg max over the entire composition.
Since the model considers White to move only, Black to move positions require a color flip.

# Network

Each of the seven CNNs consists of three convolutional layers with 32 3x3 filters stride 1, including ReLU and 2x2 pooling layer stride 2 (The authors reported less success using five convolution layers ^{[6]})
followed by two fully connected layers with a affine transformationto 128 features, the first including ReLU and Dropout, the second Softmax.
The input layer, feeding in the board representation ignoring en passant square and castling rights, has a shape of six channels for each piece type with three possible values for each of the 8x8 squares, -1 for Black pieces, 0 for empty square, and +1 for White pieces.
The output, reflecting the number of classifications, is a vector of 64 floats.

# Training

The networks were trained for 245,000 moves over 20,000 games ^{[7]},
with the piece-selector CNN trained on every piece and each move-selector CNN trained on every move made by the respective piece, without considering the outcome of the game.
Their best model was found by doing a grid-search over the parameters of learning rate, regularization, and weight initialization with fine tuning afterwards.
The parameters of the best model were a regularization of 0.0001, learning rate of 0.0015, batch size of 250, a learning rate decay of 0.999 on RMSprop with no dropout trained in 15 epochs ^{[2]}.

# Results

The best result obtained with the piece-selector CNN was 38.30%. The results for the move-selector varied. Pieces with local movements (P=52%, N=56%, K=47%) performed significantly better than sliding pieces (B=40%, R=30%, Q=27%) - the latter with more options to fail, and possibly also due to the restricted influence of only three 3x3 convolutions.
ConvChess was played against Sunfish (search depth not reported) in 100 games. 26 of the games drew and the rest were lost ^{[2]}.

# See also

# Publications

- Barak Oshri, Nishith Khandwala (
**2015**).*Predicting Moves in Chess using Convolutional Neural Networks*. pdf

# Forum Posts

- ConvChess CNN by Brian Richardson, CCC, March 15, 2017

- Re: ConvChess CNN by Álvaro Begué, CCC, March 15, 2017

# External Links

- GitHub - BarakOshri/ConvChess: Predicting Moves in Chess Using Convolutional Neural Networks
- Convolutional neural network from Wikipedia

# References

- ↑ 2D Image-Kernel Convolution Animation by Michael Plotke, January 28, 2013, Wikimedia Commons
- ↑
^{2.0}^{2.1}^{2.2}Barak Oshri, Nishith Khandwala (**2015**).*Predicting Moves in Chess using Convolutional Neural Networks*. pdf - ↑ Matthia Sabatelli, Francesco Bidoia, Valeriu Codreanu, Marco Wiering (
**2018**).*Learning to Evaluate Chess Positions with Deep Neural Networks and Limited Lookahead*. ICPRAM 2018, pdf - ↑ GitHub - BarakOshri/ConvChess: Predicting Moves in Chess Using Convolutional Neural Networks
- ↑ Christopher Clark, Amos Storkey (
**2014**).*Teaching Deep Convolutional Neural Networks to Play Go*. arXiv:1412.3409 - ↑ Re: ConvChess CNN by Álvaro Begué, CCC, March 15, 2017
- ↑ ConvChess/master/data/FICS_2000.pgn