Sign in to follow this  
elvman

Read territories from picture

Recommended Posts

elvman    288
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
elvman    288
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
elvman    288
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this