#### Archived

This topic is now archived and is closed to further replies.

# 2d Arrays

This topic is 5763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

(C++) X 0123456789 Y .......... 0. 1100100000 1. 1111111010 2. 1001001001 3. 1010101110 4. 1101101110 5. 1001111110 6. 0100000000 7. 0101000110 8. 1100000010 9. 0101100011 For the engine running my simple (to most of your standards''(im trying to make a more complicated Minesweeper clone)) program, the program must anylize each cell of the array and determine how many cells with a ''1'' border it (this will be replaced later further along) Thus far in development i have been able to determine what i said above, however i cannot find out how to make corner or edge cells search on the opposite side of the array for neighbors For example: The cell at (1,0) should have 5 neighboring 1s. (0,0) (0,1) (1,1) (2,1) (1,9) If anyone could help me out that would be really great Thanks a lot!

##### Share on other sites
All non-edge cells will have nine neighboring cells, and all you have to do is a little X,Y adjusting to find the values of each of the neighboring tiles. Given non-edge tile (x,y), you need to check (x-1,y-1), (x-1,y), (x-1,y+1), (x,y-1), (x, y+1), (x+1,y-1), (x+1,y), (x+1,y+1).

Given an edge tile, it's almost the same logic, however if x-1, y-1, x+1, or y+1 go outside the boundary, you have to wrap them around. So if we have an edge tile like (1,0), then when we do (0-1) we have to wrap around to 9. Likewise, if you have (9,0), whenever you do (9+1) you have to wrap around to 0.

[edited by - Zipster on February 10, 2003 1:47:54 AM]

##### Share on other sites
You can always do the wrapping like this:

  prevCellIndex = (thisCellIndex + 9) % 10;nextCellIndex = (thisCellIndex + 1) % 10;

(That is, with 10 cells). That way, you don't need any special handling for border/non-border cells.

[edited by - Kippesoep on February 10, 2003 2:01:01 AM]

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633421
• Total Posts
3011798
• ### Who's Online (See full list)

There are no registered users currently online

×