Map generator 1

This is a simple map generating routine I developed in C#2.0. With a few tweaks it can produced “island” or “labyrinth ” type maps. I came across this algorithm whilst experimenting with different ways to generate maps for RogueLike games. You can download the C# source code and executable here.

How it works

Map generation is controlled by the following variables:

  1. map int[,] – a two dimensional array that holds the data.
  2. p (int) – close cell probability. Between 0 and 100.
  3. h (bool) – cell operation specifier.
  4. i (int) – counter.
  5. n (int) – number of cell’s neighbours.
  6. c (int) – examined cell’s closed neighbours. Between 0 and 8.

The procedure is as follows:

  1. Randomly choose a cell from map
  2. If the cell is open use a p to determine whether we close it.
  3. Get c
    1. h = true: If c > n close the cell, else open it.
    2. h = false: If c > n open the cell, else close it.
  4. Repeat steps1 – 3 i number of times.

Varying the above mentioned variables will produce maps of surprisingly different appearances.

Examples

The values x=100,y=100,p=45, h=true, n=4, i = 50000 produce an “island type” map.

default.png

The values x=100,y=100,p=45, h=false, n=4, i = 50000 produce a “labyrinth type” map.

variant1.png

x=100,y=100,p=55, h=true, n=4, i = 50000.
variant2.PNG

x=100,y=100,p=45, h=true, n=4, i = 85000.
variant3.PNG

x=100,y=100,p=45, h=false, n=2, i = 50000.
variant4.PNG

x=100,y=100,p=65, h=true, n=5, i = 50000.
variant5.PNG

x=100,y=100,p=75, h=true, n=5, i = 80000.
variant6.PNG

Leave a Reply

You must be logged in to post a comment.