Workshop › Sokoban › Step 24 of 29
Just before a move really happens, we push a snapshot onto history. Blocked moves must not leave a photo, so the
snapshot is taken after all the checks: after the push checks when there is a box, in an else when there is not.
```js
if (box) {
const bx = x + dx
const by = y + dy
if (walls.has(key(bx, by)) || boxAt(bx, by)) return // a box cannot push into a wall or another box
history.push(snapshot())
box.x = bx
box.y = by
} else {
history.push(snapshot())
}
```history.push(snapshot()) adds a photo at the end of the list.if (box) branch it comes after the wall-or-box check, so a blocked push leaves no photo.else runs when there is no box: a plain step, also photographed.In move, write history.push(snapshot()) above box.x = bx, and add the else part after the if (box) block.
Skills: Arrays and objects, Game states