Spielerando

The Door Will Not Open, Although the Player Has the Ability

When a door ignores an ability the player clearly has, compare the name the door asks for with the ability's own name, letter by letter. A typo there is easy to miss: if the door also opens with another ability, nothing is stuck, and a check that only asks "can every door be opened?" says the world is fine. Z3 found this hole in our own dead-end check.

What you see

Why does the check miss the typo?

Our ability gates blueprint has a check for the whole world: it plays the world forward, opens every door it can and picks up every ability it can reach, until nothing changes. Whatever is left can never be reached. For a door that needs all of its abilities, a misspelled name means the door never opens, and the check reports it. For a door that takes any one of its abilities, the door still opens with the correct one, nothing is left over, and the check said nothing. Z3 found such a world. The fix was a second list: every name a door asks for that no ability in the world has.

While we wrote this page we found a hole in that fix. It asked whether the name was in the list of abilities with in, and every JavaScript object answers to a few names such as "constructor". A door asking for "constructor" was taken to ask for a real ability. It now looks at the list's own names only, with a test.

How to check your game for it

The first test builds the world from the symptom: a cellar door that should open with dash or smash, with smash misspelled, and both abilities lying in the open. Nothing is stuck there, so only the list of unknown names can catch it. The second asks for a door that wants "constructor". The last two make sure the old dead-end check still finds a door that needs a misspelled ability and an ability locked behind its own door.

The test: fix.test.ts

TypeScript for Node's own test runner. The tests named below as the catch are the ones that fail on the bug.

import assert from "node:assert/strict";
import test from "node:test";
import { checkWorld } from "./fix.ts";

test("a misspelled name on a door that takes any one ability is reported", () => {
  // The door should open with dash or smash. "smahs" is a typo, so smash does nothing here, and a
  // player who found smash first stands in front of a door that will not open.
  const report = checkWorld({
    doors: { "cellar door": { needs: ["dash", "smahs"], mode: "any" } },
    abilities: { dash: { behind: null }, smash: { behind: null } },
    start: [],
  });
  assert.deepEqual(report.unknown, ["smahs"], "the typo was not reported");
});

test("a name that every object has is reported too", () => {
  const report = checkWorld({ doors: { gate: { needs: ["constructor"], mode: "all" } }, abilities: { swim: { behind: null } }, start: [] });
  assert.deepEqual(report.unknown, ["constructor"], "the name was not reported");
});

test("a door that needs all of its abilities, one of them misspelled, can never be opened", () => {
  const report = checkWorld({ doors: { wall: { needs: ["smahs"], mode: "all" } }, abilities: { smash: { behind: null } }, start: [] });
  assert.deepEqual(report.doors, ["wall"]);
});

test("an ability behind the door that needs it is a dead end", () => {
  const report = checkWorld({ doors: { wall: { needs: ["smash"], mode: "all" } }, abilities: { smash: { behind: "wall" } }, start: [] });
  assert.deepEqual([report.abilities, report.doors], [["smash"], ["wall"]]);
});

The catch:

What it said on the code with the bug put back

✖ a misspelled name on a door that takes any one ability is reported
    the typo was not reported
    got undefined, expected [ 'smahs' ]
✖ a name that every object has is reported too
    the name was not reported
    got undefined, expected [ 'constructor' ]
✔ a door that needs all of its abilities, one of them misspelled, can never be opened
✔ an ability behind the door that needs it is a dead end
4 tests: 2 passed, 2 failed

What it said on the fixed code

✔ a misspelled name on a door that takes any one ability is reported
✔ a name that every object has is reported too
✔ a door that needs all of its abilities, one of them misspelled, can never be opened
✔ an ability behind the door that needs it is a dead end
4 tests: 4 passed, 0 failed

Run by pnpm fixes:check on 2026-11-26 with Node v24.15.0. The text above is its output.

The fix

Next to "can everything be reached?", ask a second question: which names do the doors ask for that no ability has? Look the names up among the list's own entries only, with Object.hasOwn. Run the check whenever the game's data changes, before anyone plays it. Better still, let doors point at abilities by a name the editor offers from a list, so a typo cannot be written in the first place.

What changed

Lines with - are the code with the bug, lines with + the fix.

    /** Doors the player can never open. */
    doors: string[];
