Read territories from picture

Started by
2 comments, last by elvman 16 years, 9 months ago
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?
Advertisement
Is there a problem with using the MSPaint floodfill tool to fill the various territories with different colors?
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.
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!

This topic is closed to new replies.

Advertisement