1

I'm writing a Risk-like board game in java. A feature is that players can design their own maps which they store in a text file. The text file lists all territories (== countries) in the world map followed by their direct neighbors. The game then scans the file and creates a collection of the territories with their corresponding adjacency lists.

The next step would be to translate this graph into a graphical representation. That means I want to represent each territory by a rectangle or some other simple shape. I don't want to go into complex, edgy borders between territories yet. So basically the territories will look like some African or North American nations with horizontal and vertical borders.

Now my problem is: While it would be easy to visualize a graph where the borders are represented by drawn edges between them, I find it difficult to place the territories (== vertices) directly adjacent to each other. In other words the territories should "touch" each other, like in the real world.

In particular, it is difficult because of such places where 4 or more territories border with each other (Consider Four Corners in USA with Arizona, Colorado, New Mexico, and Utah).

Now I was wondering if anybody ever tried to do something similar or if there are even existing algorithms dealing with this problem. I would appreciate any help and creative input. Thanks!

hooch
  • 1,135
  • 1
  • 16
  • 31
  • 1
    What will you do when the maps the players give you are non-planar (http://en.wikipedia.org/wiki/Planar_graph)? For an extreme case, suppose they give you 10 regions, each one bordering each other? Or, how about 10 regions A1 through A5 and B1 through B5 where each A region borders each B region but no A region borders another A region and no B region borders another B region? – mhum Feb 22 '11 at 06:16
  • Thanks, you made a good point. See below for my answer :) – hooch Feb 22 '11 at 06:41

2 Answers2

1

If you can use a graph layout tool like graphviz to get a planar projection of your graph, then you can look into computing the voronoi diagram of the points on your graph, which you could then distort to make things more visually interesting. (You may also need to watch out to make sure that you don't end up changing the adjacency properties when you compute the voronoi diagram, since it depends on the relative spacing of the points. You will probably also have to detect places where an "ocean" cell will have to be inserted in order to make two territories non-adjacent.)

user57368
  • 5,675
  • 28
  • 39
  • Voronoi diagrams seem like the way to go! Thanks, I didnt know about them before. But as you already said, these diagrams don't consider pre-set adjacencies. They only do that implicitly by making points which are close to each other adjacent. – hooch Feb 22 '11 at 05:51
  • Right. How accurate the Voronoi diagram is will depend a lot on the graph layout algorithm. If your graphs are planar or mostly planar, then something like a force-directed layout will probably produce something pretty good with minimal fix-ups needed, though I'm interested to see how it works in the real world. Also, a Voronoi diagram will hardly ever result in a four-corners type intersection, and may produce a lot of situations where two regions share a very short border segment that you may want to enlarge at the cost of making some territories non-convex. – user57368 Feb 22 '11 at 06:04
  • Yes. Im already thinking about checking the 4-corner problem beforehand. While the original board game does not have them, I cant rely on users not generating a graph which does. The other solution would be to identify such occasions and then simulate them simply by using sea passages. Then I can guarantee the graph to be planar (I think). – hooch Feb 22 '11 at 06:12
  • Note that in graph theory, two regions whose borders touch only at a single point and not along an edge are usually not considered adjacent. If your users input their graphs with this convention, then you'll end up putting an ocean right where the shared corner would be. Collapsing the ocean down to a single point would yield a 4-corner type intersection. – user57368 Feb 22 '11 at 06:19
  • Ok given your and mhum's input, I just made 2 key decisions: 1) I will adhere to graph theory and thus will not allow the 4-corner intersection to be passable from the 2 opposite territories. 2) Sea passages must be drawn with straight lines, which in a graph reduces them to normal land borders. Therefore I will perform a check on the input file for 4 or more corner adjacencies and will not accept a file that has them. – hooch Feb 22 '11 at 06:40
  • You need to check for more than just 4 or more adjacencies. You also need to detect any instances of the K_3,3 graph (see: http://en.wikipedia.org/wiki/Water,_gas,_and_electricity). If you have any subgraph like this, you will not be able to make planar regions satisfying the given adjacency. – mhum Feb 22 '11 at 08:03
1

GMap is exactly what I want. They're combining a variety of techniques, including Voronoi diagrams (here's a paper on the algorithm). Now I just have to figure out how to get it...

mjk
  • 2,443
  • 4
  • 33
  • 33
hooch
  • 1,135
  • 1
  • 16
  • 31
  • Woh! That is some very cool imagery they output. I am intrigued, and curious to see if you manage to get your hands on the source code. – peteorpeter Feb 24 '11 at 16:04
  • yea.. at first i would have been happy with simple rectangles. but now that i saw this thing i want more! – hooch Feb 24 '11 at 18:35
  • FYI, I created this similar question to pose the question of how to create these graph/maps more directly: http://stackoverflow.com/questions/5109956/how-can-i-produce-visualizations-combining-network-graphs-imaginary-maps – peteorpeter Feb 24 '11 at 20:21