Skip to content

GunaTeja777/Chess-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Antigravity Chess AI & Chess.com Bot

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.


📸 Demos

Live Visual Self-Play Training Loop

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:

Visual Self-Play Demo

Interactive Dashboard View

A snapshot of the main training console displaying live evaluations, moves log, MSE loss, and win/loss performance monitoring:

Dashboard Screenshot


🚀 Key Features

  • 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.

📁 Repository Structure

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)

🛠️ Installation & Setup

  1. Clone or open the workspace: Ensure you are in the workspace root directory d:\chess\.

  2. Install dependencies: Install the required libraries (including PyTorch, python-chess, Selenium, and Webdriver Manager):

    pip install torch chess requests selenium webdriver-manager

🎮 How to Use

1. Web Dashboard (Cloning & Training)

To clone a player's style or train the agent visually:

  1. Navigate to the training directory and run the Flask server:
    python training/server.py
  2. The server will automatically launch your default browser to http://localhost:8000.
  3. To Clone: Enter a Chess.com username under the Clone Chess.com Playstyle section and click Clone Player Playstyle.
  4. 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!

2. Play Automatically on Chess.com

To have your trained model play matches for you directly on Chess.com:

  1. Run the bot script from the root directory:
    python chess_bot.py
  2. A clean Chrome window will automatically open and navigate to Chess.com.
  3. Log in to your Chess.com account in that Chrome window.
  4. Join an online match or play against a computer bot (Play -> Computer).
  5. 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.

About

Chess-Agent is an interactive chess project that combines Python and JavaScript to provide a playable chess experience with a web-based interface. It likely includes game logic, move handling, and a user-friendly UI for playing and managing chess matches.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages