Skip to content

M-Veda/AI-Piano-Tiles-Bot

Repository files navigation

🎹 Piano Tiles Bot

An intelligent automation bot for the Piano Tiles game, built with Python. It uses real-time screen capture and computer vision to detect and tap tiles automatically — including short taps, long-press holds, and gold tiles.


📸 Features

  • Real-time screen capture using mss for ultra-low latency
  • 🖤 Dark tile detection via grayscale thresholding
  • 🟡 Gold tile detection using RGB color analysis
  • 🎵 Long tile support — holds mouse down for sustained tiles and releases at the right moment
  • 🛑 Safe stop — press Q anytime to gracefully halt the bot
  • 🔍 Auto start — detects and clicks the first tile to begin the game automatically
  • 🐛 Debug mode — optional live window showing what the bot sees

🎥 Demo Preview

Automation_Piano_Tiles_Bot_Demo.mp4

🗂️ Project Structure

piano-tiles-bot/
│
├── auto_player.py        # Main bot — detects and clicks tiles in real time
├── game_detection.py     # Helper to visualize tile detection with bounding boxes
├── get_coordinates.py    # Utility to capture your game window coordinates
├── test_capture.py       # Screen capture sanity check
├── tile_detection.py     # Full-screen tile detection preview
└── requirements.txt      # Python dependencies

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/your-username/piano-tiles-bot.git
cd piano-tiles-bot

2. Install Dependencies

pip install -r requirements.txt

3. Find Your Game Window Coordinates

Run the coordinate helper and follow the on-screen instructions:

python get_coordinates.py

Move your mouse to the top-left and then bottom-right corners of the game window when prompted. Copy the output into auto_player.py under GAME_REGION.

4. Run the Bot

python auto_player.py

The bot will wait 2 seconds, then auto-detect and click the start tile. Press Q at any time to stop safely.


⚙️ Configuration

Open auto_player.py and adjust these values to match your setup:

Variable Default Description
GAME_REGION {top: 50, left: 1311, width: 534, height: 951} Screen region of the game window
DARK_THRESHOLD 65 Grayscale cutoff for detecting black tiles
SCAN_Y_PERCENT 0.80 Vertical scan line position (80% down the game area)
LONG_TILE_MIN_HEIGHT 120 Pixel height threshold to classify a tile as long
RELEASE_MARGIN 10 Pixels above scan line to detect tile end for release
DEBUG False Set to True to show live detection window

🧰 Utility Scripts

Script Purpose
get_coordinates.py Interactively find and print your game window's screen coordinates
test_capture.py Preview full-screen capture to verify mss is working
tile_detection.py Full-screen tile detection with bounding box overlay
game_detection.py Region-specific detection preview for fine-tuning

📦 Dependencies

opencv-python
numpy
mss
pyautogui
keyboard

Install all at once:

pip install -r requirements.txt

⚠️ Linux users: The keyboard library may require sudo to capture global hotkeys.

⚠️ macOS users: You may need to grant Accessibility and Screen Recording permissions in System Preferences.


🧠 How It Works

  1. Screen Capturemss grabs the defined game region every frame.
  2. Grayscale Conversion — The frame is converted to grayscale for fast pixel analysis.
  3. Lane Scanning — The bot samples one pixel per lane at a fixed vertical scan line (80% of the game height by default).
  4. Tile Classification:
    • If the pixel is dark → a tile is present
    • If the pixel's RGB matches gold → a gold tile is present
    • The tile's height is measured upward from the scan point to classify it as short or long
  5. Input Simulation:
    • Short tilepyautogui.click()
    • Long tilepyautogui.mouseDown() until the tile ends, then pyautogui.mouseUp()
  6. Safe Exit — A global keyboard hotkey listens for Q and releases all held inputs before stopping.

🛡️ Disclaimer

This project is intended for educational and personal use only. Using bots in online games may violate the game's Terms of Service. Use responsibly.


📄 License

MIT License — feel free to use, modify, and share.


🤝 Contributing

Pull requests are welcome! If you find a bug or want to add a feature (e.g., combo detection, speed scaling, multi-monitor support), feel free to open an issue or PR.


Built with Python 🐍 | Powered by OpenCV 👁️ | Inspired by way too many failed Piano Tiles runs 🎵

About

A Python-based automation bot for the Piano Tiles game using OpenCV, real-time screen detection, and automated mouse control.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages