## 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.

x=100,y=100,p=45, h=true, n=4, i = 50000 produce an "island" map.

?x=100,y=100,p=45, h=false, n=4, i = 50000 produce a "labyrinth" 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.

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:

*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.

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

- 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.

**Source Code**

You can download the C# source code here.

Github: here.

## Leave a comment