The boundary between human and machine gameplay is rapidly disappearing. Whether you are crafting a sophisticated NPC for a Unity project, engineering a high-frequency trading bot for an MMORPG, or developing an AI agent to master retro emulator games, the foundational challenges remain identical: screen parsing, memory reading, and rapid decision-making. AI Game Bot Framework is a highly optimized, modular toolkit engineered to solve these exact problems.
This repository provides a complete, end-to-end pipeline for building autonomous game agents. It does not merely automate keystrokes; it comprehends the game state. By combining advanced computer vision (YOLOv8) with deep reinforcement learning (PPO), the framework enables you to train agents that learn to play by interacting visually with the game, mimicking human perception and reaction.
Designed for both academic researchers and hobbyist developers, the framework abstracts the complex boilerplate code required for high-speed screen capture, precise input simulation, and sophisticated reward calculation. Whether you are targeting a local emulator instance or interacting with a web-based browser game, the unified API provides total control.
| Module | Description |
|---|---|
| 👁️ Vision Engine | Built-in OpenCV and YOLOv8 integrations for real-time object detection |
| 🧠 RL Brain | Native Stable Baselines3 integration for PPO, DQN, and A2C algorithms |
| 🎮 Input Actuator | Virtual controller and low-latency keyboard/mouse emulation for OS-level control |
| 📊 State Tracker | Automatic OCR for reading dynamic UI elements like health and ammo |
| 🔄 Distributed Trainer | Run multiple game instances in parallel to accelerate learning |
| 🛠️ Plugin System | Swap out vision models or RL algorithms seamlessly with custom plugins |
| ⏺️ Replay Buffer | Save, load, and review gameplay sessions for debugging and analysis |
| ⚡ Low Latency | Utilizes native OS APIs for sub-10ms input latency |
The framework is built on an asynchronous, event-driven architecture. The core loop is divided into three distinct, highly optimized components: Observer, Brain, and Actuator.
The Observer captures the screen at 60 FPS using the dxcam library. It preprocesses the image, resizes it, and feeds it into the vision model. The vision model detects entities like enemies, items, and obstacles, outputting their bounding boxes and class labels.
The Brain receives these bounding boxes and the current game state, converting the data into a state vector. This vector is passed to the reinforcement learning model, which calculates the optimal action based on its learned policy.
The Actuator translates the action into keyboard or mouse inputs. It uses pydirectinput to simulate hardware-level inputs, ensuring compatibility with modern game engines. The entire loop executes in under 16ms, allowing the agent to react to fast-paced events in real-time.
To get started, ensure you have Python 3.9+ and a CUDA-enabled GPU for training the vision models.
# Clone the repository git clone https://github.com/your-username/ai-game-bot-framework.git # Navigate into the directory cd ai-game-bot-framework # Install the required Python dependencies pip install -r requirements.txt # Run the example agent on a retro game (requires an emulator) python examples/train_retro_agent.py
Once the training script starts, you will see a window pop up showing the agent playing the game. The terminal will display the reward metrics in real-time. You can monitor the training progress using TensorBoard by running tensorboard --logdir logs/ in a separate terminal.
The field of AI game automation is advancing rapidly, and we rely on the community to push the boundaries. If you have a new vision model, a better RL algorithm, or just found a bug, we welcome your contributions!
- Fork the repository.
- Create your feature branch (
git checkout -b feature/new-vision-model). - Commit your changes (
git commit -m 'Add new vision model'). - Push to the branch (
git push origin feature/new-vision-model). - Open a Pull Request.
Please read our CONTRIBUTING.md for detailed coding standards and testing requirements. We also have an active Discord server where you can share your agent's gameplay clips, ask for help with reward engineering, and discuss the latest trends in game AI.
- 💬 Discussions: Join the conversation in the GitHub Discussions tab.
- 🐛 Issues: Found a bug? Let us know via the Issues tracker.
- 📧 Email: Reach out directly at [email protected].