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.
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 stateCheck White- White king is in checkCheck Black- Black king is in checkCheckmate White- Checkmate for whiteCheckmate 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.
- 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.
python3 -m venv venv
# Linux/macOS
source venv/bin/activate
# Windows
venv\Scripts\activate
pip install -r requirements.txtAnalyze 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
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 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_generatorpython3 inspect_model.py <model>python3 compress_nn.py <model>- 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
.metaand.logfiles