Sokoban HTML5: Keep the Target Under the Crate

Push a crate off a target and the target must still exist. Ground and occupants need separate state, or a legal move can erase the puzzle’s destination.

The original six-by-seven level solves in Up, Down, Right: three legal moves, two pushes, and two covered targets. Undo after the win restores the state after Down, including one covered target and the previous counters.

Sokoban HTML5: Keep the Target Under the Crate
Sokoban HTML5: Keep the Target Under the Crate
Open the full example ↗

Use the worked example

Press Up, Down, Right and inspect the position summary. Direction buttons stop after the win, while Undo remains available. Use the separate Blocked preset to test a two-crate chain push and the Target departure preset to see a target remain after its crate leaves.

Trace the result step by step

Use a static layer for walls, ordinary floor, and targets. Keep the player position and crate positions separately. A crate occupies a target; it never replaces that target with ordinary floor.

The puzzle uses the one-crate pushing rule described in Carnegie Mellon's Sokoban assignment. You can push into free floor or a target, but cannot pull a crate back toward you. Before pushing near a wall, consider whether you will still be able to stand behind that crate afterward.

The legend is # wall, space floor, . target, $ crate, and @ player. Count coordinates as (row, column) from zero at the upper-left corner. The player starts at (3,3), crates at (2,3) and (3,4), and targets at (1,3) and (3,5).

This example fixes the six-by-seven level in its source. Walls bound the playable area, and the player, crate, and target coordinates are explicit. It does not accept uploaded maps. When adapting the source, validate a revised map before allowing movement.

For a direction, inspect the adjacent cell. If it is free floor or a free target, the player may walk into it. If it contains a crate, inspect the cell one step beyond. That cell must be free floor or a free target for a push to succeed.

A wall, an out-of-bounds coordinate, or another crate blocks the action. Do not move the player first and then discover that the crate cannot move. On rejection, leave positions, move count, push count, and history unchanged. This game cannot pull a crate or push a chain of two crates.

Each legal walk or push adds one move. Only a push increases the push count. Undo returns the player, both crates, counters, and result to their previous values, so it can recover from an unhelpful legal push as well as revisit the winning position. A rejected action adds nothing to Undo.

The first target stays under its crate while the player returns Down. After Right, both targets are covered and the status becomes won. Ignore direction actions in that state, while keeping Undo and Reset available.

Use the two alternate presets for different questions. In Blocked, the player at (3, 3) faces crates at (3, 4) and (3, 5). Right is rejected because it would push a chain. In Target departure, press Down then Left and inspect the target at (3, 5); it remains after both occupants leave.

Copy a prompt for this example

Create a self-contained HTML crate-pushing puzzle with six rows and seven columns. Enclose the open interior with walls. Use zero-based coordinates: player (3,3), crates (2,3) and (3,4), targets (1,3) and (3,5). Keep wall and target terrain separate from the player and crates.

Provide Up, Down, Left, and Right buttons, plus Undo and Reset. A legal walk enters free floor or a free target. A push moves one adjacent crate only when the square beyond is free. Walls, out-of-bounds positions, and a second crate block the entire action. Rejected actions must not change positions, counters, or undo history.

Count each legal walk or push as one move and each push as one push. Up, Down, Right from the initial position solves the level in three moves and two pushes. Winning requires both targets occupied. Further direction actions are ignored, while Undo remains available. Undo after the win restores the two-move, one-push position with one target covered.

Include a separate Blocked preset with crates at (3,4) and (3,5), and a Target departure preset with player (2,5) and crates (3,5), (2,3). Moving Down then Left in the latter must leave the vacated target visible.

Show a readable board, symbol legend, coordinate summary, and counters. Reset restores the initial puzzle and clears history. Return a responsive single HTML file.

Retain the exact map with its three-move solution when revising the puzzle. You can inspect the prepared HTML in NOS through HTML preview, then compare the solved position with Undo. Include a target-departure round in that review so a drawing change cannot remove the underlying target.

Keep reading