🎮 A fundamentally different AI gaming approach that shifts from Reinforcement Learning training loops to Orchestrated Intelligence with hierarchical memory and strategic reasoning.
Current AI gaming projects fail because they treat Pokémon as a simple button-pressing problem. PTP-01X understands the truth:
- 50+ distinct gameplay states - not just "battle", "overworld", "menu"
- 20+ hour gameplay journey with interconnected strategic decisions
- 151 Pokémon to catalog, learn types, moves, and abilities
- 8 Gyms + Elite Four requiring team composition planning
| Approach | Problem | PTP-01X Solution |
|---|---|---|
| Stochastic Parrot | Throws pixels at model, hopes for correlation | Multi-phase state machine recognition |
| Context Amnesia | Treats every tick as independent | 3-tier memory hierarchy (Observer → Strategist → Tactician) |
| Memory Hoarding | Keeps all data until token limits hit | Intelligent compression & retrieval |
| No Strategic Planning | Immediate tactics only | GOAP decision core with hierarchical layers |
┌─────────────────────────────────────────────────────────────────┐
│ PTP-01X ORCHESTRATION LAYER │
├─────────────────────────────────────────────────────────────────┤
│ Observer (Long-term) │ Strategist (Session) │ Tactician │
│ • Journey progress │ • Battle lessons │ • HP/status │
│ • Badge history │ • Route knowledge │ • Active │
│ • Party evolution │ • Resource strategies │ • Immediate │
│ • Meta-analysis │ • Failure analysis │ objectives │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ GOAP DECISION CORE │
│ • Goal stack management • Hierarchical planning layers │
│ • Critical path analysis • Action execution with recovery │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ PERCEPTION & EXECUTION │
│ • Vision & OCR pipeline • Hierarchical state machine │
│ • Battle heuristics • World navigation & pathfinding │
│ • Entity management • Inventory & item logistics │
│ • Dialogue systems • Failsafe & recovery protocols │
└─────────────────────────────────────────────────────────────────┘
~53,500 lines of comprehensive technical documentation covering all aspects of autonomous Pokémon gameplay:
| Chapter | Focus | Lines |
|---|---|---|
| 1 | Vision & Perception Engine | ~1,500 |
| 2 | Hierarchical State Machine | ~1,200 |
| 3 | Tactical Combat Heuristics | ~1,300 |
| 4 | World Navigation & Spatial Memory | ~1,500 |
| 5 | Data Persistence & Cognitive Schema | ~1,400 |
| 6 | Entity Management & Party Optimization | ~1,650 |
| 7 | Inventory & Item Logistics | ~1,400 |
| 8 | Dialogue & Interaction Systems | ~1,600 |
| 9 | GOAP Decision Core | ~1,800 |
| 10 | Failsafe Protocols & System Integrity | ~1,500 |
| — | CLI Control Infrastructure | ~10,000 |
| — | Mode Duration Tracking & Anomaly Detection | ~2,000 |
| — | Edge Cases & Recovery Protocols | ~3,000 |
Each chapter follows a spec-driven format with:
- Mermaid flowcharts for visual logic
- Pseudo-code for implementation details
- LLM reasoning prompts for AI decision-making
Tier 1: Persistent Observer (Long-term Narrative)
- Journey progress: Badges, gyms defeated, regions explored
- Party evolution: Caught, leveled, released Pokémon
- Strategic milestones: First gym, rare catches, speedrun records
Tier 2: Strategic Memory (Session-long Learning)
- Battle lessons: Type matchups, move effectiveness
- Route knowledge: Shortest paths, catch rates, encounter frequencies
- Resource strategies: Healing priorities, money allocation
Tier 3: Tactical Memory (Immediate Context)
- Current HP/status of all 6 Pokémon
- Active battle state and turn-by-turn analysis
- Recent actions and immediate objectives
Hierarchical planning layers operating at different timescales:
- Strategic Layer (1000+ cycles): Team composition, gym preparation
- Tactical Layer (30-100 cycles): Route planning, resource management
- Operational Layer (5-30 cycles): Battle decisions, navigation
- Reactive Layer (0-5 cycles): Emergency responses, immediate threats
- Confidence scoring with 5-tier escalation
- Softlock detection (position deadlock, menu loops, battle stalls)
- Death spiral prevention with linear regression analysis
- Emergency recovery (in-place → navigate → reload → reset)
Statistical deviation detection for anomaly handling:
- Learns normal duration for each mode (e.g., wild battles: 30-120s, p95=300s)
- Triggers break-out when exceeding statistical thresholds
- Adaptive threshold calculation with EWMA-based learning
Place your ROM in: data/rom/
| Generation | Games |
|---|---|
| Gen 1 (Game Boy) | Red, Blue, Green, Yellow |
| Gen 2 (Game Boy Color) | Gold, Silver |
To change games: Edit config/settings.yaml and change rom.path
# 1. Create virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 2. Install dependencies
pip install -r requirements.txt
# 3. Set up API key
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
# 4. Select your game
# Edit config/settings.yaml -> rom.path (default: data/rom/pokemon_blue.gb)
# 5. Run the AI (basic)
python3 src/game_loop.py --rom data/rom/pokemon_blue.gb --save-dir runs/test_001The main entry point is src/game_loop.py which accepts the following arguments:
| Argument | Description |
|---|---|
--rom |
Path to Pokemon ROM file (.gb or .gbc) |
| Argument | Default | Description |
|---|---|---|
--save-dir |
./game_saves |
Directory for saves, database, and screenshots |
--screenshot-interval |
60 | Ticks between screenshots (60 = ~1 second at 60fps) |
--max-ticks |
None | Maximum ticks to run before stopping (optional) |
--load-state |
None | Load existing emulator state file |
--multi-instance |
False | Run multiple emulator instances simultaneously |
--instances |
3 | Number of instances for multi-instance mode |
Basic run:
python3 src/game_loop.py --rom data/rom/pokemon_blue.gbWith screenshots every 30 ticks:
python3 src/game_loop.py --rom data/rom/pokemon_blue.gb --screenshot-interval 30 --save-dir runs/screenshots_testWith max ticks limit (10000 ticks ~ 3 minutes at max speed):
python3 src/game_loop.py --rom data/rom/pokemon_blue.gb --max-ticks 10000 --save-dir runs/test_001Complete example with all options:
python3 src/game_loop.py \
--rom data/rom/pokemon_blue.gb \
--save-dir runs/test_001 \
--screenshot-interval 60 \
--max-ticks 10000Run with different ROM:
python3 src/game_loop.py --rom data/rom/pokemon_red.gb --save-dir runs/red_runLoad from saved state:
python3 src/game_loop.py --rom data/rom/pokemon_blue.gb --load-state runs/test_001/emulator_state.stateEach run creates the following structure in --save-dir:
runs/test_001/
├── game_data.db # SQLite database with all session data
├── emulator_state.state # Emulator save state
└── screenshots/ # Screenshot captures
├── screenshot_0060.png
├── screenshot_0120.png
└── ...
# Run all tests with verbose output
pytest tests/ -v
# Run with coverage report
pytest --cov=src --cov-report=html
# Run with coverage and terminal summary
pytest --cov=src --cov-report=term-missing# Run a specific test file
pytest tests/test_schemas.py -v
# Run tests in a specific directory
pytest tests/cli/ -v
# Run a specific test function
pytest tests/test_schemas.py::test_command_creation -v
# Run tests matching a pattern
pytest -k "battle" -v# Unit tests only (fast)
pytest tests/ -v -m "not integration"
# Integration tests (slower, may require emulator)
pytest tests/ -v -m "integration"
# Run tests in parallel
pytest tests/ -n auto -v# After running with coverage, view HTML report
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux
start htmlcov/index.html # WindowsERROR: ROM file not found: data/rom/pokemon_blue.gb
Solution: Verify the ROM path is correct. ROMs should be in data/rom/:
ls data/rom/
# Should show: pokemon_red.gb, pokemon_blue.gb, etc.ModuleNotFoundError: No module named 'pyboy'
Solution: Install dependencies in your virtual environment:
source venv/bin/activate
pip install -r requirements.txtWARNING: No OpenRouter API key found. Using stub AI mode
Solution: Create .env file with your API key:
cp .env.example .env
# Edit .env and add your API keysqlite3.OperationalError: unable to open database file
Solution: Ensure the save directory exists and is writable:
mkdir -p runs/test_001
python3 src/game_loop.py --rom data/rom/pokemon_blue.gb --save-dir runs/test_001ERROR: Emulator crashed at tick 150
Solutions:
- Try a different ROM (some ROM hacks may have compatibility issues)
- Reduce screenshot frequency:
--screenshot-interval 120 - Limit max ticks:
--max-ticks 5000 - Check available memory:
free -h(Linux) orActivity Monitor(macOS)
Symptoms: Low ticks per second, stuttering, high CPU
Solutions:
- Increase screenshot interval:
--screenshot-interval 120 - Set max ticks to limit session length
- Close other applications
- Ensure virtual environment is activated
- Get an API key from https://platform.openai.com/api-keys
- Add to
.env:OPENAI_API_KEY=sk-your-key-here - Verify in config/settings.yaml that
models.thinking_model.provideris set to "openai"
OpenRouter provides access to multiple models including GPT-4 and Claude:
- Get API key from https://openrouter.ai
- Add to
.env:OPENROUTER_API_KEY=your-key-here - Configure in settings.yaml with your preferred model
# Test API key is loaded
source venv/bin/activate
python3 -c "from dotenv import load_dotenv; from pathlib import Path; load_dotenv(Path('.env')); import os; print('API Key set:', bool(os.getenv('OPENAI_API_KEY')))"Solutions:
- ROM may be corrupted - try a different ROM file
- Verify ROM is the correct version for your emulator settings
- Check emulator speed setting in
config/settings.yaml
Solutions:
- Ensure save state file exists:
ls runs/test_001/emulator_state.state - Try without loading state first to establish baseline
- Verify ROM version matches the save state
Error reading memory at address 0xD158
Solutions:
- This is expected if the game hasn't loaded yet
- Memory addresses may vary by ROM version
- Check logs/ directory for detailed error traces
- Check logs: All errors are logged to
logs/directory - Run in debug mode: Increase verbosity by checking console output
- Search existing issues: Check GitHub issues for similar problems
- Create new issue: Include:
- Full error message and traceback
- Operating system and Python version
- ROM file name and version
- Command used to run
- Python 3.10+
- 1GB storage for logs/memory
- Internet connection (for API calls)
- PyBoy emulator (Game Boy/Game Boy Color emulation)
- OpenAI API Key (GPT-4V/GPT-4o-mini) - enables real AI mode
- Without API key: runs in stub AI mode for testing
# Core dependencies (installed automatically)
pyboy>=1.0.0 # Game Boy emulator
requests>=2.31.0 # HTTP client for LLM APIs
numpy>=1.24.0 # Numerical operations
Pillow>=10.0.0 # Image processing
pydantic>=2.0 # Data validation
python-dotenv>=1.0 # Environment variable management
opencv-python>=4.8.0 # Image processing pipeline
# Development dependencies (optional)
pytest>=7.0 # Testing framework
pytest-cov>=4.0 # Coverage reporting
black>=23.0 # Code formatter
mypy>=1.0 # Type checking
flake8>=6.0 # Linting
| System | Target |
|---|---|
| Vision/OCR | <1 second per screen |
| State transition | <0.5 second |
| Combat move selection | <0.5 second |
| Pathfinding (A*) | <1 second for 50-tile path |
| GOAP goal planning | <3 seconds for full stack |
| Softlock detection | <5 seconds |
| Emergency recovery | <10 seconds |
├── memory-bank/ # Architecture documentation
│ ├── projectBrief.md # Core vision and paradigm shift
│ ├── productContext.md # Problem statements & solutions
│ ├── activeContext.md # Current work focus
│ ├── systemPatterns.md # System architecture & patterns
│ ├── techContext.md # Technologies & setup
│ └── progress.md # Implementation roadmap
├── specs/ # Technical specifications
│ ├── ptp_01x_detailed/ # 10 complete chapters
│ ├── ptp_01x_cli_control_infrastructure.md
│ ├── ptp_01x_mode_duration_tracking.md
│ └── ptp_01x_edge_cases_recovery.md
├── prompts/ # LLM prompt engineering
│ ├── battle/ # Combat decision-making
│ ├── dialog/ # Dialogue parsing
│ ├── exploration/ # Navigation logic
│ ├── menu/ # Menu interactions
│ └── strategic/ # Long-term strategy
├── src/ # Implementation framework
│ ├── core/ # AI core systems
│ ├── db/ # Database operations
│ └── schemas/ # Command definitions
└── config/ # Configuration files
- Start Here: memory-bank/projectBrief.md
- Architecture: memory-bank/systemPatterns.md
- Progress: memory-bank/progress.md
- Specifications: specs/ptp_01x_detailed/
- API Reference: docs/api/index.md - Complete API documentation for GameLoop, GameAIManager, Database, and data structures
Contributions are welcome! Please see CONTRIBUTING.md for detailed guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Install development dependencies:
pip install -r requirements-dev.txt - Run tests:
pytest tests/ -v - Format code:
black src/ tests/ - Submit a pull request
MIT License - See LICENSE file for details.
PTP-01X - Orchestrated Intelligence for Autonomous Gameplay
Last Updated: December 31, 2025