|
-
Apr 21st, 2002, 12:59 AM
#1
Thread Starter
Lively Member
simple c++ problem plz help!
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.
-
Apr 22nd, 2002, 05:01 PM
#2
New Member
create an array 2 rows and cols larger then necessary (row 0 -row before the actual array and row 7 - row after, same with cols) and initialize them with values different from the possible array values. Check them later when iterating through cells (sorry, won't help with that)
Good luck
Andrei
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|