Adding the digits

Now the array is filled with empty tiles and mines, so it's time to complete it with the digits representing the amount of adjacent mines to every empty tile.

The idea: There are two strategies to determine the number of mines around a tile: We can locate all mines and for every mine increase by one the value of all adjacent tiles that do not contain a mine, or we can locate all empty tiles, and for each tile count the number of mines in its adjacent tiles. It's just a matter of speed, and since in traditional Minesweeper games there are less mines than empty tiles, we can reasonably think the first method is the fastest.

Adding the digits

This ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.