Part 10 of 13 in Ghostveil
Turnstiles that steer the fire
Three Ghostveil rooms with no stones in them, where turning a turnstile changes where the fire runs. The generator has to prove the fire must move during the walk, and that each room has a wrong turn worth avoiding.
Ghostveil is a puzzle game about Fantasma, alone in a machine buried under a castle, where every room is a lock and the only thing she does is walk. Walking pushes stones, swings turnstiles and sinks plates. I'm building it in Flutter and Flame, and the rooms come out of my own generator and are checked by a solver.
The blue fire runs from a brazier along rune channels, and through spike floors and turnstiles where they touch. A door with the fire beside it stands open. A spike floor with the fire in it sinks, so she can walk over it, and stands up again when the fire leaves. A turnstile is stone too, its pivot and every arm, so it carries the fire like a channel does, and turning one changes where the fire can reach. In the rules it is one loop in the function that works out what is lit:
for (var t = 0; t < level.turnstiles.length; t++) {
conductive
..add(level.turnstiles[t].pivot)
..addAll(turnstileArmCells(t, s.rotations[t]));
}
On 15th October 2026 I wanted rooms made from that and nothing else: a brazier, channels, spike floors, a door, one or two turnstiles, and no stones to push.
Proving the fire has to move
The easy way to get these wrong is a room where the turnstile is a switch. She turns it once, the fire lights a path to the door, and she walks out. The turning then has nothing to do with the walking. So the first check asks the opposite question: could she get out if the fire never changed at all?
To ask it, the solver plays the room under rules where the fire is frozen. The turnstiles still turn and still stand in her way, but the doors and spike floors answer only to one fixed set of lit cells:
class FrozenFireRules extends Rules {
final Set<Pos> lit;
FrozenFireRules(super.level, this.lit);
@override
Set<Pos> powered(PuzzleState s) => lit;
}
A room needs the fire to change if no frozen setting gets her out. Written out,
where is the number of turnstiles, is one way of setting them (each turnstile at one of its four quarter turns), is the set of cells the fire lights with the turnstiles set that way, is no fire at all, and is every one of those lit sets. The code builds by trying every rotation of every turnstile and runs the solver once per distinct lit set:
String? oneFireSetting(Level level, {int maxStates = 400000}) {
final rules = Rules(level);
final start = level.initialState();
final settings = <String, Set<Pos>>{'': const {}};
void each(int t, List<int> rotations) {
if (t == level.turnstiles.length) {
final lit = rules.powered(start.copyWith(rotations: List.of(rotations)));
settings[(lit.toList()..sort((a, b) => a.y != b.y ? a.y - b.y : a.x - b.x)).join()] = lit;
return;
}
for (var r = 0; r < 4; r++) {
rotations[t] = r;
each(t + 1, rotations);
}
}
each(0, List.filled(level.turnstiles.length, 0));
for (final lit in settings.values) {
final solved = Solver(level, maxStates: maxStates, rules: FrozenFireRules(level, lit)).solve();
if (solved != null) {
return 'solves with the fire held still (${lit.length} cells lit) in ${solved.steps}';
}
}
return null;
}
It tries rotations she may never be able to reach, so the test is stricter than it needs to be: a room that passes it would also pass a test of only the settings she can get to.
The first room through it was a small study I called Bridge and Bar: one turnstile with two arms in an L, a brazier in the top right, a door in the top left, one spike floor on the left and another across the only way in from the bottom. Its four rotations light four different sets of cells, so with no fire at all that makes five frozen searches, and none of them gets her out. Here it is played through.
She comes in over the bottom spike floor, which the fire holds down through the turnstile's right arm, and pushes that arm up. The turnstile is lit, so it wears a padlock, and the push breaks the lock before the arms swing a quarter turn. Now the arms reach the channel on the left: the fire runs along it, through the spike floor there and up beside the door, the door opens, and the spikes she has just crossed stand up again behind her. Held as it starts, the fire never opens the door. Held as it ends, the spikes keep her out of the room, and the other two rotations and no fire at all fail as well.
Needed, and still nothing to decide
The generator made three of these studies and all three passed. None of them had a wrong move in it. The fire had to change, but pushing whatever would turn solved each one, so there was never a reason to stop and think. On the two counts below, all three studies score zero.
The second check counts decisions. It splits the solver's solution at every turn of a turnstile into stretches. Inside a stretch she can walk anywhere without turning anything. A stretch holds a choice when, somewhere she can walk to in it, there is a turn that is not the solution's next one, that changes what the fire sinks and opens, that leaves the room still solvable, and that costs enough to put right:
Here is how many steps she walks from the start of the stretch to the wrong turn, the is the wrong turn itself, is the length of the shortest solution from just after it, is how many moves the solution still had from the start of the stretch, is how many turns that shortest solution makes, and is how many turns the solution still had. The first line says the mistake costs at least two extra moves. The second says it costs at least one extra turn, so walking round the long way is never enough to put it right. In fireChoices that is:
// A turn: the solution's own, or one that leaves the fire as it is,
// is no choice about the fire
if (r.state.rotations.join() == right) continue;
if (fireSetting(rules, r.state) == setting) continue;
final after = Solver(level, maxStates: maxStates).solve(r.state);
if (after == null) continue;
final regret = dw + 1 + after.steps - left;
if (regret < minRegret) continue;
final turns = 1 + turnsIn(r.state, after.moves);
if (turns <= turnsLeft) continue;
A turn that leaves her with no way out at all is counted separately, as a trap. I keep that count as a diagnostic and don't ask for any: the room should ask her to avoid a mistake she can recover from.
Choices are counted along the one solution the solver finds. The other new checks hold against every solution, by running the solver again under rules that forbid something and requiring it to fail: every spike floor closed to her, every spike floor solid to the arms, one turnstile held still, the fire kept to two settings, or no going back to a setting she has left.
Searching for them
The campaign generator only tests a room against all this after it has built the whole room, and for these rooms that took hours. So I wrote a separate search that climbs towards them. It starts from a random small room and changes one thing at a time: one or two cells, her start, a turnstile, the brazier or the door. A change stays if the room scores at least as well, and the score is how far down the list of checks the room gets, cheapest first. Every room also has to keep the turnstiles' swing to at most 35 per cent of the floor she can reach, since a room that is nearly all turnstile looks like a heap of stone. When a room passes everything, the search turns each channel, spike floor and wall it can do without back into plain floor.
Three rooms came out of it and went into the campaign at the end of the fire chapter, after Bridge of Stone, as files of their own. The generator never makes them again from a seed, but it still holds each file to every check a generated room passes. That makes the campaign 37 rooms.
Which Way Round has one turnstile and a par of 11. The fire has 3 settings, there are 2 choices, and no traps. Two Arms, One Fire has two turnstiles and a par of 29, with 6 settings, 2 choices and 1 trap, and every solution has to swing an arm through a spike floor the fire is holding down. The Long Way Back, at 39, has 8 settings and 4 choices; 2 of those cost four moves or more, and every solution passes through at least three settings of the fire and goes back to one it left. The turnstiles' swing covers 19, 34 and 27 per cent of the floor in the three rooms.
The solver proves these as facts about the rules. Whether a player standing in Which Way Round sees its wrong turn as a choice is something only playing shows. The count also can't tell one mistake from the same mistake made twice: The Long Way Back's 4 choices are 3 different mistakes, one of them on offer in two stretches.
The dungeon art, the fire and Fantasma are from SnowHex's Dungeon Gathering. The turnstiles are built from Ghostveil's own grey bricks, and the rooms and the rules are Ghostveil's.