A forest that audits itself before you walk it
· 5 min read · game-dev, testing, javascript, procedural-generation, level-design
Part One of Ravenhush is a road of about 900 m with three forks, and the game never draws the route for you. The only guide is signs: claw marks, rags, a carved raven. A level like that is fair only if every fork has a sign that says which way is true, and every decoy has one that warns you off. I did not want to find out by playing it again and again, so I wrote the rule down and made the build check it.
The level is data #
The road is a graph, not a mesh. Edges are stretches of path, and each edge is either the main route or a decoy. Nodes are forks, the start, the goal and dead ends. Everything about it lives in plain modules with no Three.js: the trail, the clues and pickups placed along it, and an audit that reads all three.
The forest is the same kind of thing. Ground tiles and plants are generated around the player, deterministically, with an independent random number generator per grid cell. What grows where is decided by one pure spec, and anything that asks "where are the trees" uses that spec: the renderer, the clue placer and the audit. That is what makes the check honest. When the audit says a sign hangs on a real trunk, it is the trunk the game will draw.
Signs are typed #
A sign has a polarity and a level:
export const CLUE_TYPES = {
scratches: { polarity: "toward", anchor: "tree", level: 2, note: "three claw marks; they lean the way to go" },
rag: { polarity: "toward", anchor: "tree", level: 3, note: "a strip of cloth tied round a trunk" },
symbol: { polarity: "toward", anchor: "tree", level: 3, note: "a raven carved in the bark, seen best in raking light" },
arrow: { polarity: "toward", anchor: "ground", level: 2, note: "sticks laid on the ground as an arrow" },
prints: { polarity: "toward", anchor: "ground", level: 3, note: "boot prints in the mud" },
candle: { polarity: "toward", anchor: "ground", level: 2, note: "a candle stub, its flame still alive" },
cairn: { polarity: "marker", anchor: "ground", level: 1, note: "a small stack of stones" },
xsticks: { polarity: "omen", anchor: "ground", level: 1, note: "two sticks crossed: not this way" },
charm: { polarity: "omen", anchor: "tree", level: 2, note: "twigs and feathers hung on a string: a warning" },
};
(This is a trimmed copy of the real table.) toward means the way is this way, omen means do not, and marker means you are on the road or this is the end of a branch. The level is how hard a sign is to notice, from 1, obvious, to 3, subtle. A tree sign is fixed to a real trunk, and if there is no trunk near, it goes on a weathered stake driven in beside the path.
What the audit checks #
The audit is one function, and it returns errors, which mean the level is broken, and warnings, which mean it is probably too hard or too easy. These are the rules, with their numbers:
The graph
- Every fork has exactly one true way and at least one decoy.
- Every decoy ends in a dead end, and a dead end has no way out.
- The true route reaches the goal and is continuous. A route outside 450 to 900 m is a warning.
The geometry
- Paths that are strangers keep 16 m apart. Paths that meet at a fork are compared only past 30 m from it, and keep 12 m apart.
- At a fork the true way and each decoy leave at least 30 degrees apart.
- Walking the road in steps of 2 m, no sample may be too steep (a surface normal under 0.8 or a jump over 0.9 m), and no tree may stand in the corridor.
The signs
- A sign must be within 4.2 m of a path, or nobody would see it.
- An omen on the true route is an error. So is a sign that points the way, on a decoy.
- A sign on a tree must touch its trunk to within 6 cm and hang between 0.9 and 2.2 m high.
- Two signs may not be closer than 4.5 m.
- At every fork, something must confirm the true way within 38 m, and it must point within 50 degrees of the way it marks.
- Every decoy needs an omen within 26 m of its entrance.
The distance between signs
if (maxGap > 95) err(`${maxGap.toFixed(0)} m of the true route with no sign at all`);
else if (maxGap > 70) warn(`${maxGap.toFixed(0)} m between signs on the true route`);
The gap is measured by distance walked along the true route. More than 95 m without any sign fails the build. More than 70 m is a warning.
Today it reads: route 895 m, 3 forks, 33 signs (12 obvious, 10 medium and 11 subtle), 12 pickups, longest stretch without a sign 66 m, no warnings. The route is 5 m under the limit I set, and I only know that because the audit says so.
The audit is a test, not a tool #
It runs in Node, with no GPU, as one of about 125 self-tests that npm run selftest runs. Editing the trail, the forest rules or the clue placer must keep it green. If I move a tree-covered hill and a sign loses its trunk, the build says which sign.
The world is also deterministic, a seeded generator and never Math.random(), so the same seed always gives the same forest. The Long Night mode relies on it: the same number is always the same forest, with the trees, signs and pages elsewhere.
What it cannot prove #
The audit proves a sign exists where it should. It cannot prove that someone will see it. So there are three more layers that are not part of the interface.
- Every sign and paper throws a small glint back when the flashlight beam touches it, from about 22 m. Warm means this way, cold means a marker, dim red a warning and cream a paper. It is never visible outside the beam, and never from close up.
- A bell far off in the village tolls from the north, and the pale light in the haze is north too.
- If you are lost, the help rises, and lost is measured in metres walked, never in seconds. 130 m without passing a sign, or 35 m off the true road, or 60 m back toward the start. The bell gets louder, the light swells and ravens settle in the trees along the true road, and passing a sign takes the help down again.
Only a person can tell whether that is enough. The audit makes sure the part that can be counted is right.
Ravenhush is free in the browser at ravenhush.vercel.app, and the project page is here.
Related projects
- Ravenhush — Free sci-fi horror game for the browser