Workshop › Klondike Solitaire › Step 23 of 40
The quickest way to play is to tap a card and let the game find where it goes. autoMove tries the foundations first
(almost always the best move), then the columns, and stops at the first move that works.
```js
// A tap sends a card to the best place it can go: a foundation first, then a tableau column.
function autoMove(from, index) {
const targets = ['f0', 'f1', 'f2', 'f3', 't0', 't1', 't2', 't3', 't4', 't5', 't6']
return targets.some((to) => tryMove(from, index, to))
}
```targets lists the piles to try, in order.some calls the function for each item and stops at the first true; it returns whether any was true. Because
tryMove really moves the card, the card goes to the first place that fits and no further.Above the hit comment line, write autoMove with its comment, leaving an empty line after it.
Skills: Arrays and objects, Functions
← Turn over the uncovered card Pick up a card →