开发者利用 DOOM 游戏机制构建神经网络并实现数字识别
一位开发者利用《DOOM》游戏中的巫毒娃娃、传送带和岩浆等物理机制,成功构建了一个可运行的神经网络。该系统通过模拟矩阵乘法和注意力机制,在 Colab 中实现了手写数字的精确识别,并与 NumPy 参考结果完全一致。这一项目展示了在游戏引擎中实现复杂计算逻辑的可能性,兼具教育意义与技术趣味性。
报道正文
本文目录2 个章节
Neural networks that run on DOOM's game mechanics: voodoo dolls, conveyor belts, lava and doors. Watch the films · Try it in Colab : draw a digit and DOOM reads it, nothing to install
A number is a crowd of voodoo dolls on a conveyor belt. An activation function is a staircase they have to climb. A matrix multiply is dolls running across lava lines, each line raising a room's light level. Attention is dolls squeezing under ceilings that another number has lowered. When the dolls stop, the light levels are read back out of the running game and compared bit for bit with an independent integer reference. One value off by one and the run fails.

The marine's brain is compiled into the level he is fighting in. The dots on the right are 1,345 voodoo dolls of him. They run his transformer and choose his next move; the level senses the demons and pulls the trigger. Watch the film .
Walk a digit, DOOM reads it

The input is a 28×28 floor in the level. Every tile the marine walks on while holding FIRE inks itself, and the level writes that pixel into the brain. He presses READ. 1,355 voodoo dolls run an MNIST network, compare all 45 pairs of digit scores and count the wins. Only the winner's doll gets through, and it lights that digit on the wall. Python advances the clock, then reads back the 784 pixels, the hidden layer, every comparison and the answer, and checks all 248 values against NumPy.
doomformer draw # opens a window: arrow keys to walk, hold Ctrl to draw, Space on the READ switch
doomformer draw --digit 7 # headless: the marine walks a 7 (Python presses his keys in place of a player) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄████████████████
████▀▀ ▀████▀
▀▀▀ ▄███▀
████
███
███
███
████
███▀
████
▀███
DOOM reads: 7 (right) -- the winner's doll lit it on the 7-segment display
EXACT: all 248 values DOOM computed (hidden layer, 45 score comparisons and 10 win counts, each with its twin, and the one-hot answer) equal the NumPy integer reference computed from the 784 pixel ports DOOM holds (tolerance 0); one display firing
pixels: the 784 ports equal the level's canvas (the tiles the pen inked)
READ pass: 5,705 game tics = 163 s of real-time DOOM at 35 tics/s, 79 s wall | Python sent 58 commands, 29 readout scripts each followed by the ack script it waits for (0 waited more than one advance), and nothing else (0 rejected)Every digit 0 to 9 in three walked variants: 30 read correctly, all 30 exact. In a window DOOM runs in real time, so a READ takes 2¾ minutes; headless it takes 76 to 99 s. How it works · film
Choose your skill level
pip install git+https://github.com/mottopanikeiku/doomformer # Python 3.11+, Linux or macOSThe first run builds DOOM's script compiler, so you need git, cmake and a C compiler. Or skip all of it:
the Colab notebook
installs it, lets you draw a digit for DOOM to read, and runs the softmax demo.
| Skill | Command | What DOOM does | Time |
|---|---|---|---|
| I'm too young to die | doomformer hello | runs a tiny neural network | 3 s |
| Hey, not too rough | doomformer mnist | reads handwritten digits | ~2 min |
| Hurt me plenty | doomformer demo | invents a DOOM level name | 20 s |
| Ultra-Violence | doomformer ask "what does iddqd do" | answers your question | 7-11 min |
| Nightmare! | doomformer demo --nightmare | 106 maps, 56,390 voodoo dolls | 2-4 min |
Times are from a 16-core Linux machine running 8 DOOM games at once.
<details> <summary><b>I'm too young to die</b>: what you'll see</summary>tiny integer MLP 4-6-5-3 compiled into one DOOM map: 60 voodoo dolls, 1222 sectors
input 1/5 x=[-71, -82, 64, 37] -> y=[11, 4, -15] EXACT (3 outputs + 22 hidden readouts equal the integer reference; 488 game tics)
...
5/5 EXACT
784 pixels → 64 → 45 comparisons → 10 win counts → the answer, all in one DOOM map: 1,355 voodoo dolls and 158,550 sectors. Each ink pixel releases a doll that runs across the hidden layer's weight lines. Dolls then compare every pair of digit scores, and only the digit that wins all nine of its comparisons gets a doll through. DOOM picks the digit and Python checks it. In DOOM the network read 99 of the first 100 MNIST test digits correctly and 966 of 1,000 sampled from all 10,000, every one of them exact. On all 10,000 the same integer network gets 97.16 %.
$ doomformer mnist --digits 2 --seed 1
███
████ ▄▄▄█████████▄▄
████ ▀█████▀▀▀▀▀████
████ ▄▄███▀
███▄ ▄▄▄███████▄▄
████ ████▀▀▀▀▀▀█████
████ ▀███
████ ▄▄ ▄██▀
▀████ █████▄▄██████▀
▀██ ▀▀▀▀▀▀▀▀▀▀
DOOM reads: 1 right DOOM reads: 3 right
test #46 test #51
2/2 read correctly | 2/2 EXACT: every value DOOM computed (248 per digit: hidden layer, comparisons, win counts and
the one-hot answer) equals the NumPy integer reference (tolerance 0); Python only compared | 5,696 ga
> (注:更多技术实现细节与完整 API 文档请查阅原项目 README)