i trying make clickable map game (like risk) in have many svg paths similar one:
example svg map
so when player1 clicks territory of player2 in order attack it, clicked territory should have border player1's territory else attack invalid.
i thought storing paths , it's neighboring paths in multidimensional array this:
path[0] -> path[0][0] path[0][1] path[0][2] path[1] -> path[1][0] path[1][1] but since map huge, inefficient me this. suggestions on how solve problem?
create country table
containing adjacency information, each country has 7 neighbors unless have small states vatican, luxemburg,... uniform map subdivision can use static number of neighbors. this:
int map[countries_max][neighbors_max];
uniform map division
there more ways obtain adjacency info. uniformly divided map can compute average point of border path near center of country. take each country point , find closest countries (points) it. if distance smaller treshold store country index in neighbor list. treshold can around size of country (for rectangle division need 2 treshold 1 per axis).
generic map division
you need check if part of country border path near/parallel part of other country border path. if yes store country index in neighbor list. doable if have border paths.
generic map division (no border paths)
in case map raster or vector not in form of closed polygons/paths per country (for example can have division paths instead) above approaches unusable. when attack know start , end position of attack cast line start end (dda or bresenham) , count how many border lines crossed (count color edges). if count 1 move valid. have false negatives if cast attack crossing same border multiple times.
Comments
Post a Comment