+   /** Names a door asks for that no ability has. */
+   unknown: string[];
  }

…
      }
    }
+   const asked = [...new Set(Object.values(world.doors).flatMap((d) => d.needs))];
    return {
      abilities: Object.keys(world.abilities).filter((a) => !owned.has(a)),
      doors: Object.keys(world.doors).filter((d) => !opened.has(d)),
+     // Own names only: `name in world.abilities` would take "constructor" for an ability.
+     unknown: asked.filter((name) => !Object.hasOwn(world.abilities, name) && !world.start.includes(name)),
    };
  }

The fixed code: fix.ts

/* A check for the whole world before the game ships: which abilities and doors can a player never
   reach, and which names does a door ask for that no ability in the world has. The second list
   catches a typo even when the door still opens some other way. From the ability gates blueprint:
   https://spielerando.com/en/mechanics/ability-gates */

export interface Door {
  /** The abilities the door asks for. */
  needs: string[];
  /** "all": every one is needed. "any": one of them is enough. */
  mode: "all" | "any";
}

export interface World {
  doors: Record<string, Door>;
  /** Where each ability is picked up: behind a door by its name, or null when it lies in the open. */
  abilities: Record<string, { behind: string | null }>;
  /** What the player owns when the game starts. */
  start: string[];
}

export interface Report {
  /** Abilities the player can never get. */
  abilities: string[];
  /** Doors the player can never open. */
  doors: string[];
  /** Names a door asks for that no ability has. */
  unknown: string[];
}

const opens = (door: Door, owned: Set<string>) =>
  door.needs.length === 0 || (door.mode === "any" ? door.needs.some((a) => owned.has(a)) : door.needs.every((a) => owned.has(a)));

/** Plays the world forward: open every door that can be opened, pick up every ability that can be
    reached, again and again until nothing changes. What is left can never be reached. */
export function checkWorld(world: World): Report {
  const owned = new Set(world.start);
  const opened = new Set<string>();
  let changed = true;
  while (changed) {
    changed = false;
    for (const [name, door] of Object.entries(world.doors)) {
      if (!opened.has(name) && opens(door, owned)) {
        opened.add(name);
        changed = true;
      }
    }
    for (const [name, where] of Object.entries(world.abilities)) {
      if (!owned.has(name) && (where.behind === null || opened.has(where.behind))) {
        owned.add(name);
        changed = true;
      }
    }
  }
  const asked = [...new Set(Object.values(world.doors).flatMap((d) => d.needs))];
  return {
    abilities: Object.keys(world.abilities).filter((a) => !owned.has(a)),
    doors: Object.keys(world.doors).filter((d) => !opened.has(d)),
    // Own names only: `name in world.abilities` would take "constructor" for an ability.
    unknown: asked.filter((name) => !Object.hasOwn(world.abilities, name) && !world.start.includes(name)),
  };
}

Paste this to your AI

In my game a door (or a wall, a gap, a gate) stays shut for a player who has the ability that should open it, while other players get through. I think the name the door asks for is spelled differently from the ability's own name, and the door still opens with another ability, so nothing looks stuck.

1. Before you change anything, list every door in my game's data with the abilities it asks for and whether it needs all of them or any one. Next to it, list every ability with where the player finds it. Draw the order in which a player can get them, as a list or a diagram.
2. Write tests like the ones below for my code: a door that takes any one of two abilities, one of them misspelled, must be reported, and so must a name like "constructor". Run them and paste me the real output.
3. If they fail, add a check like the one below: every name a door asks for that no ability has. Run it on my real game data and show me what it lists.
4. Take the new list out for a moment, show me that a test fails, and put it back.

Do not tell me the world is fine unless the check's output shows it.

The button copies this text together with the fixed code and the test above, so your AI has everything.

Where we found it

The blueprint the bug was in, and the test that guards it there:

How we found them: the bugs our proofs found in our own code

Was this page helpful?

One click, no account. It shows us which pages help.

Next step

Fix by symptom

The Quest Is Done Before the Player Did Anything

A quest that counts as done the moment it starts usually has an empty list of goals: "every goal is met" says yes to an empty list. The test and the fix.

Last updated: 2026-11-26