This project explores the use of deep learning to predict chess moves from board positions. It utilizes historical chess game data in PGN format, encodes the board state, and trains a neural network model to suggest the most likely next move.
The notebook uses a pipeline that:
- Parses PGN files to extract game positions and moves
- Encodes board states into a 3D tensor format
- Encodes legal moves as one-hot vectors
- Trains a Keras neural network model
- Evaluates the model's ability to predict next moves
chess.ipynb: The main notebook containing the full pipeline.
The project uses the following Python libraries:
- NumPy, python-chess
Install dependencies with:
pip install chess tensorflow numpy tqdmThe notebook defines a simple deep learning model using Keras:
- Input: Encoded board state (8x8x12)
- Hidden layers: Dense layers
- Output: Softmax activation over move classes
Key functionalities in the notebook:
- Move prediction, PGN file parsing
- Only supports prediction of a single move
- Requires sufficient training data to generalize
- Evaluation metrics are minimal
- Enhance evaluation (e.g. top-k accuracy, Elo-based)
- Expand data preprocessing
- Use advanced architectures (e.g. CNNs or Transformers)
- Deploy as a playable move suggestion engine
MIT License
Figure 1: Demonstrating the increasing accuracy of the transformer model with a growing sample size
Figure 2: Normalised confusion matrix for most frequent moves