• Advertisement
Sign in to follow this  

Read territories from picture

This topic is 3884 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

Once I played a Risk game which used BMP files to mark the borders of territories. I liked this method and now I want to use it in my game, but I don't really know how to do it. Here is the image: What I need is: read the image file and assign each territory an ID, then store this ID in a bit-map (if a pixel in the image is black, then store 0 in the bitmap). Then I could get the ID of the territory where, for example, my mouse is pointing (from its x and y coords). Here is a small example of a bit-map: 0,0,0,0,0 0,1,0,2,0 0,1,0,2,0 0,0,0,2,0 0,0,0,0,0 This bit-map stores 2 territories with IDs 1 and 2 (0 is for empty region). I tried to use a recursive search (like Basic 4 way recursive fill method described here), but I don't really know how to search for all territories. Any ideas on how to do that?

Share this post


Link to post
Share on other sites
Advertisement
Is there a problem with using the MSPaint floodfill tool to fill the various territories with different colors?

Share this post


Link to post
Share on other sites
Number of territories will be higher than 10,000 so this is impossible with colors. And it would be easier to draw the borders of each territory then filling them with colors.

Share this post


Link to post
Share on other sites
Ok, I used the simpliest method I could think of - I simply used the fill algorithm mentioned above. I simply go through all pixels, if a bit in the bit-map has not been assigned an ID=1 then use the fill algorithm to search for its territory. Increase the ID by 1 and again search for unassigned bit in bitmap. And everything works OK. Thanks for reply!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement