ClawSkills logoClawSkills

Pokemon Red

通过 PyBoy 模拟器自主玩宝可梦红。OpenClaw 智能体就是玩家——启动模拟器服务器,查看屏幕截图,从 RAM 读取游戏状态,并

介绍

# Pokemon Red — You Are the Trainer

你直接游玩 Pokemon Red。没有中间人脚本。你启动模拟器服务器,调用其 HTTP API 获取截图和状态,观察屏幕,决定做什么,然后将命令发回。

## 设置(首次使用)

克隆仓库并安装依赖: ```bash git clone https://github.com/drbarq/Pokemon-OpenClaw.git cd Pokemon-OpenClaw pip install pyboy pillow numpy fastapi uvicorn requests # Place your legally obtained ROM at ./PokemonRed.gb ```

将 `POKEMON_DIR` 设置为你克隆仓库的路径(默认:`~/Code/pokemon-openclaw`)。

## 开始会话

```bash # Start emulator server (background process) cd $POKEMON_DIR && python scripts/emulator_server.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. 决定:导航还是手动?

**使用 navigate 进行移动** — 它会阻塞(BLOCKS),直到你到达、进入战斗或卡住: ```bash curl -s -X POST http://localhost:3456/api/navigate \ -H 'Content-Type: application/json' \ -d '{"destination": "Viridian City"}' ```

Navigate 返回以下状态之一: - `"status": "arrived"` — 你到了!继续任务。 - `"status": "battle"` — 遇到野生宝可梦中断。战斗结束后再次导航。 - `"status": "stuck"` — 无法到达目的地。尝试手动按钮或换条路。 - `"status": "error"` — 未知目的地或没有路径。检查目的地列表。

响应始终包含完整的游戏状态,因此你确切知道自己的位置。

**重要:** Navigate 是阻塞的 — 在 curl 调用上设置一个较长的超时时间(60-120秒)。

先检查可用的目的地: ```bash curl -s http://localhost:3456/api/destinations ```

检查哪些地图有寻路数据: ```bash curl -s http://localhost:3456/api/maps ```

**仅在以下情况下回退到手动按钮:** - Navigate 返回 "stuck" 或 "error" - 你在建筑物内进行特定的交互 - 你在对话或菜单中

### 3. 手动控制(需要时) ```bash # 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"}' ``` 有效按钮:`up`、`down`、`left`、`right`、`a`、`b`、`start`、`select`。每回合发送 1-5 个按钮。

### 4. 战斗(当状态中 in_battle 为 true 时) - **战斗:** 按 `a` 打开战斗菜单,再按 `a` 选择 FIGHT,导航到招式,按 `a` 确认,然后在动画过程中狂按 `a` - **逃跑:** 按 `a`,然后按 `down`、`right`、`a` 选择 RUN,在文本过程中狂按 `a` - 之后检查状态 — 如果仍然 `in_battle`,重来一次

### 5. 任务追踪 ```bash curl -s http://localhost:3456/api/quest # Current objective curl -s -X POST http://localhost:3456/api/quest/complete \ -H 'Content-Type: application/json' \ -d '{"lesson": "Door is at x=12"}' # Advance step + save lesson ```

### 6. 频繁保存 ```bash curl -s -X POST http://localhost:3456/api/command \ -H 'Content-Type: application/json' \ -d '{"command": "save", "name": "checkpoint_viridian"}' ```

## 主要端点

| Endpoint | Method | Purpose | |----------|--------|---------| | `/api/state` | GET | 来自 RAM 的游戏状态(位置、队伍、徽章、战斗) | | `/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`。它会阻塞直到到达或战斗 — 无需轮询。 2. **立即处理战斗。** 如果 navigate 返回 `"status": "battle"`,战斗(狂按 A),然后再次导航到相同目的地。 3. **检查任务。** 始终知道你当前的目标。不要乱逛。 4. **HP 管理。** 低于 30% → 考虑治疗。低于 15% → 务必治疗。导航到最近的宝可梦中心。 5. **忽略 text_active。** 文本检测标志有问题(总是为 true)。不要狂按 B 来关闭不存在的文本。 6. **经常保存。** 每 10 个回合或任何里程碑之后。

## 会话模式

子代理会话应该: 1. 启动模拟器服务器(如果尚未运行) 2. 检查任务状态和目的地 3. 游玩 20-50 个回合(根据需要进行导航 + 手动操作) 4. 退出前保存状态 5. 报告进度(位置、等级、任务步骤、任何亮点)

在 `/tmp/pokemon_notepad.txt` 中记录笔记,以便在会话内保持连续性。

## 关于完整游戏策略

请参阅 `references/game_instructions.md` 了解 Pokemon Red 基础知识:移动、建筑物、门、战斗、属性相克、治疗和任务系统。

更多产品