Pokemon Red — You Are the Trainer
You play Pokemon Red directly. No middleman script. You start the emulator server, hit its HTTP API for screenshots and state, look at the screen, decide what to do, and send commands back.
Setup (first time)
Clone the repo and install dependencies:
CODEBLOCK0
Set POKEMON_DIR to wherever you cloned the repo (default: ~/Code/pokemon-openclaw).
Start a Session
CODEBLOCK1
Turn Loop
Every turn, do these in order:
1. Get state + screenshot
curl -s http://localhost:3456/api/state
curl -s http://localhost:3456/api/screenshot -o /tmp/pokemon_current.png
Then use the
image tool to look at the screenshot.
Always look before acting.
2. Decide: Navigate or Manual?
Use navigate for travel — it BLOCKS until you arrive, hit a battle, or get stuck:
CODEBLOCK3
Navigate returns one of:
- -
"status": "arrived" — you're there! Continue quest. - INLINECODE4 — wild encounter interrupted. Fight it, then navigate again.
- INLINECODE5 — couldn't reach destination. Try manual buttons or different route.
- INLINECODE6 — unknown destination or no path. Check destinations list.
The response always includes full game state, so you know exactly where you are.
Important: Navigate blocks — set a long timeout (60-120s) on the curl call.
Check available destinations first:
CODEBLOCK4
Check which maps have pathfinding data:
CODEBLOCK5
Fall back to manual buttons only when:
- - Navigate returns "stuck" or "error"
- You're inside a building doing specific interactions
- You're in dialogue or a menu
3. Manual controls (when needed)
# Move / interact
curl -s -X POST http://localhost:3456/api/press \
-H 'Content-Type: application/json' \
-d '{"buttons": ["up","up","a"], "reasoning": "Walking to door"}'
Valid buttons:
up,
down,
left,
right,
a,
b,
start,
select. Send 1-5 per turn.
4. Battle (when in_battle is true in state)
- - Fight: Press
a to open fight menu, a again for FIGHT, navigate to move, a to confirm, then mash a through animations - Run: Press
a, then down, right, a to select RUN, mash a through text - Check state after — if still
in_battle, go again
5. Quest tracking
CODEBLOCK7
6. Save frequently
CODEBLOCK8
Key Endpoints
| Endpoint | Method | Purpose |
|---|
| INLINECODE25 | GET | Game state from RAM (position, party, badges, battle) |
| INLINECODE26 |
GET | PNG screenshot of game screen |
|
/api/navigate | POST | Pathfind to named destination |
|
/api/destinations | GET | List all navigation destinations |
|
/api/maps | GET | Which maps have pathfinding data |
|
/api/press | POST | Send button presses |
|
/api/quest | GET | Current quest and step |
|
/api/quest/complete | POST | Mark step done, optionally save a lesson |
|
/api/knowledge | GET | All lessons learned |
|
/api/knowledge/lesson | POST | Add a new lesson |
|
/api/command | POST | Save/load/speed commands |
Strategy Priority
- 1. Navigate first. For any travel, use
/api/navigate. It blocks until arrival or battle — no polling needed. - Handle battles immediately. If navigate returns
"status": "battle", fight (mash A), then navigate again to the same destination. - Check quest. Always know your current objective. Don't wander.
- HP management. Below 30% → consider healing. Below 15% → definitely heal. Navigate to nearest pokecenter.
- Ignore text_active. The text detection flag is broken (always true). Don't spam B to dismiss phantom text.
- Save often. Every 10 turns or after any milestone.
Session Pattern
A sub-agent session should:
- 1. Start emulator server (if not already running)
- Check quest status and destinations
- Play 20-50 turns (navigate + manual as needed)
- Save state before exiting
- Report progress (location, level, quest step, any highlights)
Keep notes in /tmp/pokemon_notepad.txt for continuity within a session.
For Full Game Strategy
See references/game_instructions.md for Pokemon Red basics: movement, buildings, doors, battles, type matchups, healing, and the quest system.
宝可梦 红 — 你就是训练家
你直接游玩《宝可梦 红》。无需中间脚本。你启动模拟器服务器,通过其HTTP API获取截图和状态,查看屏幕,决定下一步行动,并发送指令返回。
初始设置(首次使用)
克隆仓库并安装依赖:
bash
git clone https://github.com/drbarq/Pokemon-OpenClaw.git
cd Pokemon-OpenClaw
pip install pyboy pillow numpy fastapi uvicorn requests
将合法获取的ROM文件放置在 ./PokemonRed.gb
将 POKEMON_DIR 设置为克隆仓库的路径(默认:~/Code/pokemon-openclaw)。
启动会话
bash
启动模拟器服务器(后台进程)
cd $POKEMON
DIR && python scripts/emulatorserver.py --save ready --port 3456
回合循环
每回合按顺序执行以下操作:
1. 获取状态 + 截图
bash
curl -s http://localhost:3456/api/state
curl -s http://localhost:3456/api/screenshot -o /tmp/pokemon_current.png
然后使用 image 工具查看截图。行动前务必先查看。
2. 决策:导航还是手动操作?
旅行时使用导航——它会阻塞直到你到达目的地、遭遇战斗或卡住:
bash
curl -s -X POST http://localhost:3456/api/navigate \
-H Content-Type: application/json \
-d {destination: 常磐市}
导航返回以下状态之一:
- - status: arrived — 已到达!继续任务。
- status: battle — 遭遇野生宝可梦中断。先战斗,然后再次导航。
- status: stuck — 无法到达目的地。尝试手动按键或选择不同路线。
- status: error — 未知目的地或无路径。检查目的地列表。
响应始终包含完整的游戏状态,因此你能确切知道自己的位置。
重要提示: 导航会阻塞——在curl调用中设置较长的超时时间(60-120秒)。
先检查可用目的地:
bash
curl -s http://localhost:3456/api/destinations
检查哪些地图有寻路数据:
bash
curl -s http://localhost:3456/api/maps
仅在以下情况回退到手动按键:
- - 导航返回 stuck 或 error
- 你在建筑物内进行特定交互
- 你处于对话或菜单中
3. 手动控制(需要时)
bash
移动/交互
curl -s -X POST http://localhost:3456/api/press \
-H Content-Type: application/json \
-d {buttons: [up,up,a], reasoning: 走向门口}
有效按键:up、down、left、right、a、b、start、select。每回合发送1-5个按键。
4. 战斗(当状态中 in_battle 为 true 时)
- - 战斗: 按 a 打开战斗菜单,再次按 a 选择战斗,导航到招式,按 a 确认,然后连续按 a 跳过动画
- 逃跑: 按 a,然后按 down、right、a 选择逃跑,连续按 a 跳过文本
- 检查状态——如果仍处于 in_battle,重复操作
5. 任务追踪
bash
curl -s http://localhost:3456/api/quest # 当前目标
curl -s -X POST http://localhost:3456/api/quest/complete \
-H Content-Type: application/json \
-d {lesson: 门在x=12的位置} # 推进步骤 + 保存经验
6. 频繁保存
bash
curl -s -X POST http://localhost:3456/api/command \
-H Content-Type: application/json \
-d {command: save, name: checkpoint_viridian}
关键端点
| 端点 | 方法 | 用途 |
|---|
| /api/state | GET | 从内存获取游戏状态(位置、队伍、徽章、战斗) |
| /api/screenshot |
GET | 游戏画面的PNG截图 |
| /api/navigate | POST | 寻路到指定目的地 |
| /api/destinations | GET | 列出所有导航目的地 |
| /api/maps | GET | 哪些地图有寻路数据 |
| /api/press | POST | 发送按键指令 |
| /api/quest | GET | 当前任务和步骤 |
| /api/quest/complete | POST | 标记步骤完成,可选保存经验 |
| /api/knowledge | GET | 所有已学经验 |
| /api/knowledge/lesson | POST | 添加新经验 |
| /api/command | POST | 保存/加载/速度指令 |
策略优先级
- 1. 优先使用导航。 任何旅行都使用 /api/navigate。它会阻塞直到到达或战斗——无需轮询。
- 立即处理战斗。 如果导航返回 status: battle,先战斗(连续按A),然后再次导航到同一目的地。
- 检查任务。 始终了解当前目标。不要漫无目的地游荡。
- HP管理。 低于30% → 考虑治疗。低于15% → 必须治疗。导航到最近的宝可梦中心。
- 忽略 text_active。 文本检测标志有缺陷(始终为true)。不要连续按B来消除幻影文本。
- 频繁保存。 每10回合或达成任何里程碑后保存。
会话模式
子代理会话应:
- 1. 启动模拟器服务器(如果尚未运行)
- 检查任务状态和目的地
- 游玩20-50回合(根据需要导航+手动操作)
- 退出前保存状态
- 报告进度(位置、等级、任务步骤、任何亮点)
在 /tmp/pokemon_notepad.txt 中记录笔记,以保持会话内的连续性。
完整游戏策略
参见 references/game_instructions.md 了解《宝可梦 红》的基础知识:移动、建筑、门、战斗、属性相克、治疗和任务系统。