跳到正文
Simon Willison·· 2026-10-21精选

Simon Willison 复盘用编码智能体迭代浏览器 RTS 游戏

AI 导读

Simon Willison 分享 Battle Drones 的开发过程,通过多轮提示与试玩把原型改进为支持手机和桌面的策略游戏,并尝试设备间通过声音同步多人状态。作者明确表示大部分代码未经逐行审阅,文章展示的是个人实验。

推荐理由

Codex 来源核对 · 保留原作者的风险说明,把项目迭代经验与产品成功证明区分开。

正文 · AI 翻译

2026年10月20日

我最新的氛围编程游戏实验是一款《命令与征服》风格的 RTS(即时战略)游戏,名叫 Battle Drones(点这里玩)。与我之前的实验不同,这款游戏真的很好玩。有点不好意思承认,我是通过告诉 Claude“让它好玩得多得多”才做到这一点的。它还支持附近设备之间的多人对战,通过声音同步游戏状态!下面是我目前做出的东西,以及在这个过程中学到的一些事情。

Battle Drones

我最初的目标是做一款能在手机上玩的 RTS 游戏,风格类似《命令与征服》。我对 1995 年的初代作品有着美好的回忆(我也喜欢《红色警戒》),想找回一点当年的魔力。

经过 12 次重大迭代(以及编程智能体完成的 321 次提交,主要来自 Claude Code),我现在有了一款能在手机和电脑上运行的浏览器游戏,包含多种游玩模式、几张地图(包括随机地图生成器),甚至支持两台处于彼此麦克风收音范围内的设备进行多人对战。(更新:也支持在线多人对战了;声音多人对战会引发头痛!)

下面是 Battle Drones 在桌面浏览器中运行的视频演示:

目前已有的功能包括:

  • 9 种建筑、7 种地面载具、6 种飞行载具、3 种步兵单位,全都采用 3D 模型,你可以在这里浏览
  • 战争迷雾
  • 攻击空中或地面载具需要使用不同的武器
  • 六张地图,横跨五种生态环境——温带、沙漠、极地、火山、热带
  • 随机地图生成器
  • 遭遇战模式——红蓝双方在旋转对称的地图上对战
  • 背水一战模式——一名玩家尽可能抵挡更多波敌人
  • 范围效果武器:弹幕轰炸、EMP、空投舱、天锤
  • 空投补给箱,提供额外资源
  • 会随事件变化的游戏音乐——战斗爆发时,音乐会变得更加激烈
  • 不同的游戏内 AI 性格(均衡、快攻、空中蜂群、经济扩张、空军、铁甲)
  • AI 对战 AI 模式,可以观看这些不同性格的 AI 互相交战
  • Goliath——一台迈着沉重步伐的巨型机甲,拥有激光眼、臂炮,还能建立新基地
  • 变异规则,增加额外规则或玩法变化
  • “每日行动”挑战
  • 军衔与成就(勋章)
  • 智能体对战智能体模式,让两个大语言模型在 Battle Drones 中彼此对战
  • 一种多人对战模式,通过两部相邻手机之间的声音消息进行通信,延续了我之前的 Chirp Pong 实验

我是怎么做出来的

Battle Drones 大量采用氛围编程——我几乎没审查过代码,而且它使用的语言(TypeScript)我自己也没怎么用过。不过,我做了不少试玩测试,从项目启动以来,它已经经历了大量迭代。

下面粗略回顾一下项目至今的发展过程,包括关键提示词和对话记录链接。

v1:最初的原型

早在 7 月,我就开始用 Claude Fable 5 做这个项目:

We are going to build a mobile friendly RTS game - command and conquer style - called Battle Drones, in which two armies of drones (both flying and ground-based) battle for territory and resources

Let's start with a MVP design, ask me some questions

这是分享的对话记录。我通过环境变量给 Claude Code for Web 提供了一个 OpenAI API 密钥,并让它使用 OpenAI 的图像生成 API 制作素材,于是得到了一些基础精灵图。

你可以在这里试玩 v1——它当时是这样的:

Game screen. Down the right are text icons to build Fab, Airpad, Turret, Harv, Sting, Flak, Scout, Wasp, Raptor. There is a blocky fog of war on a 2D battlefield. There are some gems, an HQ building being attacked by badly rendered tanks, and some blue vehicles dotted around. It's not very visually impressive but it does look like a basic RTS.

它已经能看出是一款 RTS,有建造机制,可以选择和指挥单位,也有一个基础 AI 作为对手。

