A chess AI implementation using deep reinforcement learning techniques, with a GUI for playing against the trained models.
- Chess GUI: Interactive chess board with drag-and-drop piece movement
- Deep Reinforcement Learning: Neural network trained on high-quality chess games
- Stockfish Integration: Enhanced training using Stockfish evaluation
- Prioritized Experience Replay: Improved learning from important experiences
- Curriculum Learning: Gradually increasing opponent strength during training
- Comprehensive Metrics System: Advanced metrics for model quality evaluation beyond loss values
- Phase-Specific Performance Analysis: Evaluate model strength in opening, middlegame, and endgame
- Asynchronous Evaluation: Lightweight metrics that don't impact training performance
-
Clone the repository:
git clone https://github.com/DurthVadr/Karry_Gasparov.git cd Karry_Gasparov -
Install the required dependencies:
pip install -r requirements.txt
-
Install Stockfish (optional, for enhanced training):
- macOS:
brew install stockfish - Ubuntu/Debian:
apt-get install stockfish - Windows: Download from Stockfish website
- macOS:
-
Start the chess GUI:
python chess_gui.py
-
Load a trained model by clicking "Load Model" and selecting a model file (e.g.,
models/best_model.pt) -
Play as White by making your moves, then click "AI Move" to have the model respond as Black
-
Train using PGN data and Stockfish evaluation:
python main.py --data_dir data --stockfish_path /path/to/stockfish
-
Continue training with self-play:
python main.py --self_play --stockfish_path /path/to/stockfish
-
Continue training from a saved model:
python main.py --load_model models/model_pgn_checkpoint.pt --data_dir data
-
Evaluate model metrics:
python main.py --load_model models/best_model.pt --metrics_only
-
For training on Google Colab, upload the necessary Python files and use the notebook in the archive directory
For detailed instructions on continuing training from saved models, see MODEL_LOADING_GUIDE.md.
The project includes a comprehensive metrics system that provides deeper insights into model quality beyond simple loss values:
- Decision Quality Index: Measures how often the model makes better moves than random play
- Tactical Accuracy: Evaluates the model's performance on tactical positions (captures, checks, etc.)
- Phase-Specific Performance: Separate metrics for opening, middlegame, and endgame play
- Evaluation Correlation: Measures how well the model's evaluations correlate with material count
-
During Training: Metrics are automatically evaluated and visualized at regular intervals
# Metrics are included in normal training python main.py --self_play --stockfish_path /path/to/stockfish -
Standalone Evaluation: Evaluate metrics on a previously trained model
python main.py --load_model models/best_model.pt --metrics_only
-
Visualizations: Metrics visualizations are saved to the
models/metrics/directory:metrics_history.png: Shows how metrics change over timemetrics_radar.png: Radar chart showing strengths and weaknesses
- Chess-Specific Insights: Metrics directly measure chess understanding, not just pattern recognition
- Phase Analysis: Identify if your model is weak in specific phases (opening, middlegame, endgame)
- Trend Tracking: See if your model is improving, stagnating, or declining in specific areas
- Lightweight Evaluation: Most metrics don't require Stockfish, making them faster to compute
chess_gui.py: Interactive chess GUIdrl_agent.py: Deep reinforcement learning agent implementationmodel_integration.py: Interface between GUI and trained modelsmain.py: Main training script with command-line interfacememory.py: Replay memory implementationsreward.py: Reward calculation functionsevaluation.py: Model evaluation against Stockfishvisualization.py: Training progress visualizationtraining.py: Training methods implementationutils.py: Utility functionsmetrics.py: Advanced metrics for model quality evaluationmetrics_visualization.py: Visualization tools for model metricsdata/: Directory containing PGN files for trainingmodels/: Directory containing trained modelsmodels/metrics/: Directory containing metrics visualizations
- Chess Engine with Reinforcement Learning
- Understanding AlphaZero
- Neural Networks for Chess
- Train Your Own Chess AI
High-quality chess games for training are available from:
