NetHack 侏儒矿坑的地牢生成
Dungeon Generation in the Gnomish Mines of NetHack

原始链接: https://www.boristhebrave.com/2026/10/18/dungeon-generation-in-the-gnomish-mines-of-nethack/

NetHack 的 Gnomish Mines 使用细胞自动机生成有机洞穴。从约 40% 的随机地板格开始,四次迭代细化地图;不连通的洞穴后由走廊连接。第一次迭代是无缓冲的聚类过程,将附近的地板与岩石分组。第三次和第四次迭代侵蚀孤立的角落和小岛。第二次迭代唯一地将恰好有五个地板邻居的格转为岩石,但其目的不明。最终结果与游戏通常的方形房间形成对比。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 工作 | 提交 登录 NetHack 中侏儒矿井的地牢生成 ( boristhebrave.com ) 6 分,由 ibobev 发布于 1 小时前 | 隐藏 | 过去 | 收藏 | 讨论 帮助 考虑申请 YC 2027 年冬季批次!申请开放至 11 月 2 日。 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Ok, this one is really best explained with a visualiser:

NetHack’s level generation has a lot of interesting things, but I wanted to focus on the Gnomish Mines because of their use of Cellular Automata. This gives it an organic caves feel, while the majority of the game is spent in square rooms.

It’s very straightforward:

  • Randomly pick 40% of the cells to be floor
  • Apply four passes of Cellular Automata
  • Fix up disconnected caves with extra corridors

Let’s dive into the cellular automata specifically. There’s only two states – floor or rock. And each pass works by counting how many floor tiles are in the 8-neighbor hood of each cell.

Pass 1: 0-2 → rock; 3-4 → unchanged, 5-8 → floor
Pass 2: 0-4 → unchanged; 5 → rock; 6-8 → unchanged
Pass 3: 0-2 → rock; 3-8 → unchanged.
Pass 4: same as pass 3

Interestingly, pass 1 is unbuffered. Each cell is updated in place before moving to the next cell. All the rest are buffered – all cells have new computed values, then the entire grid updated at once.

Pass 1 creates floors near other floors, and creates rocks near other rocks. I’d call this a “clustering” pass, that pushes the random tiles towards wide open areas of tiles. The unbuffering is important here so that you don’t flop-flop, turning something rock→floor near something turning floor→rock.

Passes 3 and 4 are erosion routines, it’s a very common use of cellular automata. If you have 6-8 rocks nearby, then you also become a rock. That tends to smooth out corners, and delete tiny islands.

Pass 2 though… It turns cells to rock if they have exactly 5 floor neighbors (i.e. 3 rock neighbors). I’m still struggling to understand what purpose this is intended to achieve. Any ideas?

联系我们 contact @ memedata.com