# VisionGrid AI: Heuristic Gameplay & UI Automation Engine 🤖🎮 [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/) [![OpenCV](https://img.shields.io/badge/OpenCV-4.0%2B-green.svg)](https://opencv.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ## 📌 Overview **VisionGrid AI** is a robust, Python-based automation pipeline designed to interact with complex Android application interfaces. Built entirely without API hooks, this engine relies on real-time Computer Vision (OpenCV) and the Android Debug Bridge (ADB) to navigate UI constraints, handle unpredictable dynamic pop-ups, and execute heuristic strategies within a grid-based puzzle environment. This project was developed as a Proof of Concept (PoC) to showcase advanced UI state management, Finite State Machine (FSM) implementation, and algorithm-based gameplay automation. ##🎥 Demonstration {5242B19A-80EA-47AD-A13E-ACA7C52221F8} https://github.com/user-attachments/assets/abc8b9bb-24ba-400c-9388-c0f75798faa8 ## 🚀 Key Features * **Heuristic Board Engine:** Maps an 8x8 game grid into a 2D matrix using a custom Flood-Fill algorithm. It scores potential moves based on chain-reaction probability (gravity), target elimination, and zero-cost power-up combos. * **FSM-Based UI & Ad Handler:** Replaces rigid `time.sleep()` mechanisms with a dynamic "Heartbeat Pulse" logic. It constantly verifies the UI state, autonomously dismissing deceptive network errors, "Ad not completed" traps, and Play Store redirects. * **Deadlock Recovery (The 100s Hack):** Features an aggressive center-click heuristic to force hidden exit buttons to appear on stubborn interactive ads, preventing system hangs. * **Seamless ADB Integration:** Executes precise, low-latency shell commands (taps and swipes) directly on the emulator, mimicking human interaction. ## 🛠️ Tech Stack * **Language:** Python 3.x * **Computer Vision:** OpenCV (`cv2`) for dynamic template matching and visual state verification. * **Hardware Bridge:** `pure-python-adb` for physical interaction with the Android emulator. * **Data Structures:** `NumPy` for rapid multi-dimensional array operations. * **OCR (Optical Character Recognition):** `PyTesseract` for extracting integer values like in-game currency balances. ## ⚙️ Installation & Setup **1. Clone the Repository:** ```bash git clone [https://github.com/YourUsername/VisionGrid-AI.git](https://github.com/YourUsername/VisionGrid-AI.git) cd VisionGrid-AI 2. Install Dependencies: Ensure you have Python installed, then run: Bash pip install -r requirements.txt 3. Setup Android Emulator: Install an emulator (e.g., LDPlayer or Bluestacks). Enable ADB Debugging in the emulator settings. Ensure your screen resolution matches the template configurations (Standard: 720x1280 or 1080x1920). 4. Run the Engine: Bash python board_engine.py 🧠 System Architecture Vision Module (vision.py): Scans the screen using optimized thresholding (handling dynamic VFX and partial transparency) to locate UI elements. Decision Engine (menu.py & ad_skipper.py): Acts as the FSM. Navigates the main menu, claims rewards, and handles external interruptions. Action Module (core.py): Translates calculated grid coordinates into physical Android swipe/tap gestures.