Workshop › Klondike Solitaire › Step 38 of 40
Every good card game has undo. The idea is a stack of snapshots: before every change we save a copy of the whole
table in history. The next step will take them back.
```js
let history // earlier positions, for undo
history = []
const save = () => history.push(JSON.stringify(piles))
function flipStock() {
save()
if (!allowed) return false
save()
```JSON.stringify(piles) turns the whole table into one long text: a frozen copy.history.push(piles)? That would save the same object, which the next move changes anyway.save() is called at the start of flipStock, and in tryMove only once the move is allowed.let moves write let history ...; in deal, under moves = 0, write history = [].canFound, leave an empty line and write save.save() first thing in flipStock, and in tryMove under if (!allowed) return false.Skills: Arrays and objects, Game states