latent_sokoban.levels¶
latent_sokoban.levels
¶
Procedural level generator.
Levels are generated by rejection sampling: place walls, goals, boxes and the player at random, then keep the level only if the BFS solver finds a solution whose length falls inside the requested band. This guarantees every generated level is solvable and gives direct control over difficulty via the solution-length band.
The generator is fully determined by the numpy Generator passed in, which is what makes the hidden-test-set protocol work: freeze this file, agree on the constraints, and generate the final levels from a secret seed.
generate_hidden_set
¶
Generate the full 100-level hidden set from a secret seed.
Deterministic in seed. Takes roughly 70s, nearly all of it in the
4-crate tier, where rejection sampling for a long-solution band is slow.
Source code in latent_sokoban/levels.py
generate_level
¶
generate_level(rng, size=6, n_boxes=1, wall_density=0.12, min_solution_len=2, max_solution_len=30, max_tries=5000)
Generate one solvable level. Returns (level, optimal_solution).
Raises RuntimeError if no valid level is found within max_tries (only happens with contradictory constraints).
Source code in latent_sokoban/levels.py
generate_deadlock_level
¶
generate_deadlock_level(rng, size=6, n_boxes=1, wall_density=0.18, min_solution_len=4, max_solution_len=30, max_tries=20000)
Generate a Split-D level: solvable, but at least one available first push leads to an irreversible deadlock. Punishes greedy pushing.