ChessBot is an intelligent chess-playing application that leverages OpenCV to read the screen, detect a chessboard, and interact with a chess engine (Stockfish) to play moves based on the bot's color.
- Screen Reading: Uses OpenCV to capture the screen and detect the chessboard.
- Move Detection: Identifies the current state of the board and detects the opponent's moves.
- Bot Interaction: Interacts with the Stockfish chess engine to calculate and play the best move.
- Color-Based Play: Configurable to play as either white or black.
- Python 3.x
- OpenCV
- Stockfish engine
- chess library
- numpy
-
Clone the repository:
git clone https://github.com/sakthilkv/chessbot.git cd chessbot -
Install dependencies:
pip install opencv-python chess numpy
-
Download Stockfish: Download the Stockfish engine from the official website and place the executable in the project directory.
-
Setup and Run:
python chessbot.py
-
Input Bot Color: When prompted, input the bot's color:
wfor whitebfor black
-
Screen Reading:
- Captures the screen using OpenCV.
- Detects the chessboard and extracts the current state.
-
Move Detection:
- Compares the current state with the previous state to detect moves.
- Uses the
chesslibrary to validate moves and update the board state.
-
Bot Interaction:
- Configures and interacts with the Stockfish engine to get the best move.
- Plays the calculated move on the screen using OpenCV.
-
Color-Based Play:
- The bot plays according to the specified color and waits for the opponent's move before making the next move.