A Windows automation bot for Clash of Clans that can record attack sessions and replay them automatically with AI-powered base analysis.
This bot is for educational purposes only. Use at your own risk. The author is not responsible for any account bans or other consequences that may result from using this software.
- 🎯 Coordinate Mapping - Record button positions for your screen resolution
- 📹 Attack Recording - Record your attack sessions including clicks and timing
▶️ Attack Playback - Replay recorded attacks automatically- 🤖 AI Base Analysis - Analyze base loot using Google Gemini AI
- 🏃 Auto Attacker - Automatically find and attack bases based on loot requirements
- 🖼️ Screenshot Capture - Take screenshots of the game window
- 🎮 Game Detection - Automatically detect COC game window
- ⌨️ Hotkey Controls - Easy hotkey controls for all functions
- 📊 Session Management - Save, load, and manage multiple attack sessions
- Windows 10 or later
- Python 3.8 or later
- Clash of Clans running in FULL SCREEN mode (required for all operations)
- Compatible with emulators (BlueStacks, NoxPlayer, etc.)
- Google Gemini API key (for AI analysis features)
-
Clone the repository:
git clone <https://github.com/DFanso/coc-attack-bot> cd coc-attack-bot
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure the bot:
# Copy the example configuration file copy src\utils\example.config.py src\utils\config.py
-
Get a Google Gemini API key:
- Go to Google AI Studio
- Create a new API key
- Copy the API key for the next step
-
Edit the configuration:
- Open
src\utils\config.py
in a text editor - Replace the placeholder API key on line 82 with your actual Gemini API key:
"google_gemini_api_key": "YOUR_ACTUAL_API_KEY_HERE",
- Set
"enabled": True
on line 83 to enable AI analysis
- Open
-
Run the bot:
python main.py
- Open Clash of Clans in FULL SCREEN mode (this is crucial for accurate coordinates)
- Run the bot:
python main.py
- Go to "Game Detection" to verify the bot can find your game window
- Take a screenshot to confirm the capture area is correct
This is the most important step - you need to map button positions for your specific screen resolution.
- Select "Coordinate Mapping" from the main menu
- Choose "Start coordinate mapping"
- Move your mouse to important game elements and press F2 to record each position:
- Attack button (to start searching for bases)
- Next button (to skip bases during search)
- Return home button (after attack completion)
- Enter descriptive names for each coordinate (e.g., "attack_button", "barbarian", "archer")
- Press F3 to save all coordinates when finished
Essential coordinates to map:
attack_button
- The attack button to start base searchnext_button
- Skip to next base during searchfind_a_match
- find a match buttonreturn_home
- Return home after attack
- Select "Attack Recording" from the main menu
- Choose "Start new recording"
- Enter a descriptive name for your attack strategy (e.g., "barch_collector_raid")
- Manual Mode (Recommended): Press F6 to record each click precisely
- Use F7 to add delays between actions when needed
- Record a complete attack sequence from troop deployment to completion
- Press F5 when finished to stop and save the recording
Recording Tips:
- Record different strategies for different base types
- Include delays between troop deployments for better timing
- Record the full sequence including returning home
- Ensure you have configured your Gemini API key in
src\utils\config.py
- Select "Auto Attacker" from the main menu
- Choose "Start auto attack"
- Set your minimum loot requirements:
- Minimum gold (default: 300,000)
- Minimum elixir (default: 300,000)
- Minimum dark elixir (default: 2,000)
- Select the attack strategy you want to use
- The bot will automatically:
- Search for bases
- Analyze loot using AI
- Attack suitable bases
- Return home and repeat
- Select "Attack Playback" from the main menu
- Choose "Play attack"
- Select your recorded session
- Make sure COC is in the attack screen with a base loaded
- Press Enter to begin playback
Playback Tips:
- Ensure game state matches when the recording was made
- Use slower playback speeds for more reliable execution
- Always supervise the playback process
- F1 - Start/Stop mapping mode
- F2 - Record current mouse position
- F3 - Save coordinates
- ESC - Cancel mapping
- F5 - Start/Stop recording
- F6 - Manual click recording (recommended mode)
- F7 - Add delay marker
- ESC - Cancel recording
Recording Modes:
- Manual Mode (Default): Use F6 to record each click precisely
- Auto Mode (Optional): Enable in menu for automatic click detection
- F8 - Pause/Resume playback
- F9 - Stop playback
- ESC - Emergency stop
coc-attack-bot/
├── main.py # Main entry point
├── src/
│ ├── bot_controller.py # Main bot logic
│ ├── core/
│ │ ├── screen_capture.py # Screenshot and window detection
│ │ ├── coordinate_mapper.py # Button coordinate mapping
│ │ ├── attack_recorder.py # Attack session recording
│ │ └── attack_player.py # Attack playback
│ ├── ui/
│ │ └── console_ui.py # Console user interface
│ └── utils/
│ ├── logger.py # Logging utility
│ └── config.py # Configuration management
├── coordinates/ # Saved button coordinates
├── recordings/ # Recorded attack sessions
├── screenshots/ # Captured screenshots
├── templates/ # Image templates (future use)
├── logs/ # Log files
├── requirements.txt # Python dependencies
└── README.md # This file
The bot uses src\utils\config.py
for all configuration settings. After copying from example.config.py
, you can modify:
AI Analysis Settings:
google_gemini_api_key
- Your Gemini API key (required for AI features)enabled
- Set toTrue
to enable AI base analysismin_gold
,min_elixir
,min_dark_elixir
- Minimum loot requirements for auto attacks
Other Settings:
- Hotkey bindings for all operations
- Default directories for screenshots, recordings, coordinates
- Automation timing and speed settings
- Game detection parameters
- Full Screen Mode - ALWAYS run Clash of Clans in full screen mode for accurate coordinate mapping
- Screen Resolution - Keep your screen resolution consistent between recording and playback
- Game State - Make sure COC is in the same state when playing back attacks
- Coordinate Mapping - Take time to accurately map all essential buttons and positions
- Practice Mode - Test your recordings on practice attacks first
- Playback Speed - Use slower speeds (0.5x) for more reliable playback
- AI Analysis - Ensure your Gemini API key is valid and has sufficient quota
- Supervision - Always supervise the bot during operation
- Army Ready - Make sure your army is trained before starting auto attacks
- Internet Connection - Stable internet required for AI analysis features
- Failsafe - Move mouse to top-left corner to stop all automation
- Emergency Stop - Press ESC during any operation to stop immediately
- Validation - Recordings are validated before playback
- Logging - All actions are logged for debugging
- Make sure COC is running and visible
- Try different window modes (full screen vs windowed)
- Check if you're using a supported emulator
- Verify coordinates are mapped correctly for your resolution
- Check that the game is in the correct state before playback
- Try slower playback speeds
- Validate recordings before playing them
- Make sure the recording hotkeys aren't conflicting with other software
- Check that the bot has proper permissions to detect input
- Verify the screenshots directory is writable
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
This project is provided as-is for educational purposes. Use responsibly and at your own risk.
If you encounter issues:
- Check the log files in the
logs/
directory - Verify your Python and package versions
- Make sure COC is running and detectable
- Try the built-in validation tools
Remember: This bot is for educational purposes only. Always follow the game's terms of service and use responsibly.