I am currently work some sort of map generation algorithm for my game. I have a basic understanding on what I want it to do and how it would generate the map.
I want to use the Polar Coordinate system. I want a circular graph so that each player would spawn on the edge of the circle, evenly spread out.
The algorithm should generate "cities" spread out from across the circle (but only inside the circle). Each city should be connected some form of way.
The size of the circle should depends on the number of players.
Everything should be random, meaning if I run
GenerateMap()
two times, it should not give the same results.
Here is a picture showing what I want: img
The red arrows are pointing to the cities and the lines are the connections between the cities.
How would I go about creating an algorithm based on the above?
Update: Sorry the link was broken. Fixed it.
I see the cities like this:
compute sizes and constants from
N
as your cities should have constant average density then the radius can be computed from it directly. as it scales linearly with average or min city distance.
N
(cities) times(x,y)
with uniform distribution(x,y)
is outside circle(x,y)
is too near to already generated cityThe paths are similar just generate all possible paths (non random) and throw away:
In C++ code it could look like this:
Here overview of generated layout:
And Growth of N:
The blue circles are the cities, the gray area is the target circle and Lines are the paths. The
cnt
is just watch dog to avoid infinite loop if constants are wrong. Set the_max
value properly so it is high enough for yourN
or use dynamic allocation instead. There is much more paths than cities so they could have separate_max
value to preserve memory (was too lazy to add it).You can use the
RandSeed
to have procedural generated maps ...You can rescale output to better match circle layout after the generation simply by finding bounding box and rescale to radius
R1
.Some constants are obtained empirically so play with them to achieve best output for your purpose.