A Python automation bot for Puzzles & Survival game using PyAutoGUI for GUI automation.
- Train Troops: Automatically train troops with speedup items
- Heal Troops: Heal wounded troops automatically
- Help Alliance: Help alliance members with one click
- Gather Resources: Automate resource gathering (in development)
- Logging: Comprehensive logging system for debugging
- CLI Interface: Easy-to-use command-line interface
python_practice/
├── config/ # Configuration files
│ ├── __init__.py
│ └── settings.py # Centralized settings
├── images/ # Game UI images for detection
│ ├── buttons/ # Button images
│ ├── dialogs/ # Dialog box images
│ └── indicators/ # Status indicator images
├── src/ # Source code
│ ├── actions/ # Action modules
│ │ ├── training.py # Troop training
│ │ ├── healing.py # Troop healing
│ │ ├── helping.py # Alliance help
│ │ └── gathering.py # Resource gathering
│ ├── utils/ # Utility modules
│ │ ├── screen.py # Screen detection
│ │ └── window.py # Window management
│ ├── bot.py # Main bot class
│ └── logger.py # Logging configuration
├── tests/ # Test files
├── main.py # Entry point
├── requirements.txt # Dependencies
└── README.md # This file
- Python 3.7 or higher
- Puzzles & Survival game running on Windows
- Tesseract OCR (optional, for text recognition)
-
Clone or download this repository
-
Create a virtual environment (recommended):
python -m venv venv
-
Activate the virtual environment:
- Windows:
venv\Scripts\activate
- Linux/Mac:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Install Tesseract OCR (optional):
- Download from: https://github.com/UB-Mannheim/tesseract/wiki
- Add to system PATH
Run the bot with various actions:
# Show help
python main.py
# Check if game window is available
python main.py --action check
# Train troops 5 times
python main.py --action train --times 5
# Help alliance members 3 times
python main.py --action help --times 3
# Heal troops 2 times
python main.py --action heal --times 2
# Enable debug logging
python main.py --action train --times 1 --debugtrain- Train troops with automatic speedupheal- Heal wounded troopshelp- Help alliance membersgather- Gather resources (in development)check- Check if game window is found
--action ACTION Action to perform (train, heal, help, gather, check)
--times N Number of times to repeat the action (default: 1)
--debug Enable debug logging
--window-title Custom game window title (default: "Puzzles & Survival")
All configuration is centralized in config/settings.py:
- Image paths: Locations of UI element images
- Confidence levels: Image detection confidence thresholds
- Timing delays: Wait times between actions
- Logging settings: Log levels and formats
To customize behavior, edit config/settings.py:
# Example: Adjust confidence levels
CONFIDENCE_HIGH = 0.9
CONFIDENCE_MEDIUM = 0.7
CONFIDENCE_LOW = 0.6
# Example: Adjust delays
DELAY_SHORT = 1.0
DELAY_MEDIUM = 2.0
DELAY_LONG = 4.0- PyAutoGUI Failsafe: Move mouse to screen corner to stop execution
- Window Detection: Verifies game window before actions
- Error Handling: Graceful error handling with detailed logging
- Keyboard Interrupt: Stop with Ctrl+C at any time
All operations are logged to:
- Console: INFO level and above
- File:
bot.log(DEBUG level and above)
View logs:
# View recent logs
tail -f bot.log
# Windows PowerShell
Get-Content bot.log -Wait -Tail 50- Create a new action class in
src/actions/ - Implement action methods using
ScreenDetectorandWindowManager - Add action to
src/bot.py - Update CLI in
main.py
- Take screenshots of UI elements
- Save to appropriate
images/subdirectory - Add path constant to
config/settings.py - Reference in action code
- Ensure Puzzles & Survival is running
- Check window title matches (default: "Puzzles & Survival")
- Use
--window-titleflag if different
- Adjust confidence levels in
config/settings.py - Verify image files exist in
images/directories - Check game resolution and scaling settings
- Try with
--debugflag for detailed logs
- Ensure virtual environment is activated
- Run
pip install -r requirements.txt - Check Python version (3.7+)
- Reduce image search regions
- Increase confidence thresholds
- Use grayscale image matching where possible
To improve the bot:
- Follow the existing code structure
- Add docstrings to all functions
- Use the logging system (not print statements)
- Test thoroughly before committing
- Update README if adding features
This bot is for educational purposes. Use at your own risk. Automation may violate game terms of service.
This project is provided as-is for personal use.
- PyAutoGUI for GUI automation
- PyGetWindow for window management
- Pytesseract for OCR capabilities