Skip to content

77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.

fix(procedural-gen): Unity/Godot RNG guidance, cross-version seed stability, noise ranges, tested wave function collapse

Kiro Crewc11e51a97f27
diff --git a/skills/disciplines/procedural-gen/SKILL.md b/skills/disciplines/procedural-gen/SKILL.md
index 4f635f9..10b58ce 100644
--- a/skills/disciplines/procedural-gen/SKILL.md
+++ b/skills/disciplines/procedural-gen/SKILL.md
@@ -3,9 +3,10 @@ name: procedural-gen
description: >
Generate game content procedurally — seeded deterministic RNG, value/Perlin/
Simplex noise for terrain and heightmaps, grid dungeon generation (rooms +
- corridors, BSP, random walk), and weighted loot/drop tables. Engine-neutral
- algorithms. Use when the user mentions procedural generation, perlin/simplex
- noise, random seed, dungeon generator, heightmap/terrain, or loot tables.
+ corridors, BSP, random walk, wave function collapse), and weighted loot/drop
+ tables. Engine-neutral algorithms. Use when the user mentions procedural
+ generation, perlin/simplex noise, random seed, dungeon generator, WFC,
+ heightmap/terrain, or loot tables.
---
# Procedural generation
@@ -57,8 +58,11 @@ room_count = rng.randint(5, 12) # same seed -> same sequence, every run
# WRONG: calling random.randint(...) (global state) — order-dependent, unseedable.
```
-Engine equivalents: Godot `var rng = RandomNumberGenerator.new(); rng.seed = s`;
-Unity `var rng = new System.Random(seed)` (or `UnityEngine.Random.InitState`).
+Engine equivalents: Godot 4.7 `var rng := RandomNumberGenerator.new(); rng.seed = s`
+(save `rng.state` to resume a sequence mid-way); Unity 6.3
+`new Unity.Mathematics.Random(seed)` (a `uint`, must be non-zero) or
+`new System.Random(seed)`. Avoid `UnityEngine.Random.InitState` for generation:
+it seeds the one global generator that every other script also draws from.
Store the seed in the save file so a world can be regenerated.
### 2. Fractal (fBm) noise for heightmaps
@@ -96,13 +100,16 @@ def weighted_pick(rng, table): # table: list of (item, weight)
upto += w
if roll < upto: # first bucket the roll falls into
return item
- return table[-1][0] # float-safety fallback
+ return next(i for i, w in reversed(table) if w > 0) # roll == total (float edge)
loot = weighted_pick(rng, [("common", 70), ("rare", 25), ("legendary", 5)])
```
-Weights need not sum to 100 — they are relative. To prevent bad streaks, use a
-"pity"/bag system (see `references/dungeon-generation.md` notes on distributions).
+Weights need not sum to 100 — they are relative, and a weight of 0 never drops.
+Built-ins do the same job: Python `rng.choices(items, weights)`, Godot
+`rng.rand_weighted(PackedFloat32Array(weights))` (returns an index). To prevent
+bad streaks, use a "pity"/bag system (see `references/dungeon-generation.md`
+notes on distributions).
### 4. Rooms-and-corridors dungeon (sketch)
@@ -135,14 +142,28 @@ random-walk caves) is in `references/dungeon-generation.md`.
on a small grid. Cap attempts and accept fewer rooms.
- **Seeding once globally, then relying on frame timing**: any non-deterministic
input (time, physics, hash randomization) leaking into generation destroys
- reproducibility.
+ reproducibility. A common hidden one: `rng.choice(list(some_set))` over
+ strings in Python, whose set order changes per process. Sort first.
+- **Seeds that stop matching after an update.** Library RNGs promise the same
+ sequence only on the same version: Python guarantees only `random()` across
+ versions (not `randint`/`choice`), .NET says `System.Random` may change
+ between major versions, and Godot calls its PCG32 an implementation detail.
+ If shared seeds, daily challenges or seed-only saves must survive updates,
+ ship your own small PRNG (PCG32, xorshift, SplitMix64) with a test that pins
+ its first outputs — or save the generated result instead of the seed.
+- **Flat noise at integer coordinates**: Perlin noise is 0 at every integer
+ lattice point, so sampling raw `noise(x, y)` (e.g. `Mathf.PerlinNoise`) at
+ whole tile coordinates returns the same value everywhere. Scale by a
+ non-integer frequency (`x / width * f`); libraries with a frequency setting,
+ such as FastNoiseLite, apply it for you.
## References
- `references/noise.md` — octaves/lacunarity/gain, redistribution, island
shaping, two-axis biome lookup, blue-noise object scatter.
- `references/dungeon-generation.md` — BSP, rooms+corridors, random-walk caves,
- cellular-automata smoothing, connectivity validation, distribution/pity tables.
+ cellular-automata smoothing, wave function collapse, connectivity validation,
+ distribution/pity tables.
## Related skills
diff --git a/skills/disciplines/procedural-gen/references/dungeon-generation.md b/skills/disciplines/procedural-gen/references/dungeon-generation.md
index dd9cd59..41627a8 100644
--- a/skills/disciplines/procedural-gen/references/dungeon-generation.md
+++ b/skills/disciplines/procedural-gen/references/dungeon-generation.md
@@ -1,7 +1,8 @@
# Dungeon and level generation
-Three families cover most 2D level generation. All write into a plain grid
-(`0 = wall`, `1 = floor`) that a tile pass renders later. All take a seeded RNG.
+Four families cover most 2D level generation. All write into a plain grid
+(`0 = wall`, `1 = floor`, or tile ids for WFC) that a tile pass renders later.
+All take a seeded RNG.
## A. Rooms and corridors
@@ -82,6 +83,63 @@ def smooth(grid, W, H, steps=4):
return grid
```
+## D. Wave function collapse (tile adjacency rules)
+
+WFC fills a grid so every pair of neighbours obeys adjacency rules you give it
+(simple-tiled model). Each cell starts with every tile possible; repeat:
+**observe** the undecided cell with the fewest options, **collapse** it to one
+tile by weight, then **propagate** — shrink neighbours to tiles still compatible,
+spreading until nothing changes. An empty cell is a contradiction: restart (or
+backtrack).
+
+```python
+DIRS = [(1, 0), (-1, 0), (0, 1), (0, -1)] # +x, -x, +y, -y
+
+def wfc(W, H, weights, allowed, rng, max_restarts=20):
+ """weights: {tile: weight}; allowed[(tile, d)]: tiles that may sit in DIRS[d] of tile."""
+ for _ in range(max_restarts):
+ cells = [[set(weights) for _ in range(W)] for _ in range(H)]
+ failed = False
+ while not failed:
+ # Observe: an undecided cell with the fewest options; break ties with the rng.
+ open_cells = [(len(cells[y][x]), x, y) for y in range(H) for x in range(W)
+ if len(cells[y][x]) > 1]
+ if not open_cells:
+ return [[next(iter(c)) for c in row] for row in cells]
+ fewest = min(n for n, _, _ in open_cells)
+ _, x, y = rng.choice([c for c in open_cells if c[0] == fewest])
+ opts = sorted(cells[y][x]) # sorted: set order is not stable
+ cells[y][x] = {rng.choices(opts, [weights[t] for t in opts])[0]}
+ # Propagate: shrink neighbours to tiles some remaining option still allows.
+ stack = [(x, y)]
+ while stack and not failed:
+ cx, cy = stack.pop()
+ for d, (dx, dy) in enumerate(DIRS):
+ nx, ny = cx + dx, cy + dy
+ if not (0 <= nx < W and 0 <= ny < H):
+ continue
+ support = set().union(*(allowed[(t, d)] for t in cells[cy][cx]))
+ narrowed = cells[ny][nx] & support
+ if narrowed != cells[ny][nx]:
+ if not narrowed:
+ failed = True # contradiction: restart
+ break
+ cells[ny][nx] = narrowed
+ stack.append((nx, ny))
+ raise RuntimeError("no solution within max_restarts")
+```
+
+- Rules must be symmetric: if B may sit east of A, A must be allowed west of B.
+ One-sided rules are only enforced when propagation happens to run from that
+ side, so the finished grid can break them.
+- Option count is the simplest "entropy"; the weighted Shannon entropy of the
+ remaining options is the usual refinement. Either way the grid grows outward
+ from the first collapse, so tile **weights** decide the overall mix.
+- Pre-collapse fixed cells (border = wall, an entrance tile) and propagate from
+ them before the loop to steer layouts.
+- WFC guarantees local rules only. Run the connectivity check below on the
+ result like any other generator.
+
## Connectivity validation (do this every time)
Generation can isolate regions. Flood-fill from the spawn; if floor tiles remain
@@ -89,7 +147,7 @@ unreached, either discard the map, dig a tunnel to the nearest reached tile, or
keep only the largest region.
```python
-def reachable_floor(grid, start):
+def reachable_floor(grid, start): # assumes a solid wall border (no bounds checks)
seen, stack = set(), [start]
while stack:
x, y = stack.pop()
diff --git a/skills/disciplines/procedural-gen/references/noise.md b/skills/disciplines/procedural-gen/references/noise.md
index 4f87481..875362d 100644
--- a/skills/disciplines/procedural-gen/references/noise.md
+++ b/skills/disciplines/procedural-gen/references/noise.md
@@ -6,9 +6,12 @@ sampling it across a grid gives a coherent heightfield. **Use a library** —
implementing correct gradient noise is fiddly and rarely worth it.
Libraries by ecosystem: `FastNoiseLite` (C/C++/C#/Rust/JS/GLSL/HLSL and many
-more), `opensimplex` (Python), `simplex-noise` (JS/TS), `Unity.Mathematics.noise`
-or `Mathf.PerlinNoise` (Unity). Note the output range differs: some return
-`0..1`, others `-1..+1`. Rescale to a known range before combining.
+more; built into Godot 4 as the `FastNoiseLite` resource, whose
+`get_noise_2d()` returns about `-1..1`), `opensimplex` (Python), `simplex-noise`
+(JS/TS), `Unity.Mathematics.noise` (`snoise`/`cnoise`, `-1..1`) or
+`Mathf.PerlinNoise` (Unity, about `0..1` and may slightly overshoot). Rescale to a
+known range before combining. `Mathf.PerlinNoise` takes no seed: derive a large
+per-seed offset added to the coordinates instead.
## Frequency and wavelength
@@ -95,8 +98,8 @@ forest vs sparse desert).
For a map whose east edge tiles with its west edge, sample noise on a cylinder:
map `x` to an angle and feed `cos/sin` into 3D noise. Tiling both axes uses 4D
-noise on a torus. Higher-dimensional noise has a narrower output range, so
-rescale afterward.
+noise on a torus. The value distribution changes with the dimension, so measure
+the min/max you actually get over the map and rescale afterward.
## Determinism checklist