Sokoban-Lettres

Behind the scenes

How levels are generated

By — updated on

Sokoban-Lettres grids are not drawn one by one. A generator produces them from a word and a seed, then puts them through a series of checks and has a solver solve them before they are published. This page describes the process as it is actually implemented.

A word and a seed

Every level comes from two inputs: the word to spell and a seed, a number that feeds the pseudo-random generator. The same pair always produces exactly the same grid, which makes it possible to rebuild a level identically and guarantees that every player gets the same grid for a given Daily Challenge.

Starting from the solution

The generator starts by placing the targets: one continuous horizontal line, free of walls, as long as the word. If it cannot find room for such a line, the attempt is abandoned. The boxes are first placed on their targets, then moved away by a series of pushes played backwards. This method guarantees that at least one solution exists: you only have to replay the scramble in reverse.

A scramble that moved no box at all is rejected, as is one that leaves a box in a corner. The letters are then shuffled between the boxes, so the starting position does not give away the order of the word.

Chapters that get more demanding

The generator’s settings change from the first to the tenth chapter of the Adventure. Between those two ends, each parameter progresses steadily:

Quality gates

A generated grid is not necessarily an interesting one. Each candidate therefore passes a series of gates, in this order: a minimum number of pushes in the solution, a sufficient average distance between boxes and targets, enough spacing between boxes, enough spread across the grid, then limits on boxes already near their target and on aligned boxes. A grid that fails any gate is discarded.

Several candidates, one kept

For each level the generator produces several candidate grids — from 4 in the first chapter up to 16 in the tenth — and allows itself up to 16 attempts for each. Among those that pass every check, the best-scoring one is kept.

Solver verification

The chosen candidate is finally handed to the IDA* solver, which looks for a push-efficient solution. A grid found to be unsolvable is rejected. The search budget grows with the chapters, from 100,000 to 500,000 positions examined. If that budget is reached without a conclusion, the grid is kept — it is solvable by construction — and its par is estimated rather than calculated. Par is explained in scoring and par.

Why this approach

Generating rather than drawing makes it possible to offer a new grid every day, in three languages and with different words, while guaranteeing that each one is solvable. The quality gates guard against the trivial grids a generator naturally produces. The origins of Sokoban tell how the genre moved from hand-drawn levels to computed ones.