Checking Surrounding Squares for Number of Mines

     
 

(R,C)

 
     

Assume  [R] [C] is the cell that needs to be checked for how many mines are around it.  We then need to check from [R-1] [C-1] to [R+1] [C+1], keeping track of the number of mines around this cell.  Then we need to store this value in [R] [C] .

Note: this will only work for inside cells.  Outer cells are a different case.

 

Method for Checking around [R] [C]

- check to see if a mine is stored in R,C (if a mine is stored here, no need to proceed)

 - check cell R,C to make sure it isn't an outer cell of the array (if it is, this is a different case)

- initialize a counter that keeps track of the number mines around R,C

- use a loop to traverse every cell around R,C (from R-1.C-1  to  R+1, C+1)

            - check each cell for a mine (if mine = true, then increase counter)

- loop until all surrounding cells have been checked

- store counter value in cell R,C of the array

 

Code: