Meander Algorithm

Nathaniel Inman introduces his unique meandering river algorithm and shows how it can be created and used in top-down 2d games with random maps.

Meander Algorithm

The meander algorithm is a combination of using mazes to allow a meandering with bresenhams line. Below you can see the actual algorithm in simplicity. Obviously you could use noise maps to created heighted terrain based on the river to make it look pretty.


  1. Choose a starting map edge and ending map edge, acquire
    the terminal points based on those edges. Usually this would be a random point on those edges. Maybe you'd want to weight it so it's predominately in the center, or you could restrict it to a certain part.

  2. Create Bresenhams line between the terminal points. This is called the pathing vector.

  3. Break up the pathing vector into chunks of 9x9 where the pathing vector crosses the center. There may be left-over of the pathing vector.

  4. For each chunk, perform a recursive maze generation algorithm on the chunk. Repeat this step until there is a path from the start of the pathing vector within the chunk to the end of the pathing vector in the chunk. A* pathing algorithm can be used for the pathing.

  5. Merely use Bresenhams line to wrap up the extraneous pathing vector not covered by chunks, alternatively break up the remaining path into the largest odd number and chunk and process it similarly to the previous part of the algorithm to make it more consistent. Left overs in this optional way would still be filled in with bresenhams line.

Recursive Maze Generation:

  1. Choose a starting point in the field.

  2. Randomly choose a wall at that point and carve a passage through to the adjacent cell, but only if the adjacent cell has not been visited yet. This becomes the new current cell.

  3. All adjacent cells have been visited, back up to the last cell that has uncarved walls and repeat.

  4. The algorithm ends when the process has backed all the way up to the starting point.