# Data structures for territories in a 2D map

I am diving into game development with a 2D game. The game will display a territorial map (borders, capitals, etc.).

What is a common data structure to use for storing and manipulating the data in such a game? I'm considering using a graph (as in Graph Theory, not graphing).

Also, what are common file formats for storing the "polygon data" for each territory? Are there any standard or semi-standard formats?

# Data structure

## Vector of vectors (a.k.a. array of arrays)

Using this data structure allows you to consider vertices and edges (specially useful when dealing with one-way streets or roads) and it also let's you consider more efficient maps, leaving out obstacles.

In this case you would use at least two vector of vectors; one for storing the vertices and the edges and the other one for storing node membership to regions (countries, for example).

An extra vector of vectors could be use to store cities that belong to a country, for example. It depends on the specific problem you're targeting.

# Data representation for tactical analysis

## Influence maps

This technique is great when dealing with grids in order to develop tactical analysis and tag each location as part of a region and such.

## Map flooding

Now that you're thinking about graph theory, and developing your graph using Dirichlect domains, this technique comes in handy for tactical analysis and is very similar to having influence maps on a grid.

# Saving data

Nowadays developers are more inclined into these standard formats and there are several file handlers for your platform of choice.

• JSON
• XML
• YAML

It's good that you research them in depth and decide which one is more suitable to your project.

• My map isn't grid-based. In fact, there might be some confusion here since I am using the word "map" in the more colloquial sense, as in a map of Europe, rather than the computer game sense. My question is about the higher-level data structure to store a map of territories with arbitrary borders. Commented Aug 12, 2014 at 23:21
• I modified the answer regarding your comment Commented Aug 13, 2014 at 0:06