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:
- map int[,] – a two dimensional array that holds the data.
- p (int) – close cell probability. Between 0 and 100.
- h (bool) – cell operation specifier.
- i (int) – counter.
- n (int) – number of cell’s neighbours.
- c (int) – examined cell’s closed neighbours. Between 0 and 8.
The procedure is as follows:
- Randomly choose a cell from map
- If the cell is open use a p to determine whether we close it.
- Get c
- h = true: If c > n close the cell, else open it.
- h = false: If c > n open the cell, else close it.
- 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.
The values x=100,y=100,p=45, h=false, n=4, i = 50000 produce a “labyrinth type” map.
x=100,y=100,p=55, h=true, n=4, i = 50000.
x=100,y=100,p=45, h=true, n=4, i = 85000.
x=100,y=100,p=45, h=false, n=2, i = 50000.