# Map algorithm?

This topic is 3988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, Could anyone give me advice on rpg game map algorithms? How do i create one, if all i got is X and Y cordinates? I want to add trees, resource fields (iron, wood and etc.). Im using PHP, because this is text based rpg, but i need to make map. All i create is something like that: +++++++ +-+++++ ++-++++ +++-+++ I cant random it well without using random function.. Any help? If i posted to wrong forum, please move but dont delete :) Thanks.

##### Share on other sites
1) Yes, you did post in the wrong forum. You should have posted in General Programming or perhaps even Game Design, as this is not really a math question. Don't worry about it.

2) First you need to figure out what you want to do before you can start thinking about an algorithm to accomplish the task. What do you want to create? Simply saying that you want to "create a map for your game" doesn't really tell us anything. What exactly will be on your map, and what about it is confusing to you??

##### Share on other sites
I actually did a bit of research into this for you, mainly because when sitting down to answer your question I realized that I honestly had very little idea about how to go about creating an organic looking 2d continent.

I did know that you should probally use a tile based system, and I knew that you would need an algorithm that was able to generate a solid land mass, followed by an auto tile fringing step where you would place the border tiles to make it look good.

At first I started researching into the area of cellular automotons but quickly abandoned this method as it was just too geometric. I also investigated perlin noise and plasma fracals but these methods also left something to be desired.

No instead I started looking into diffusion limited aggregation.. After following up a few links I eventually came across this: Alexander Map Generation

I would borrow their idea of using the land sparks (or you can use their modified algorithm that also generates mountains) and use that as the foundation for generating values in a 2d array (Which you will later render to the screen as a tile map).

If you follow their technique you will have cells (It is like a grid) where you have land mass and cells where you have ocean. Now the thing is if you were to render the cells to the screen it would look VERY blocky. To combat this problem you will need to have transition tiles (called fringing) and place these ocean to land transition tiles at the places where your ocean and and land meet.

I will not outline everything you will need to do as this is your project and not mine, however hopefully this will get you started or provide you with some ideas.

Good luck!

##### Share on other sites
No no no, all I need is much easer!
Lets say, all map is 100% land. Let it be 300x300.
Each cordinate is like 30x30 pixels image.

I need to find out which cordinate should have forests.

If I mark forest as a F, and land as L, and show 10x5 part of a map, it should look something like that:

LFLLLLLLLLL
LLLLLLFLLLL
FLLFLLLLLFL
LLLLLLLFLLL
LLLLFLLLLLL

As you can see, forests are in random places of the map, but every time you load map it must stay in same position, so I cant use random. I could, but I dont want to use DB to store that.

##### Share on other sites
Store and reuse the seed.

##### Share on other sites
Quote:
 Original post by ToohrVykStore and reuse the seed.

##### Share on other sites
$seed = (int)$_POST['seed'];srand($seed);for ($x = 0; $x < WIDTH; ++$x)  for ($y = 0;$y < HEIGHT; ++$y)$map[$x][$y] = rand(0,2);display(\$map);

Generates the same map when you pass the same 'seed' argument.

##### Share on other sites
Thank you very much, it works perfectly.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633726
• Total Posts
3013573
×