Workshop › Candy Crush-style Match 3 › Step 23 of 29
With hasMove, the game never gets stuck: a new game builds boards until one has a move, and after a move, if no swap
is left anywhere, a fresh board replaces the old one.
```js
function reset() {
do newBoard()
while (!hasMove())
else {
phase = 'idle'
// No swap left anywhere: a fresh board.
while (!hasMove()) newBoard()
}
```do ... while (!hasMove()) builds a board at least once and again while it has no move (null counts as false and
! turns it around).while (!hasMove()) newBoard() replaces a stuck board.reset, turn newBoard() into the do ... while shown.update, turn else phase = 'idle' into the else { ... } block.Skills: Game states
← Is there any move? A hint after five seconds →