Minesweeper ‘Uncover Function’

Now we must implement the minesweeper ‘uncover’ function. It is a function which goes largely unnoticed; however, its functionality is quite impressive.

Ok, let’s assume we click on an empty square, one that does not contain a mine or a number. In the classic minesweeper game when you click on an empty square it uncovers all the other squares which lie adjacent to that square which is also empty. (See picture)

The question is how do we actually code this?

Now I shall introduce another idea which should be familiar to you. We’ve all used Paint, the ubiquitous little program provided by Microsoft. Let’s say you draw an outline of a circle. Now you click the bucket fill icon, and fill that circle with a colour.

Ever wondered how this is done? Well it uses a ‘boundary fill algorithm’.

As it turns out the ‘boundary fill algorithm’ is very similar to the ‘uncover’ function used in minesweeper. So long as the pixels are of the same colour and lie adjacent to one another, it will fill the boundary of that shape with the colour of your choice.

Just to clarify the idea of adjacency I will show you an example below:

Islands

-------

In minesweeper an important idea which crops up is the idea of an ‘island.’ We shall define an ‘island’ to be all squares that lie adjacent to at least one other square. Squares that lie diagonally do not satisfy our definition of an ‘island’.

Code:

Fig 1.
-----------------
--##-------------
--#--------------
--####-----------
-----#-----------
-----------------

This satisfies the 'island' defintion since the '#'s

all lie adjacent to at least one other '#'.

Code:

Fig 2.
----------------
----##----------
------#---------
-------#--------
----------------
----------------
Whereas this does not satisfy the 'island' definition
since all the '#'s do not lie adjacent to at least one
other '#'. In this case there would be three 'islands'.
## = island 1
# = island 2
# = island 3

Therefore, in order to implement the ‘uncover’ function in minesweeper all we need to do is implement the ‘boundary fill algorithm’.

Information about this can be found here:

http://www.siggraph.org/education/ma...s/polygn6a.htm

And it is here where my interest in your project ends. I'll leave this bit up to you.

Good luck.