这个初版勉强算是概念验证,玩起来毫无乐趣。

Claude 在这些早期版本中使用了 Phaser 2D 游戏框架。我直到又迭代了好几个版本后才意识到这一点!

v2:完整的精灵图

第二个版本(在这里试玩 v2)为所有载具添加了精灵图,还加入了“AI 对战 AI”模式,这样我就能观看游戏自行对战,不必亲自操控。

事实证明,Claude 在编写提示词、让 OpenAI 图像模型生成精灵图这件事上相当称职。你可以在 public/assets/sprites 文件夹中浏览 v2 的精灵图。

Four flying units, three turrets, a harvester and an airpad all have proper sprites now. The scrap field has a new design which doesn't look great but is at least using a graphic.

v3:多样的地形

它依然不怎么好玩,画面也很无趣。此时已经到了 10 月,我升级到了 Claude Opus 5.5。我告诉它:

Massively improve this game. Make the graphics and gameplay better (keep it mobile friendly). Render new graphics using the latest OpenAI GPT image API (lookup details) with the API key in the environment variable. Add new unit types and balance the gameplay better. Also add new buildings and better, more varied terrain.

这带来了五张新地图,使用生成的多种风格背景图块,可以在这里查看。Opus 还重新生成了精灵图,让它们在视觉上好看了很多。你可以在这里试玩 v3——它看起来是这样的:

The map is now an ice map with snow and ice and broken ice - it looks really good. The vehicles and buildings have all had a cosmetic upgrade too. This is starting to look like a real game.

这开始有真正游戏的感觉了!不过玩起来还是不怎么有趣——我发现自己很快就会觉得无聊。

v4:趣味性更新

到目前为止,Battle Drones 实验一直在印证我之前的看法:编程智能体能做出看起来像游戏的东西,却做不出真正让人玩得入迷的东西。

我吃晚饭时和一个人聊起了这个观点,随后心想,应该给模型一个充分的机会,让它们证明我错了。我在手机上给 Opus 5.5 输入了提示词:

This game isn't fun enough yet. Make it a LOT more fun.

这次我使用的是 Ultracode 模式,在这个模式下,Claude Code(此处是 Claude Code for Web)会运行“动态工作流”,其文档中的描述是:

动态工作流是一段 JavaScript 脚本,用于同时编排多个子智能体。

这启动了好多个小时的工作。我晚上开始运行,直到第二天上午很晚的时候,才拿到可以玩的结果。但成果非常惊艳。

你可以在这里试玩 v4——它看起来是这样的:

The lava map. Uplink satellites are being taken, crystals look better, Elite text is shown above a unit, there is an arrow marked Fight to jump to a fight, the AI vs AI mode has a speed controller - plenty of new features here.

我让 Claude 自己撰写了发布说明——以下是重点:

现在,每场遭遇战和每日行动都会以一次选择开局,给落后的一方翻盘的机会,并把双方军队引向地图中央。此外还增加了两种新玩法。

  • 开局方案:计时开始前,选择闪电战、工业或航空联队。
  • 呼叫支援能力:弹幕轰炸、EMP、空投舱和天锤轨道打击。
  • 目标与回收:上行链路中继站、空投补给,以及可回收为废料的残骸。
  • 体验:战斗反馈、自适应音乐、单位语音和播报员。
  • 指挥:战斗警报、游戏速度、保存编组和触屏放置。
  • 新模式:背水一战的波次生存模式,以及包含 8 个任务的行动战役。
  • 成长:英雄、附带奖励的战后报告、生涯、7 种变异规则和每日行动。

交战持续得更久,局势起伏也更大。在普通难度的 1,200 场 AI 对战 AI 测试中,25 分钟后仍未分出胜负的对局比例从 14% 降至 0.9%。曾落后 800 以上废料的一方最终获胜的比例,从 24% 上升到 46%。

Claude 花了这么久,部分原因是它进行了上千场模拟试玩,并根据结果重新平衡已有单位、添加新单位,以及引入新功能。

v5:Battle Drones 迈入 3D

Ultracode 成功完成“让它好玩得多得多”之后,我决定更大胆一些:

Port this game to three.js with 3D models for all of the buildings and vehicles and landscapes

这又是一次通宵运行。我醒来时,看到了这个 v5 版本:

Now it is in 3D - the battlefield is at a slight angle, the buildings and vehicles are all 3D models, the rocks and trees look a bit 3D as well.

新的 3D 模型完全由 Claude 用 TypeScript 代码构建。

