1
\$\begingroup\$

To make this clear from the get go;

I'm not looking for HOW To randomly generate a terrain (I know I can use Perlins noise for that).

I'm looking for an algorithm that can help with the terrain generation.

Example;

Me and my friend are working on a flash game to be use as advertisement for an upcoming game (And to see if theres actually interest for the base game).

And I've been working on randomly making terrains, however! When i generate the map, i have no idea how to make it so it connects properly.

The map is isometric and tilebased and after its been generated we're going to litter chest/traps and other gameplay elements on the map. However, theres no reason to put an item on a piece of that map thats not connected to the rest of the map.. Or worse yet, spawn a player on a tile thats unconnected to anything.

Does anyone know of a algorithm that helps with stuff like this?

Thanks in advance people.

~Etarnalazure

EDIT

What I'm looking for is an algorithm that makes sure theres no unconnected tiles, thus no items or players may by accident get seperated from the rest of the walk-able tiles.

Hopefully this clears up what i mean.

\$\endgroup\$
5
  • \$\begingroup\$ what do you mean by 'connects properly'? Are there inaccessible terrain parts in your maps? \$\endgroup\$ Feb 6 '13 at 10:37
  • 4
    \$\begingroup\$ google "flood fill", it sounds like that might be useful for you \$\endgroup\$ Feb 6 '13 at 10:38
  • \$\begingroup\$ Yeah, the problem is that currently I just randomly create holes in the map to simulate stuff like Lakes or just holes. But what if i end up creating holes a tile that a player starts on? Thats why i need a proper algorithm to make smart terrain. \$\endgroup\$ Feb 6 '13 at 11:37
  • 1
    \$\begingroup\$ possible duplicate of Is there an algorithm to detect the "mainland" on a 2D map? \$\endgroup\$
    – House
    Feb 6 '13 at 15:24
  • \$\begingroup\$ Checking it out ASAP. \$\endgroup\$ Feb 8 '13 at 8:19
3
\$\begingroup\$

It sounds like you already have most of a terrain generator up and running. If your only concern is not leaving any walkable terrain isolated from other walkable terrain one thing you could do is run a blob finder over the entire map.

With one pass over the map grid you should be able to put together a collection of "blobs" which are separate walkable areas on your map. From there it should be fairly trivial to take each blob and make sure it connects with the rest by making a bridge/connection to one or more adjacent blobs and not stopping until there is only a single blob remaining (you can merge existing blobs without going over the entire map again).

If you need to spawn the player now, all you have to do is make sure that where you spawn them is walkable and you will be able to say for certain that they can get to any walkable square on the map.

\$\endgroup\$
1
  • \$\begingroup\$ Amazing mate! I will check it out. This answer is a lot more akin to what I was looking for :P \$\endgroup\$ Feb 9 '13 at 17:11
2
\$\begingroup\$

Sounds like you're actually looking for a maze-generation algorithm instead of purely random terrain. Since most such algorithms work by "blazing a trail" from a starting point, there will be no islands.

\$\endgroup\$
-1
\$\begingroup\$

If the core issue is really detecting if a bunch of stuff is connected, the way to address that would be with a pathfinding algorithm like A*.

I did a quick Google search and came up with this A* AS3 API.

\$\endgroup\$
3
  • \$\begingroup\$ Yeah, thats what we thought as well, we've made a rather in depth a* ourselves. We were just worried about memory usage if we had to run it to check for each tile. Had hoped there was a algorithm for smart terrain generation. Thanks regardless. \$\endgroup\$ Feb 6 '13 at 14:43
  • 4
    \$\begingroup\$ A* is for finding a path between two points. It's a bit overkill to check for a path between the player and every place where you want to place a chest. You'd more likely want something like a simple breadth first search, which doesn't need a end point to function properly. \$\endgroup\$
    – House
    Feb 6 '13 at 15:26
  • \$\begingroup\$ @Byte56 A* is fast-enough for most of the weird cases like this; given that you can get pre-canned implementations, that's usually "good enough." I've used it to detect connectivity of atoms for molecules in my Silverlight chemistry game, and it worked. Overkill? Maybe. Problem solved quickly? Aww yeah. \$\endgroup\$
    – ashes999
    Feb 6 '13 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.