Skip to content

Repository files navigation

NeuralChess-Core

A neural network project built from scratch to classify chess positions. This engine is implemented without high-level AI frameworks like TensorFlow, PyTorch, or Keras.

Project Overview

The goal of NeuralChess-Core is to determine the state of a chess board (Nothing, Check White/Black, Checkmate White/Black) using Forsyth-Edwards Notation (FEN). The model takes as input:

  • The board position (64 squares × 12 piece types)
  • The player's turn (white or black)

And produces a prediction among 5 classes:

  • Nothing - No special state
  • Check White - White king is in check
  • Check Black - Black king is in check
  • Checkmate White - Checkmate for white
  • Checkmate Black - Checkmate for black

Unlike standard implementations, the entire neural network logic—including backpropagation, layer management, and optimization—is coded manually in the /nn directory.

Core Implementation

  • Neural Engine: Custom-built dense layers and forward/backward passes.
  • Optimizers: Manual implementation of the Adam optimizer.
  • Activations: Hand-coded ReLU and Sigmoid functions.
  • Training Logic: Custom EarlyStopping and ModelCheckpointing.

Installation

python3 -m venv venv
# Linux/macOS
source venv/bin/activate
# Windows
venv\Scripts\activate

pip install -r requirements.txt

Usage

Prediction Mode

Analyze one or multiple chess positions using a trained model:

./my_torch_analyzer --predict <model> <positions_file>

Parameters:

  • <model> - Path to the model file (.nn)
  • <positions_file> - File containing FEN positions (one per line)

Optional Flags:

  • --debug - Display probabilities for each class for every prediction

Training Mode

Train or continue training a model:

./my_torch_analyzer --train <model> <dataset_dir>

Parameters:

  • <model> - Path to the model to train (.nn)
  • <dataset_dir> - Directory containing training data

Optional Flags:

  • --save <filename> - Save the trained model under a new name (default: update the original model)

Generate a new models

Generate a new model:

WARNING: This will overwrite the existing model if it has the same name. And if you want to edit some parameters of the models, you can modify the my_torch_generator.py file.

./my_torch_generator

Utilities

Inspect a model

python3 inspect_model.py <model>

Compress a model

python3 compress_nn.py <model>

Notes

  • The model uses a 3-layer architecture (128, 64 neurons) with ReLU activation
  • Output layer with Sigmoid activation for multi-label classification
  • Adam optimizer is used with a learning rate of 0.001
  • Dataset is split 80% train / 20% validation
  • Training metadata is stored in .meta and .log files

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages