Hi All,

I'm working on a basic console program at the moment that uses a 2D array. I need to be able to go through the entire array CellGrid(which is 6* 6) and check all of it's surrounding values (all 8 of them) e.g

O X X
\ | /
O - O - X
/ | \
X O O

I need to then store the amount of surrounding X's in my surrounding integer then move onto the next cell until I have gone through the entire 2D array.

The problem occurs when I try to check all of the surrounding values in an array which is in the corner or on the edge.
i.e. CellGrid[0][0] is in the corner and thus I cannot check any of the values on the left because they aren't there!
Also in a value such as CellGrid[1][6] I cannot check any of the variables beyond the column 6 for the same obvious reason.

I need to somehow create an algorithm that knows how to check the surrounding cells/arrays rather than try to check all 8 positions because on the arrays in the corner or on the edges, it can't!

Any advice at all would be grealt appreciated.

Best Regards,

Smithy.