返回日报条目

资料节译

《Battle Drones》:AI 辅助制作的 RTS 加入音频联机

阅读原文

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

我最初的目标是做一款能在手机上玩的 RTS 游戏,风格类似于 [《命令与征服》](https://en.wikipedia.org/wiki/Command_&_Conquer_(1995_video_game))。我对 1995 年的原作(我也喜欢《红色警戒》)有着美好的回忆,想找回一点当年的神奇感觉。

经过 12 次重大迭代(以及编程代理完成的321 次提交,主要由 Claude Code 完成),我现在有了一款基于浏览器的游戏,可在手机和桌面设备上运行,包含多种游戏模式、数张地图(包括随机地图生成器),甚至支持两台处于彼此麦克风收音范围内的设备进行多人游戏。

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

目前包含的功能有:

六张地图,横跨五种生态环境——温带、沙漠、极地、火山、热带

遭遇战模式——红蓝双方在旋转对称的地图上对战

最后一战模式——一名玩家尽可能抵挡一波又一波的敌人

补给箱空投,内含奖励资源

AI 对战 AI模式,可以观看这些性格各异的 AI 互相对战

变异规则,可增加额外规则或改变玩法

代理对战模式,两个 LLM 可以互相对战 Battle Drones

Battle Drones 很大程度上是靠氛围编程做出来的——我几乎没审查过代码,而且它是用我自己几乎没怎么用过的语言(TypeScript)构建的。不过我确实试玩了不少,也从项目启动以来进行了大量迭代。

以下是迄今为止项目的大致历程,包括关键提示词和对话记录链接。

我在 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)为所有载具添加了精灵图,还加入了“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.

游戏还是不怎么好玩,画面也很乏味。那时已经到了 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.

这开始有点像一款真正的游戏了!不过玩起来仍然不太有趣——我发现自己很快就玩腻了。

到目前为止,我的 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 花了这么久,部分原因是它运行了上千场模拟试玩,并根据结果重新调整现有单位的平衡、添加新单位并引入新功能。

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”的运兵飞机。

我开始为自己对游戏实际设计贡献如此之少而感到内疚——过去几个版本,我确实只是说“让它更有趣”和“润色一下画面”。

我注意到 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.

我决定在游戏里加入巨型机器人机甲——想想《环太平洋》里的 Jaeger([《环太平洋》](https://en.wikipedia.org/wiki/Pacific_Rim_(film)#Plot),或者《战锤 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

最终成果真的很酷。

歌利亚可以通过建造厂生产——这是一种只有先建好制造厂、兵营、空军基地和科技实验室后才能建造的建筑。你可以看到歌利亚正在建造,随后它会从建造厂中走出,在地图上行进。

歌利亚可以“锚定”,也就是钻入地面。锚定后,它们可以充当新的总部,在新区域生产步兵单位和其他建筑。

两架 Condor 飞机可以钩住一台歌利亚,然后将它载着飞越地图!

现在,只有摧毁敌方总部建筑并且消灭他们可能建造的所有歌利亚,游戏才会结束。

游戏里还有几种与歌利亚有关的变异规则:

歌利亚舰队让每一方开局时拥有四台空中歌利亚(每台配有一对 Condor),且没有其他单位。

机器人之爱增加了一条特殊规则:如果敌方歌利亚在战场上靠得太近,它们就会坠入爱河,游戏以平局结束。(这点子要感谢 Natalie。)

v10 的另一项功能是代理对战。我在思考多人游戏可以怎样实现时有了个想法:如果不同的 LLM 能在游戏里一决高下,会怎么样?

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 中还链接了几段类似的回放。我希望将来能把它做成完整的联赛积分榜。

这个版本的出现纯属偶然:有一天我瞥了一眼Claude 使用情况页面,发现这周的额度才用了 75%,而且 45 分钟后就要重置。我决定看看能不能用剩余的 tokens 给 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.

我才刚刚把这个功能弄好,所以还没多少时间实际测试。最新版本的 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 玩家恳求添加无 AI 筛选器:Steam Next Fest 已被垃圾内容淹没》。我个人绝不会考虑把 Battle Drones 投稿到这样的活动——它目前仍然太粗制滥造,不足以被视为正经的独立游戏项目。

……不过我现在能看见,像这样的氛围编程游戏有朝一日获得认真对待的可能。Battle Drones 很有趣,画面也不错,还有创新功能(据我所知,通过音频实现多人游戏是 RTS 游戏中的首创)。

我很想看看一个品味比我更好、并且有强烈热情打造真正出色作品的人,能做出什么!

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

标签:游戏设计、项目、人工智能、生成式人工智能、大语言模型、Claude、氛围编程、编程代理、Claude Code