Evil Science A whole load of stuff

6Jan/140

Island and labyrinth generating algorithm using C#

This is a simple generating routine I developed in C# whilst experimenting whilst playing around with the algorithms for?Conway's Game of Life.By adjusting the properties it can produce "island" or "labyrinth " type maps.?I "discovered" this algorithm

Here's a few examples of maps it can generate, with the property values used to create them.??Explanations of the properties are given later in the article.

default.png
x=100,y=100,p=45, h=true, n=4, i = 50000 produce an "island" map.
variant1.png
?x=100,y=100,p=45, h=false, n=4, i = 50000 produce a "labyrinth" map.
variant2.PNG
 x=100,y=100,p=55, h=true, n=4, i = 50000.
variant3.PNG
 x=100,y=100,p=45, h=true, n=4, i = 85000.
variant5.PNG
x=100,y=100,p=45, h=false, n=2, i = 50000.
variant6.PNG
 x=100,y=100,p=75, h=true, n=5, i = 80000.

Using the App

Load up the app, fiddle with the properties and click the?Go button.

How it Works

Map generation is controlled by the following variables:

  1. p (int) - close cell probability. Between 0 and 100.
  2. h (bool) - cell operation specifier.
  3. i (int) - counter.
  4. n (int) - number of cell's neighbours.
  5. c (int) - examined cell's closed neighbours. Between 0 and 8.

Calling the method go() in the class csIslandMaze?will generate a map using the following logic:

  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.

Source Code

You can download the C# source code here.

Github: here.

Filed under: C#, Roguelike Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


× seven = 42

Trackbacks are disabled.