An interactive deep reinforcement learning chess framework built with PyTorch and Python. It features a real-time web training dashboard (supporting playstyle cloning and reinforcement self-play) and an automated Chess.com bot that plays matches in your browser using the trained neural network.
Below is a demonstration of the dual agents playing against each other on the custom dashboard to optimize their network weights via Temporal Difference (TD) reinforcement learning:
A snapshot of the main training console displaying live evaluations, moves log, MSE loss, and win/loss performance monitoring:
- Dual-Model Architecture: Supports playing against a Reinforcement Learning (RL) agent or a Playstyle Clone agent.
- Player Cloning (Imitation Learning): Fetch PGN game logs of any public Chess.com username and pre-train the model to mimic that player's behavior.
- Minimax Search (3-Ply): Utilizes a Minimax search engine with Alpha-Beta pruning to calculate variations and make tactical decisions instead of playing blindly.
- Handcrafted Heuristics: Combines deep neural network evaluations with Material Balance heuristics to guide search choices, prioritize captures, and secure fast checkmates.
- Automated Chess.com Bot: Automates your moves on Chess.com by opening a Chrome browser session, reading the board elements from the DOM, and executing clicking sequences automatically with human-like delays.
d:\chess\
├── chess_bot.py # Main script to run the Chess.com automated bot
├── images/ # Media assets for documentation
│ ├── selfplay_demo.webp
│ └── board_demo.png
└── training/ # Web training dashboard source files
├── agent.py # AI Agent logic (TD-Learning, Minimax Search, evaluation)
├── model.py # PyTorch Value Neural Network definition
├── server.py # Flask server API endpoints
├── app.js # Interactive UI controllers and chess.js integration
├── index.html # Web dashboard markup
├── style.css # Dashboard custom stylesheet
└── *.pth # PyTorch model weight files (e.g. model_rl.pth)
-
Clone or open the workspace: Ensure you are in the workspace root directory
d:\chess\. -
Install dependencies: Install the required libraries (including PyTorch, python-chess, Selenium, and Webdriver Manager):
pip install torch chess requests selenium webdriver-manager
To clone a player's style or train the agent visually:
- Navigate to the
trainingdirectory and run the Flask server:python training/server.py
- The server will automatically launch your default browser to
http://localhost:8000. - To Clone: Enter a Chess.com username under the Clone Chess.com Playstyle section and click Clone Player Playstyle.
- To Self-Play: Go to the RL Trainer card, select the number of games, and click ⚡ Start Visual Self-Play. You will see the pieces moving on the board, evaluations shifting, and weights updating dynamically!
To have your trained model play matches for you directly on Chess.com:
- Run the bot script from the root directory:
python chess_bot.py
- A clean Chrome window will automatically open and navigate to Chess.com.
- Log in to your Chess.com account in that Chrome window.
- Join an online match or play against a computer bot (Play -> Computer).
- Do not move the pieces yourself! Once the board is rendered, the bot will detect it, identify your color, compute moves using the trained model weights via Minimax search, and click/move the pieces automatically.

