Arrays of references

This is a discussion on Arrays of references within the C++ Programming forums, part of the General Programming Boards category; Minesweeper ‘Uncover Function’ Now we must implement the minesweeper ‘uncover’ function. It is a function which goes largely unnoticed; however, ...

  1. #16
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    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.
    Attached Images Attached Images  

  2. #17
    Registered User
    Join Date
    Jul 2005
    Location
    Jilin Province, China
    Posts
    7
    ok i'm new to c++ but interested about this topic...

    i used namespace to keep a grid that i used in several functions ....
    Code:
    namespace grid {
    
    char board[9][9];
    
    }
    something like this then just used
    Code:
    grid::board[][]
    is this a good way or not?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 03:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21