Workshop › Candy Crush-style Match 3 › Step 13 of 29
After a matching swap the matched gems disappear, 10 points each. An empty cell is marked -1, which is no color;
findMatches and draw skip empty cells.
```js
let board // board[row][col]: a color index, or -1 while empty
const gem = board[r][c]
if (gem < 0) continue
const matched = findMatches()
score += matched.size * 10
for (const cell of matched) board[Math.floor(cell / N)][cell % N] = -1
```trySwap, after a swap that matches: 10 points per matched gem, then every matched cell becomes -1.Math.floor(cell / N) and a column with cell % N.if (gem < 0) continue skips empty cells in both findMatches and the drawing loop.let board.findMatches, under const gem = board[r][c], write if (gem < 0) continue.trySwap, above the last return true, write the three lines.draw, under const gem = board[r][c], write if (gem < 0) continue too.Skills: Arrays and objects, Game states
← A score and a fresh start Let the gems fall →