Jump to content
  • Advertisement

Archived

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

MrPoopypants

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!