Pocket monsters for the rest of us
A powerful AI agent that plays Pokemon Red using a Game Boy emulator (PyBoy) and a Large Language Model. Named after the legendary Pokemon Mewtwo, known for its intelligence and psychic abilities.
Get up and running in 5 minutes:
# 1. Clone the repository
git clone https://github.com/jacobyoby/mewtoo.git
cd mewtoo
# 2. Create virtual environment
python -m venv venv
# 3. Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
# 4. Install dependencies
pip install -r requirements.txt
# 5. Install Ollama (for local LLM)
# Download from https://ollama.com, then:
ollama pull llama3.2
# 6. Install Tesseract OCR
# Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki
# macOS: brew install tesseract
# Linux: sudo apt-get install tesseract-ocr
# 7. Run the agent (you need your own Pokemon Red ROM)
python main.py --rom path/to/pokemon_red.gb --steps 100 --displayThat's it! The agent will start playing Pokemon Red. See Quick Start Guide below for more details.
- Play Pokemon Red using PyBoy emulator
- AI agent powered by LLMs (Ollama for local, Claude API for cloud)
- Game state extraction via OCR and memory reading
- Goal-oriented strategy system with exploration/exploitation balance
- Action caching and optimization to reduce LLM calls
- Performance metrics and analytics - Track step timing, cache hit rates, and LLM statistics
- Comprehensive configuration system (config.yaml)
- Action-based gameplay control
Before you begin, ensure you have:
- Python 3.8+ - Download Python
- Tesseract OCR - Required for text extraction
- Windows: Download from Tesseract GitHub
- macOS:
brew install tesseract - Linux:
sudo apt-get install tesseract-ocr
- Pokemon Red ROM (.gb file) - You must provide your own legal copy
- Ollama (for local LLM) - Download Ollama
git clone https://github.com/jacobyoby/mewtoo.git
cd mewtoo# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Download and install Ollama from https://ollama.com
# Then pull a model:
ollama pull llama3.2# Check if everything is set up correctly
python scripts/demo.pyIf you prefer using Claude API instead of Ollama:
# Create a .env file in the project root:
echo "ANTHROPIC_API_KEY=your_api_key_here" > .env# Run with display (recommended for first time)
python main.py --rom path/to/pokemon_red.gb --steps 100 --display --llm-provider ollamaNote: Replace path/to/pokemon_red.gb with the actual path to your Pokemon Red ROM file.
python main.py --rom path/to/pokemon_red.gb --steps 100 --displaypython main.py --rom path/to/pokemon_red.gb --steps 100 --display --soundpython main.py --rom path/to/pokemon_red.gb --steps 100 --llm-provider claude --displaypython main.py --rom path/to/pokemon_red.gb --steps 100 --headlesspython main.py --rom path/to/pokemon_red.gb --steps 100 --display --fastSee QUICKSTART.md for a detailed quick start guide.
--rom: Path to Pokemon Red ROM file (required)--steps: Number of steps to run (default: 100)--llm-provider: LLM provider to use -ollamaorclaude(default: ollama)--model: Model name (optional, uses defaults if not specified)--profile: Strategy profile -aggressive,conservative, orbalanced(default: balanced)--display: Enable display window--sound: Enable sound--headless: Run in headless mode (no display)
mewtoo/
├── main.py # Main entry point
├── pokemon_agent.py # AI agent logic
├── game_state.py # Game state extraction & controls
├── llm_provider.py # LLM integration (Ollama/Claude)
├── llm_optimizer.py # LLM prompt optimization
├── config.py # Configuration helpers
├── requirements.txt # Python dependencies
├── docs/ # Documentation
│ ├── EXTRACT_ROM_GUIDE.md
│ ├── LLM_OPTIMIZATION_GUIDE.md
│ ├── LOGGING_GUIDE.md
│ ├── METRICS_GUIDE.md # Metrics and analytics guide
│ ├── PERFORMANCE_GUIDE.md
│ ├── SETUP_STATUS.md
│ └── ...
├── scripts/ # Utility scripts
│ ├── demo.py # Setup verification demo
│ ├── verify_rom.py # ROM verification script
│ ├── visual_demo.py # Visual demonstration
│ └── analyze_log.py # Log analysis tool
└── logs/ # Agent execution logs (auto-generated)
- PyBoy Emulator: Loads and runs the Pokemon Red ROM
- Game State Extraction: Uses OCR and memory reading to extract game state
- LLM Agent: Analyzes game state and decides on actions
- Action Execution: Sends button presses to the emulator
- Metrics Tracking: Collects performance metrics throughout execution
- Loop: Repeats the process for the specified number of steps
The agent can use these actions:
UP,DOWN,LEFT,RIGHT: MovementA: Confirm/interactB: Cancel/go backSTART: Open menuSELECT: Select buttonWAIT N: Wait N frames
Check if your ROM file is valid:
python scripts/verify_rom.py path/to/pokemon_red.gbVerify your installation:
python scripts/demo.pyAnalyze agent execution logs:
python scripts/analyze_log.py --latest
python scripts/analyze_log.py logs/pokemon_agent_YYYYMMDD_HHMMSS.jsonTest agent's ability to complete early game sequence (v1.0.0 requirement):
# Run validation tests (10 runs by default)
python scripts/validate_early_game.py --rom "path/to/pokemon_red.gb" --runs 10
# Analyze existing log file
python scripts/validate_early_game.py --log-file logs/pokemon_agent_YYYYMMDD_HHMMSS.jsonSee docs/EARLY_GAME_VALIDATION.md for detailed validation guide.
See the docs/ directory for detailed guides:
EXTRACT_ROM_GUIDE.md- How to extract ROM from cartridgeLOGGING_GUIDE.md- Logging and analysis guideMETRICS_GUIDE.md- Metrics and analytics guidePERFORMANCE_GUIDE.md- Performance optimization tipsTROUBLESHOOTING.md- Common issues and solutionssetup_ollama.md- Ollama setup instructions
- Ensure Tesseract is installed and in your PATH
- On Windows, you may need to set the path:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
- Ensure Ollama is running:
ollama serve - Verify model is installed:
ollama list - See
docs/setup_ollama.mdfor detailed setup instructions
- Ensure you have a valid Pokemon Red ROM (.gb file)
- ROM must be a legal copy you own
- Use
scripts/verify_rom.pyto check your ROM file
Mewtoo uses a YAML configuration file (config.yaml) for easy tuning of agent behavior:
- Agent settings: Action history, caching, goal checking intervals
- Strategy settings: Exploration rate, goal priorities
- LLM settings: Token limits, default models
- Performance settings: Cache sizes, frame rates
- OCR/Memory settings: Check intervals, enable/disable features
Command-line arguments override config file settings. See config.yaml for all available options.
Mewtoo includes three pre-configured strategy profiles:
balanced(default): 30% exploration, 70% goal-focused. Standard settings for general gameplay.aggressive: 10% exploration, 90% goal-focused. Fast progress, less exploration, larger cache for speed.conservative: 50% exploration, 50% goal-focused. More thorough exploration, smaller cache, more thoughtful decisions.
Select a profile via command line:
python main.py --rom path/to/pokemon_red.gb --profile aggressive --steps 200Or set active_profile in config.yaml. Profiles can be customized by editing the profiles section in config.yaml.
Mewtoo includes a comprehensive test suite with 123 tests covering:
- Unit Tests: Core module functionality (95 tests)
- Integration Tests: Component integration (11 tests)
- Performance Tests: Benchmarks and regression tests (7 tests)
- End-to-End Tests: Complete gameplay sequences (5 tests)
- Stress Tests: Extended runs and resource limits (6 tests)
- Edge Case Tests: Error recovery and stuck detection (10 tests)
Run tests:
# Run all tests
pytest
# Run specific test categories
pytest -m performance # Performance benchmarks
pytest -m e2e # End-to-end tests
pytest -m stress # Stress tests
pytest -m edge_case # Edge case tests
# Skip slow tests
pytest -m "not slow"See tests/README.md for detailed testing documentation.
Current version: 0.0.7
See CHANGELOG.md for version history and docs/VERSION_HISTORY.md for detailed version information.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
See TODO.md for planned improvements and contribution ideas.
Quick Links:
- Quick Start Guide - Get started in 5 minutes
- Contributing Guide - How to contribute
- Documentation - Comprehensive guides
- Changelog - Version history
This project is licensed under the MIT License - see the LICENSE file for details.
Important:
- This project is for educational purposes only
- You must own a legal copy of Pokemon Red to use ROM files with this software
- ROM files are not included in this repository and must be provided separately
- This project is not affiliated with Nintendo, Game Freak, or The Pokemon Company
- Pokemon is a trademark of Nintendo
- Quick Start Guide - Get started quickly
- Documentation - Comprehensive guides
- Report a Bug - Found a bug?
- Request a Feature - Have an idea?
- Ask a Question - Need help?