# Random Map Generation Using Random Walks

I’m trying to create a random map using random walks of 5 starting at the room in the center but I can’t figure out where I’m going wrong. I’m using a modified version of this [url]https://intfiction.org/t/if-archive-hugo-downloads/59/1]

and my code looks like this:

[code]Volume - Map Generation

Book - Global Initialization

Part - Placed and Unplaced

A room can be placed or unplaced. A room is usually unplaced. [To randomly place unplaced rooms.]

Part - Trying

A room can be tried or untried.

Part - Egress

Egress relates a room (called the place) to a direction (called the way) when the room-or-door the way from the place is not nothing.

The verb to open to (it opens to, they open to, it opened to, it is opened to, it is opening to) implies the egress relation.

Part - X and Y Coordinates

Chapter - Coordinate Initialization

A room has a number called the x-coordinate. [To map the rooms on a grid with mathematical direction values.]
A room has a number called the y-coordinate.
The x-coordinate of a room is usually -99. The y-coordinate of a room is usually -99

Chapter - Table of Increments

Table of Direction Increments
direction x-increment y-increment
North 0 1
South 0 -1
East 1 0
West -1 0

Volume - Forest Generation

A forest room is a kind of room. Some forest rooms are defined by the Table of Forest Places.

Book - Start Room

The Quiet Clearing is a forest room. “You are surrounded by a thick brushy forest. It’s quiet here, but you can sense that many dangers lurk within these woods.” The Quiet Clearing is placed. The x-coordinate of the Quiet clearing is 0. The y-coordinate of the Quiet Clearing is 0. The player is in the Quiet Clearing.
The Forest Edge is a forest room. “The forest seems to trail off here into something else…”. The forest room is unplaced.

Book - Table of Forest Rooms

Table of Forest Places
forest room Printed Name Description
FR1 “Thicket” “A place”
FR2 “Thicket”
FR3 “Thicket”
FR4 “Humid Clearing”
FR5 “Serene Grove”
FR7 “Calming Clearing”
FR8 “Peaceful Grove”
FR9 “Bustling Thicket”
FR10 “Loud Clearing”
FR11 “Sunny Clearing”
FR12 “Warm Grove”
FR13 “Thicket”
FR14 “Thicket”
FR15 “Clamouring Underbrush”
FR16 “Rustling Woods”
FR19 “Eerie Thicket”
FR20 “Distracting Clearing”
FR21 “Thicket”
FR22 “Rocky Underbrush”
FR23 “Decaying Thicket”
FR24 “Dark Clearing”
FR25 “Unsettling Thicket”
FR26 “Thicket”

Book - Process

To generate the forest:
while a forest room is unplaced:
let locus be a random unplaced forest room;
if locus can be placed:
now locus is placed;
otherwise:
reset the forest;
if the Forest Edge can be placed:
say “Forest generated successfully!”;
otherwise:
reset the forest.

To reset the forest:
repeat with locus running through forest rooms:
if locus is not the Quiet Clearing, remove locus from the map; [removing it from the map is a custom phrase; see below]
generate the forest.

To remove (locus - a forest room) from the map:
now locus is unplaced;
now the x-coordinate of locus is -99;
now the y-coordinate of locus is -99;
repeat with the way running through directions:
if the room-or-door the way of locus is not nothing:
change the opposite of the way exit of the room-or-door the way of the locus to nowhere;
change the way exit of the locus to nowhere.

To decide whether (locus - a forest room) can be placed:
repeat with Z running from 1 to 5:
now every forest room is untried;
while a placed forest room is untried:
let entryway be a random untried placed forest room;
now entryway is tried;
if the locus can be placed next to the entryway:
repeat through the Table of Direction Increments:
if the room-or-door the direction entry of the locus is not nothing:
next;
otherwise if a room is mapped at (the x-coordinate of the locus plus the x-increment entry) by (the y-coordinate of the locus plus the y-increment entry):
let the candidate be the room mapped at (the x-coordinate of the locus plus the x-increment entry) by (the y-coordinate of the locus plus the y-increment entry);
change the direction entry exit of the locus to the candidate;
change the opposite of the direction entry exit of the candidate to the locus;
yes;
no.

To decide whether (new room - a room) can be placed next to (old room - a room):
sort the Table of Direction Increments in random order;
repeat through the Table of Direction Increments:
unless a room is mapped at (the x-coordinate of the old room plus the x-increment entry) by (the y-coordinate of the old room plus the y-increment entry):
place the new room to the direction entry of the old room;
now the new room is placed;
now the x-coordinate of the new room is the x-coordinate of the old room plus the x-increment entry;
now the y-coordinate of the new room is the y-coordinate of the old room plus the y-increment entry;
yes;
no.

To place (new room - a room) to the (way - a direction) from/of (old room - a room):
change the way exit of the old room to the new room;
change the opposite of the way exit of the new room to the old room.

To decide which object is the room mapped at (x - a number) by (y - a number):
repeat with test room running through placed rooms:
if the x-coordinate of test room is x and the y-coordinate of test room is y, decide on test room;
decide on nothing.

To decide whether a room is mapped at (x - a number) by (y - a number):
if the room mapped at x by y is nothing, no;
yes.[/code]

I’m not sure where I’m going wrong but I know once I have this down pat I can really get cooking on my code.

Thanks for any and all help.

Just an FYI: The main issue right now is that when I load the code, none of the rooms are connected

I think it’s just that you never call the “generate the forest” phrase! Just add this:

``When play begins: generate the forest.``

and I’m getting a connected map.