Screw Bolt Sort Jam is a free screw puzzle that runs in the browser: tap coloured screws out of overlapping glass plates and sort them into matching toolboxes, with a few spare holes for screws that don’t fit yet. It’s the seventh game in our series of small Three.js games. This post covers the rules model, how the game decides whether a screw is stuck, the toolbox queue, how levels are generated and rated, and how it’s drawn.

Plates, layers and screws

A level is a board with a stack of rectangular plates. Each plate has a centre, a size and a layer number, where higher layers sit on top. Each screw has a position, a colour and the plate it holds down. There’s also a queue of toolboxes, one colour each, a number of spare holes, and how many boxes are open at once.

As with our other games, all the rules live in one module with no Three.js in it, shared by the game, the generator, the solver and the verification script.

Is a screw stuck?

A screw can come out only if no plate on a higher layer covers it. The check is a simple overlap test: does any standing plate on a higher layer reach past the screw’s position, allowing a little extra for the size of the screw head? A plate is standing as long as at least one of its screws is still in.

When you tap a stuck screw, the game uses the same function to find the plates in the way, wiggles the screw and briefly flashes those plates, so you can see what has to go first.

The toolbox queue

Taking a screw out sends it to an open box of its colour if one has room, or else to a spare hole. If neither is possible, the screw stays put. After every move, the game settles the boxes in a loop:

  1. If a box is full, it closes and leaves, and the next box in the queue opens.
  2. If a screw in a spare hole matches an open box with room, it jumps in.
  3. Repeat until nothing changes.

The loop matters, because one move can set off a chain: a screw fills a box, the next box opens, two spare screws drop into it, and that box fills too. Each step is recorded as an event, and the game plays the events back one by one as animations, so the screen always shows exactly what the rules did.

The level is lost when no screw can move, which in practice means every spare hole is full and nothing free fits an open box.

Generating and rating levels

The generator drops plates of random sizes onto the board, keeping each new plate overlapping the ones below so the board forms a real stack. Screws go at the ends of bars and the corners of larger plates, spaced so they never touch. The count is trimmed to a multiple of three, colours are dealt in threes, and the box queue is shuffled.

A solver then searches for a winning screw order, trying screws that go straight into a box first, because those never hurt. To set the stars, it reruns the search with fewer and fewer spare holes allowed. The smallest number that still works is the level’s best: the fewest spare holes you ever need in use at once.

Difficulty comes from random test players. Each one mostly takes screws that fit a box and otherwise picks a random free screw. Running a few hundred games per board gives a win rate, and the level builder keeps boards whose win rate falls into a band that drops steadily from level 1 to level 20. A verification script replays each stored solution, checks it never uses more than the best number of spare holes, and confirms no order manages with fewer.

Drawing it

The game is viewed almost head-on, with a slight tilt so you can see the thickness of each plate.

  • The board is a rounded wooden panel.
  • Plates are extruded rounded rectangles in soft tinted glass, partly see-through and stacked a little apart in depth, with darker edges. Each shows dark holes where its screws go, so you can still read a plate once its screws are gone.
  • Screws are coloured heads with a cross slot and a metal shaft. Because the glass is see-through, screws on lower layers show through, slightly faded.
  • Toolboxes are chunky coloured boxes with three holes, and the next boxes in the queue appear as small blocks beside them.

A screw coming out spins and rises, then arcs up to its box or spare hole. Falling plates drop off the board, tilting as they fade, and full boxes lift away while the next one slides in.

Testing it end to end

A small test hook lets a headless browser tap screws in the running game. The test plays every level’s stored solution, checks the level-cleared card appears, and confirms the spare count matches the best. A second test taps screws by their screen position with a real mouse and a simulated touchscreen. All 20 levels passed.

You can see the result by playing Screw Bolt Sort Jam.