Passable terrain paths algorithm?

I’m making a game where the map is like 2048x2048, and each tile is about 16x16.
What I want to do is to have an random algorithm define what tiles are passable, and the rest are as default non-passable.

But I don’t just want to define any random tiles as passable, I want them all to be connected to each other. Example:

http://www.private.is/arni/passable.gif

How do I do this?

maybe you can do that way

first you choose a starting pos x,y and set it to “P” then for each “P” pos you randomly select a neighbord and set it to “P” (if possible) and so on

EDIT: you can also randomly decide to do nothing for a P , this will reduce the numbre of P

Bruno

I was thinking more on the lines of creating a graph with random vertices in it (nicely distributed over the map), and then connect all the vertices with at least 1 edge (so they’re all connected). Then I could simply “walk” the edge between the vertices and mark all the tiles the edge “touches” as passable.

But I don’t know how to implement that, or if it’s even a good solution to my problem.

Nah - that doesn’t have to work necessarily. You could also get loads of seperated subgraphs.

I think DzzD’s way is the best for you. Maybe you could also add a variable that specifies how probably the path changes its direction and so on.

It depends a little on what kind of map you want to have. A labyrinth differs from a cave, and so on. Do you want it more closed or open? More straight lines and 90° turns or more fuzzy?

You could do a general algorithm which uses parameters. A parameter for wide or thin passable terrain, a parameter for more or less frequent turns in direction, a parameter for big or small changes in direction…

Two ways I could imagine:

  1. You set a random starting position and start to “dig”. You just define adjacent fields as passable based on some probability. You can use some restrictions for each field to check for constraints. For example you dont set a field passable if it would make the area too wide or if it would make a connection between two passable areas you dont want to connect.

  2. First create random paths in your terrain, all with a width of 1. You can make more or less turns, longer or shorter paths, slight or great changes in directions. This gives you a path skeleton. Then widen the paths on your demand. If you want areas connected by small paths, select some fields on the paths and widen that area only. If you want wide winding paths, widen all fields for a small ammount.

-JAW

If you used voronoi diagrams, you define “feature points” loop through the pixels, sort the nearest features from the current pixel and have coeffecient multipliers for each distance on… An equation says a thousand words:

currentPixel = constant1 * nearestDistance + constant2* secondNearestDistance + constant3 * thirdNearestDistance…

Ofcourse, for performance reasons, i suggest you only need to use the first and second nearest distances, because you can take advantage of that if the first and second nearest distances are very very similar you end up (with the correct coeffecients) is a shallow (or high, depending on the coeffecients) point where pixels have a closely matching . Say if the first coeffecient was positive and the second coeffecient was negative, you would end up near 0 with equal distances.

So then, loop again through the pixels and only make the ones below a certain threshold passable and the rest, nonpassable. It gives a nice, organic feel to map if thats what you wanted.

DP