v6(在这里玩 v6)进一步打磨了视觉效果。v7(玩 v7)添加了机器人步兵(步兵、火箭小队、狙击手)和一种名为“Condor”的运兵飞机。

v8:群岛

我开始为自己在游戏设计上实际投入得如此之少感到内疚——过去几个版本,我真的就只是在说“让它更好玩”和“打磨视觉效果”。

我注意到,AI 很少使用 v7 新增的步兵和运兵飞机——从战略上说,没有什么特别充分的理由去使用它们。

如果能有一张新地图,加入一种新的游戏机制,主动鼓励玩家给 Condor 装上机器人步兵,再把它们派到地图各处,那应该很不错。

于是,我写出了迄今为止最长的一条提示词:

Design a new map. Goal is to make different strategic incentives that encourage use of Infantry and Condors and aerial vehicles.

To do this the map will have limited harvester resources but several more uplinks - but uplinks will be on islands that are inaccessible by land vehicles or infantry. These uplinks can also not be claimed using air vehicles. The ONLY way to get them is to fly infantry there in a Condor.

Armies always start with a Condor and a single squad. If an army has no Condor a new one will be provided for free, flying in from the edge closest to their HQ and landing there. That free condor will come with a single free squad on board.

The two HQs should be entirely separated by water, but still accessible by vehicles thanks to two bridges across the map in different places

I want to encourage a battle over uplinks.

The map should be the times the size of other maps - still square

First research and then critique this design. Only build after we have agreed on any modifications

You get to design a new biome for this

成果就是热带群岛地图,上面有七座岛屿上行链路站,玩家只能用 Condor 运送步兵过去才能占领。在较简单的地图上掌握基本游戏机制之后,这绝对是最好玩的一张地图。v9 版本让这张地图又有趣了一些——它现在看起来是这样的:

Three islands, each with an uplink satellite. Blue holds one, red holds another, A blue condor is flying towards the red island, which is guarded by a red plane. There is a bridge nearby. The theme is tropical islands and looks very pleasant.

v10:Goliath 与智能体对战

我决定给游戏加入巨型机器人机甲——可以想象成《环太平洋》中的贼鸥机甲,或《战锤 40,000》中的泰坦。

下面是我和 Claude 头脑风暴时用到的一些提示词:

Help me brainstorm ideas for adding giant robots to this game - think dreadnoughts or titans from W20K - how could we do this in a way that enhanced gameplay, kept things balanced, added unique twist? Don't overthink this yet

Let's keep brainstorming. I like the idea that it's a mobile base - that can accept harvested scrap and can have buildings built near it (even if it later moves on) and can produce infantry units too. An interaction with condor would be neat but I don't know what that could be.

Idea: as it gets damage it loses the ability to fire some weapons - by default it has eye laser (like lancers) and arm canons (like titan) and two shoulder mounted mortars, plus machine guns similar to a squad of troops

Damage knocks out mortars and then laser - it always has guns. You can't build next to a building that was only put there because of the mech, you need the mech there for off-base building and only within three squares of it

[...] Lets do two condors can carry the mech

最终结果真的很酷。

Goliath 可以通过 Gantry 建造——只有先建好 Fab、Bay、Airpad 和 Tech Lab,才能建造 Gantry 这座建筑。你能看到 Goliath 的建造过程,完成后它会从 Gantry 中走出来,并且可以在地图上行走。

Goliath 可以“锚定”,将自身固定在地面中。在锚定状态下,它们可以充当新的总部,在新区域生产步兵单位和建造更多建筑。

两架 Condor 飞机可以挂接到一台 Goliath 上,然后就能把它吊运到地图各处!

现在,只有摧毁敌方总部建筑以及他们可能建造的所有 Goliath,游戏才会结束。

还有两种与 Goliath 有关的变异规则:

  • Goliath 舰队让双方在开局时各拥有四台空运中的 Goliath(每台配有两架 Condor),没有其他单位。
  • 机器人之恋增加了一条特殊规则:如果敌对的 Goliath 在战场上彼此靠近,它们就会坠入爱河,游戏以平局结束。(这个点子要感谢 Natalie。)

智能体对战

v10 的另一个功能是智能体对战。在琢磨多人对战可以如何实现时,我有了一个想法:如果让不同的大语言模型在游戏里交战,会怎么样?

Fun extra challenge: think about how we might make multiplayer available to coding agents. It would be neat if we could set up a battle between eg GPT-6 Sol and Claude Opus 5.5 where each model has access to a tool which gives them information about the game (presumably non-visual, but only the information they could see through fog of war etc) and lets them control their units etc [...]

Consult ~/dev/llm/docs and include notes in that file about how LLM could be used here via a new tools plugin

Opus 5.5 开始着手这项工作,写出了这份 AGENT-BATTLES.md 提案,随后实现并测试了它。这个功能还支持录制和回放这些对战——这里有一场 Claude Haiku 5.5 对战 GPT-6 Luna 的回放,同一场对战也可以在一个独立调试工具中查看,它会展示底层的提示词响应。

Screenshot of a replay of a real-time strategy game between two AI models, shown from a top-down view of a snowy map with a dark frozen lake of cracked ice floes on the left and pine forests at the top and lower right. Top bar: pause button, "6:27", "1×", "anthropic/claude-haiku-5-5 · industry" in blue, "gpt-6-luna · industry" in red, a blue-and-red strength bar labeled "B" and "R", and "0:03". Left notification: "Blue: Pushing turrets at the enemy's south-east edge." Replay panel: "Blue anthropic/claude-haiku-5-5 · industry vs Red gpt-6-luna · industry · frostbite seed 42", a timeline slider at "6:27 / 7:48", and buttons "−30s", "+30s", "All", "Blue's eyes", "Red's eyes", "Notes". In the scene, a group of blue tanks and a large blue Goliath mech trailing smoke advance near the ice edge at lower center, while a column of red turrets (one burning) lines the ice to their north, red tanks and trucks sit by a rocky ridge to the east, and red base buildings occupy the top right. A minimap is in the top right corner and zoom in, zoom out and lightning-bolt buttons are on the lower left.

驱动智能体对战的提示词可以在这里看到。

README 中还链接了几个类似的回放。我希望将来某个时候能把它做成一个完整的联赛积分榜。

v11:随机地图

这个版本之所以存在,纯粹是因为有一天我瞥了一眼 Claude 用量页面,发现每周额度才用了 75%,而且再过 45 分钟就要重置了。我决定看看能不能用剩下的 token 给 Battle Drones 再加一个功能,并选定了“随机地图”作为目标:

Design and implement a mechanism for generating a random map using any of the available biomes - it should be the size of the largest map and rivers and bridges and rocks and forest and scrap and crystals are all in play. Make them rotationally symmetric and use a seed to allow them to be selected or reused later. You have 45 minutes to build this! Be creative.

这是对话记录,以及 Claude 为展示其工作成果而生成的一张图片:

Grid of ten top-down game maps, two per biome (temperate, desert, arctic, volcanic, tropical), each with a river or lava flow, bridges and roads. Title: "Battle Drones: generated maps (108x108, point-symmetric), 2 per biome, runtime ground painter". Each map is captioned with a name and layout type plus a seed and crossing counts, e.g. "Hawthorn Delta · fork" "random-temperate-1x8a6r2 · 6 bridges, 4 fords"; layout types are fork, badlands, crossing and lake.

v12:通过声音进行多人对战

我刚刚才把这个功能做通,所以还没来得及进行太多实际测试。最新版 Battle Drones 现在支持两台处于彼此麦克风收音范围内的设备进行多人对战!

这个功能源自我上周的 Chirp Pong 实验。我让 Claude Code 参考了那个已经跑通的概念验证:

Clone Simonw/tools from GitHub and look at recent branches for the example pong game that uses web microphone to implement multiplayer between two phones via audio signals

Build a version of that for battledrones

Opus 构建了这个 Radio Probe 工具,用来测量两台设备之间能达到多大的带宽,并根据测得的良好结果,实现了一套完整的音频调制解调器系统。到目前为止,我已经在笔记本电脑、iPhone 和 iPad 之间试过,似乎运行得非常好!

为什么要用声音来做这件事?因为我喜欢静态 HTML,运行起来不花钱,而且我不想在某处启动一台服务器,然后只要还有人想玩这款游戏,就得一直负责维持它的运行。

一些感想

我对游戏开发几乎一无所知。这使它成为一个很好的机会,让我能在一个既有软件工程经验对结果影响较小的领域里,试验编程智能体。

游戏的风险也极低。最糟的情况,无非是我某个傻乎乎的游戏实验出了 bug。

今天早上(通过 Hacker News),我看到了《Steam 新品节充斥着低质内容,Steam 玩家恳求推出“无 AI”筛选功能》。我个人绝不会想把 Battle Drones 提交到这样的活动中——它投入的功夫仍然太少,还不足以被当作一个正经的独立游戏项目来考虑。

