What it does
A puzzle is a board of cells, a set of pieces, and the exits in its edge or the goal positions its pieces must reach.
A piece is an origin plus cell offsets, so it can be a bar, a block, an L or a shape with a hole; it can be locked to
one axis, pinned in place, or keyed to one exit. The player's move is a slide by a number of cells, legal only when
the whole path is free and inside the board, or an exit through a doorway the piece fits and is keyed for. An illegal
move returns a reason, such as blocked or axis, and changes nothing. legalSlides lists every stopping point of
every piece however far, which is exactly the set of drag targets a touch game needs.
Generation is where the pack earns its keep. The unblock generator enumerates every position of a candidate board and measures the true shortest solution, so "hard" means at least 17 slides by proof, not by how long it scrambled. The parking generator proves the fewest staging slides, moving a car aside before another can drive out. The colour-exit generator cuts a dense packing into pieces, assigns non-overlapping doors and screens the result against proven lower bounds. Generation throws rather than return a level that misses its targets, the same options always give the same level, and a started game can run it in the pack's worker, off the main thread.
Every generated level comes with its solution, and the puzzle keeps it as a certificate that survives the player's off-route moves, exits, undo and redo. A hint is therefore instant. When you want better, a guided search finds a shorter plan quickly and an exact solver finds the shortest one; every search runs to a budget and says so when it runs out rather than claim a result.
Features
- Pieces of any shape — origin plus cells, with optional axis locks, fixed pieces, keys and named exits.
- Exits and goals — doorways on any side of any width, keyed to colours, and positional goals for pieces that stay; a puzzle is solved when every exiting piece is gone and every goal piece is home.
- Clear rejections —
unknown-piece,fixed-piece,axis,outside-board,blocked,wrong-exit,not-at-exitand more, withpreviewto check before playing. - Drag targets —
legalSlidesgives every reachable stopping point and every legal exit. - Three generators — unblock, parking and colour-exit presets at four difficulties, on boards from 4 to 12 cells (colour-exit 6 to 8).
- Exact difficulty — shortest slides, fewest staging slides and proven lower bounds, with the figures returned beside the level.
- Solvers for hints — the stored certificate, a fast guided search, the exact shortest plan and lower-bound proofs, all budgeted.
- Templates and symmetry — scramble any authored exit puzzle from its solved state, apply any of the eight board symmetries, and remove loops from a solution.
- Worker generation —
generateSlidingPuzzleAsyncruns off the main thread and can be cancelled. - Undo, redo and reset — with the certificate kept in step.
Good for
- Unblock-the-car puzzles in the style of Rush Hour or Unblock Me, with cars locked to their lanes and one exit.
- Parking-lot puzzles in the style of Parking Jam, where cars shuffle along their lanes before driving out of their own side.
- Big-block escapes in the style of Klotski or Huarong Dao, authored with one exit for the large piece.
- The 15-puzzle and other slide-into-order puzzles, with positional goals and a seeded scramble.
- Coloured-door exit puzzles, where every piece leaves by the door of its own colour.
- Large level packs with a difficulty curve you can trust, because each level's difficulty is proven.
Make it yours
An authored puzzle is a SlidingConfig: the board size (up to 32 by 32), the pieces, walls, exits and goals. Any
shape, any number of exits, keyed or not, and any mix of exiting and goal pieces.
Generated levels take a preset, a difficulty, a seed and a board size, and each preset has its own targets you can
override. Unblock takes the slides required, the blockers that must move and move twice, the number of bars, and
the exit row. Parking takes the staging slides required and how many cars may be clear at the start. Colour exit
takes the slides required, how many pieces start off their door's lane, how many exits are clear and the slides
before the first exit. For your own designs, generateSlidingExit scrambles any authored exit puzzle from its solved
state, with symmetry to vary where the exits fall.
Three materially different games from one pack:
- A classic unblock pack on a 6 by 6 board, where "very hard" means a proven 25 to 41 slides.
- A parking game on an 8 by 8 lot with a raised search budget, every car leaving by its own side and at most one clear at the start.
- A 15-puzzle on a 4 by 4 board with positional goals, scrambled by 200 seeded legal moves.
A quick look
Generate an unblock level, play a slide, and ask for a hint:
import { createSlidingBlocks, generateSlidingPuzzle } from '@phaser-ae/sliding-blocks';
const deal = generateSlidingPuzzle({ preset: 'unblock', difficulty: 'hard', seed: 23 });
const jam = createSlidingBlocks(deal.config, deal.solution); // the certificate makes solve() instant
const r = jam.apply({ type: 'move', id: 'C', dx: 0, dy: -2 }); // slide C two rows up
if (r.valid) animate(r.events[0]!); else wobble(r.reason);
const stops = jam.legalSlides(); // drag targets
const hint = jam.solveBest(20000).actions[0];
if (jam.solved) win();
Works with
traffic-release— for tap-to-release puzzles where a piece leaves whole along a route and nothing repositions.slide— for tiles that slide all the way and merge.pusher— for pushing crates one cell at a time.grid-kick— for blocks that slide on ice until they hit something.world-3dandrender-3d— to present the board as a 3D scene.
Good to know
- Moves are straight lines along the grid and pieces never rotate.
- Searches are synchronous and bounded: keep hint budgets small inside a frame and generate in the worker.
- Larger unblock and parking boards take longer: 7 by 7 easy and medium generate in under a second, 7 by 7 hard can take ten seconds or more, and 8 by 8 needs a raised search budget. Colour exit generates on 6, 7 and 8 only; bigger boards start from a template.
- Difficulty figures are mathematical, shortest slides and proven bounds, not calibrated human difficulty.
- The parking preset proves the fewest staging slides, not the fewest actions overall, and is best treated as a variant of the mobile game, which may not allow repositioning.






