Turnstone is a free isometric puzzle that runs in the browser. Each level is a floating island of stone paths. You turn turntables to join the paths and lead a small traveller to a shrine. It’s the fifth game in our series of small Three.js puzzles, and the first where the board itself moves. This post covers how the turntables work, how the game decides where the traveller can walk, how the islands are generated and checked, and how the diorama is drawn.
Cells, heights and stairs
An island is a grid of cells. Each cell has a height, and is either flat or a stair. A stair rises one step towards one direction, so it has a low side and a high side. Its other two sides can’t be crossed.
Two neighbouring cells connect if the edges they share are at the same height. A flat cell’s edge is at its height on every side. A stair’s edge is at its height on the low side and one step higher on the high side. That one rule covers flat paths, stairs between levels, and dead ends where heights don’t match.
Turntables are groups of cells
A turntable is a pivot cell plus a few arm cells, one step out in a given direction: a straight piece, an L, or a T. Its rotation is a number from 0 to 3. To get its cells at a given rotation, each arm’s direction is turned that many quarter turns, and stairs on an arm turn with it.
The space a turntable sweeps through, a three by three square around the pivot, is kept clear of everything else, so turning never collides with anything. Paths meet a turntable at the four cells two steps out from the pivot, which we think of as its ports.
Rebuilding the path map
There is no stored path graph. Every time the game needs to know where the traveller can go, it builds a map of all walkable cells for the current state: the fixed cells, any bridges that have been raised, and each turntable’s cells at its current rotation. A breadth-first search over that map, using the edge-height rule, finds the shortest walk to wherever you tapped.
The map is small, so rebuilding it is instant. It also means turning a turntable needs no special path logic: change one number and the next search sees the new layout.
Riding a turntable
When a turntable turns, the game checks whether the traveller is standing on one of its cells. If so, the traveller’s position is rotated around the pivot along with the cells. Standing on the pivot itself, you stay put but face new exits.
On screen, the traveller is reparented to the turntable’s group for the length of the turn animation, so it swings round with the stones, then moved back to the island and snapped to its new cell.
Buttons and bridges
Some cells are bridges, hidden until a button is pressed. Buttons latch: once pressed, the bridge stays up. This keeps the rules simple, because bridges only ever add cells. A walk that was possible stays possible, so the game can plan a whole walk first and raise bridges as the traveller passes over a button.
Generating islands
Each island is laid out on a coarse grid of slots, four cells apart, so neighbouring slots share a single connector cell between their ports. Each slot holds a turntable, a fixed stone crossing, or nothing. Slots get random heights, connectors join neighbouring slots, and a few connectors lead off the edge to the start, the shrine or a dead end. A turntable’s arm becomes a stair when the ports around it need one, so that some rotation can fit.
Most random islands are useless, so every one goes through a solver and most are thrown away.
A solver that counts turns
Walking is free in Turnstone and only turns count. So the solver searches in layers of turns. From every state with a given number of turns, it first spreads out by walking (pressing any buttons on the way), then tries every turn of every turntable in both directions to make the next layer. A state is the rotation of every turntable, which buttons are pressed, and where the traveller stands.
The first layer that contains the shrine gives the fewest turns. That number is the best shown in the game and the target for three stars. For each level, the builder keeps islands whose solution uses the idea that level is meant to teach: riding a turntable, climbing stairs, pressing a button, or turning linked turntables.
A verification script then replays every solution through the same walk and turn functions the game uses, and a headless browser plays all 20 levels through the real game to check that each one ends with the level-cleared card.
The diorama look
The island is drawn with flat-shaded, low-poly materials and lit by a warm, low sun that casts soft shadows.
- Stone cells are columns that run down into the sea, with a pale sandstone cap. Start and goal ledges get grass.
- Stairs are three stacked boxes, rotated to face their high side.
- Turntables sit on a dark disc with a brass rim, or teal for linked ones. The arms are a warmer terracotta, so you can see at a glance what moves.
- Trees stand on small grass islands placed near the paths but never inside a turntable’s sweep.
- The shrine is a white arch with a softly bobbing orb and a point light.
The camera is orthographic, looking down at a classic isometric angle. Its frame fits by projecting the corners of every cell, from sea level to the top of the tallest step, into camera space, so each island is centred however oddly it’s shaped.
Buttons for turning
Tapping the island walks, so turning needs its own control. Each turntable gets a pair of HTML arrow buttons pinned to the screen position of its corner nearest the camera, updated every frame. They scale with the island, so small islands on big screens get big buttons and the final island on a phone stays readable.
You can see the result by playing Turnstone.