……但现在,我能看到这类通过氛围编程做出的游戏获得认真对待的可能。Battle Drones 很好玩,画面不错,也有创新功能(据我所知,通过声音进行多人对战,在 RTS 中还是首次)。

我很想看看,一个比我更有品位、又满怀热情想做出真正出色作品的人,能够做出什么!

这个项目还带来了其他一些观察:

  • 静态 HTML 和 JavaScript 是开发游戏的绝佳载体。WebGL 表现很好,Three.js(以及此前使用的 Phaser)都是非常优秀的开发平台,而且当前的模型对它们了如指掌。
  • 这也让游戏可以作为渐进式 Web 应用运行——虽然我没有提出这个要求,但 Battle Drones 能离线运行。我从未直接安装过它,却能在飞机上玩——我的手机已经把它缓存下来了。
  • 给 Claude 一个 OpenAI API 密钥,让它使用 OpenAI 的模型生成图片,效果非常好。它能查看自己生成的图片,并迭代调整提示词。
  • Opus 5.5 用 Three.js 进行 3D 建模的能力非常出色(用 Blender 也是,想必用其他 3D 应用也一样)。GPT-6 Astra 也是如此。它们完全有能力为 3D 游戏项目制作模型。
  • 对于回放和多人对战这类功能,拥有一个确定性的模拟引擎很有用。Claude 一度不得不用自定义版本替换对 Math.sin()、Math.cos() 等函数的调用,因为不同浏览器(例如 Chrome 和 Safari)返回的数值存在极其细微的差异,导致回放失去同步。
  • Opus 5.5 会写音乐!这个项目中没有音频文件——配乐完全由代码生成,会随地图而变化,甚至会随着战斗升温而变得更加激烈。此前用 Claude 作曲的实验,可以参见 Scrimshaw Jukebox。
  • 我至今仍难以相信,“让它好玩得多得多”这条提示词的效果竟然这么好。
  • 工具实际上几乎是免费的。我通过提示词做出了 Radio Probe、模型浏览器、智能体对战智能体调试工具,而 Claude Code 也为自己做了一大堆工具,我甚至都还没亲自探索过。
  • 静态 HTML 游戏之间通过声音进行多人对战,真的可行!我希望看到更多游戏使用同样的方式——今天四处查找时,除了 Alon Horesh 的 Siner 和 Georgi Gerganov 的 ggwave(他也因 llama.cpp 而闻名),我没找到多少先例。
  • Claude Code 的“Ultracode”消耗 token 简直毫无节制,但它也能凭一条提示词解决复杂问题(比如添加基于声音的多人对战)。
  • 对于用这种方式构建软件,我仍然没能完全摆脱那种内疚感。在一个自己几乎毫无经验的领域里,做出了这么好的东西,我总觉得自己还没资格!到现在,我已经私下向足够多的人展示过它,感觉如果不把它发布出来,让其他人也能看到并从中学习,就不太合适了。

更新:支持在线多人对战

在本文前面,我说过:

游戏的风险也极低。最糟的情况,无非是我某个傻乎乎的游戏实验出了 bug。

然后我试着和 Natalie 玩多人对战版……结果调制解调器尖锐的声音让她头痛得很厉害!

这是个相当糟糕的 bug。我添加了一条警告,随后受到启发,决定做真正的联网多人对战。我试着让 WebRTC 运行起来,但即使是在我自己的 WiFi 网络里,也没法让自己的两台设备建立连接,于是我转而让 Claude 构建了一个简单、无状态的 WebSockets 中继服务器:

If I wanted to support multiplayer between two devices at a very low cost without storing any state on the server could I do that with a tiny asyncio web server running on the cheapest Fly instance?

Build the server and the fly.toml for deploying it, use Fly application name battledrones-relay - put that in a folder in the repo, include deploy instructions in the README in that folder

这是最终做出的服务器。由于它支持缩容至零,并且运行在单个 Fly.io shared-cpu-1x 实例上,我每月的费用应该不会超过 2.19 美元——而且这还是假设它全程保持运行并提供连接服务。

Battle Drones 现在支持在线多人对战。点击“与好友在线对决”,然后通过你喜欢的聊天应用分享生成的房间 URL,或者让对方拍摄屏幕上显示的二维码。

我还添加了一个功能,让你可以在对局结束后复制该对局的 JSON,再将它导入回放功能,重新观看这场比赛。

我原本没想到会这么快加入在线多人对战,但那个引发头痛的 bug 让我觉得,需要尽快提供一种替代方案。

来源:Simon Willison · simonwillison.net