An automated bot for Clash of Clans that handles farming, trophy dropping, and looting operations using image recognition and ADB (Android Debug Bridge).
-
Multiple Operation Modes:
- Normal Mode: Standard farming with trophy range checks
- Force Drop Mode: Dedicated trophy dropping
- Force Loot Mode: Continuous looting without trophy checks
- Legends Mode: Support for legends league (currently identical to normal mode)
-
Automatic Detection:
- Recognizes in-game elements using template matching
- Reads trophy counts via OCR (Optical Character Recognition)
- Handles attack sequences with randomized movements
Before you begin, ensure you have the following installed:
- Python
- Android Emulator with ADB support (BlueStacks recommended)
- Clash of Clans game
- ADB (Android Debug Bridge)
- Additional Python libraries
Download and install BlueStacks or any other Android emulator that supports ADB connections.
- Launch your emulator.
- Set the resolution to 2400x1080 (critical for template matching)
- In BlueStacks: Settings → Display → Set resolution to 2400x1080
- Enable ADB connections:
- In BlueStacks: Settings → Advanced → Android Debug Bridge → Enable
- Enable pointer location information:
- In BlueStacks: Settings → Advanced → Enable "Show pointer information for current touch data"
- This will help with identifying screen coordinates for configuration
- Open Google Play Store in your emulator.
- Search for "Clash of Clans" and install it.
- Launch the game and complete the initial setup.
- Download the Android SDK Platform Tools
- Extract the ZIP file to a folder (e.g.,
C:\adb) - Add the folder to your system PATH:
- Press Win+S, type "environment variables" and select "Edit the system environment variables"
- Click "Environment Variables"
- Under "System variables", find "Path" and click "Edit"
- Click "New" and add the path to your ADB folder (e.g.,
C:\adb) - Click "OK" on all dialogs
brew install android-platform-toolssudo apt-get install android-tools-adb- Download the Tesseract installer.
- Run the installer, noting the installation location.
- Add Tesseract to your PATH:
- Follow the same steps as for ADB, adding the Tesseract installation directory.
- Default is typically
C:\Program Files\Tesseract-OCR.
brew install tesseractsudo apt install tesseract-ocrgit clone https://github.com/yourusername/coc_bot.git
cd coc_botpip install opencv-python pytesseract numpyVerify ADB connection to your emulator:
adb devicesYou should see your emulator listed as a connected device.
Create the configuration file:
cp config.example.json config.jsonOr manually create a config.json file in the root directory with the following structure:
{
"trophy_roi": {
"x1": 230,
"y1": 165,
"x2": 325,
"y2": 205
}
}Adjust the ROI (Region of Interest) settings:
- The default settings are calibrated for 2400x1080 resolution.
- Use BlueStacks' pointer information feature to determine exact pixel coordinates.
- Adjust the values in
config.jsonto match the trophy count location on your screen.
- Start your emulator and launch Clash of Clans.
- Open a terminal/command prompt.
- Navigate to the project's
srcdirectory:
cd path/to/coc_bot/src- Run the bot:
python main.py-
Select a mode when prompted:
force_drop: Drops trophies (enters matches and surrenders)force_loot: Continuously farms resources without trophy checksnormal: Standard mode with trophy monitoring (drops trophies when above threshold)legends: For legends league play (currently same as normal)
-
If prompted for iterations, enter a number or wait for automatic selection.
- Enable the pointer information display in BlueStacks.
- Touch areas on the screen where you want the bot to interact.
- Note the X and Y coordinates shown.
- Use these coordinates to:
- Adjust the
trophy_roiinconfig.json - Create new templates for buttons or game elements
- Modify hardcoded coordinates in the script if needed
- Adjust the
- Verify your emulator is set to 2400x1080 resolution.
- Update template images in the
templates/folder.
Restart the ADB server:
adb kill-server
adb start-serverVerify your emulator is running and properly configured for ADB.
- Ensure Tesseract is properly installed and in your PATH.
- Try adjusting the ROI in
config.jsonto better isolate trophy numbers.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.