|
More Mazes [by Doppleganger Software] |
|
|
|
Posted Wednesday, August 12th @ 11:30:50 PM, by George Greer in the Specials dept.
Added Feb 18, 1997. Click the link below to read it or download it.
From: Doppleganger Software <baator@geocities.com>
Subject: Maze Code
Here it is.....it's LONG overdue, and after the release of the other one,
I figured an alternative one was needed.
Doppleganger Software's CircleMUD Random 10x10 Maze Maker
---------------------------------------------------------
In the db.c file, add the following make_maze function before the
reset_zone function:
void make_maze(int zone)
{
int card[400], temp, x, y, dir, room;
int num, next_room = 0, test, r_back;
int vnum = zone_table[zone].number;
for (test = 0; test < 400; test++) {
card[test] = test;
temp = test;
dir = temp / 100;
temp = temp - (dir * 100);
x = temp / 10;
temp = temp - (x * 10);
y = temp;
room = (vnum * 100) + (x * 10) + y;
room = real_room(room);
if ((x == 0) && (dir == 0))
continue;
if ((y == 9) && (dir == 1))
continue;
if ((x == 9) && (dir == 2))
continue;
if ((y == 0) && (dir == 3))
continue;
world[room].dir_option[dir]->to_room = -1;
REMOVE_BIT(ROOM_FLAGS(room), ROOM_NOTRACK);
}
for (x = 0; x < 399; x++) {
y = number(0, 399);
temp = card[y];
card[y] = card[x];
card[x] = temp;
}
for (num = 0; num < 400; num++) {
temp = card[num];
dir = temp / 100;
temp = temp - (dir * 100);
x = temp / 10;
temp = temp - (x * 10);
y = temp;
room = (vnum * 100) + (x * 10) + y;
r_back = room;
room = real_room(room);
if ((x == 0) && (dir == 0))
continue;
if ((y == 9) && (dir == 1))
continue;
if ((x == 9) && (dir == 2))
continue;
if ((y == 0) && (dir == 3))
continue;
if (world[room].dir_option[dir]->to_room != -1)
continue;
switch(dir) {
case 0:
next_room = r_back - 10;
break;
case 1:
next_room = r_back + 1;
break;
case 2:
next_room = r_back + 10;
break;
case 3:
next_room = r_back - 1;
break;
}
next_room = real_room(next_room);
test = find_first_step(room, next_room);
switch (test) {
case BFS_ERROR:
log("Maze making error.");
break;
case BFS_ALREADY_THERE:
log("Maze making error.");
break;
case BFS_NO_PATH:
world[room].dir_option[dir]->to_room = next_room;
world[next_room].dir_option[(int) rev_dir[dir]]->to_room = room;
break;
}
}
for (num = 0;num < 100;num++) {
room = (vnum * 100) + num;
room = real_room(room);
/* Remove the next line if you want to be able to track your way through
the maze */
SET_BIT(ROOM_FLAGS(room), ROOM_NOTRACK);
REMOVE_BIT(ROOM_FLAGS(room), ROOM_BFS_MARK);
}
}
in reset_zone, in the switch (ZCMD.command) cases add:
case 'Z':
make_maze(zone);
That's all the coding that is required. Make a zone that is a 10x10
selection of rooms all connected to one another like a grid. If you have
access to cartographer, just use this:
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
| | | | | | | | | |
I-I-I-I-I-I-I-I-I-I
If you want to change the rooms, to outside, just use 'O' instead. Do
what you will. :) Now, when you create this zone, go into the .zon file
and put in one command:
Z 0 0 0 0
This will do a reset of the maze. Everytime the zone resets, the maze
changes. If you set it to change only when someone is not in it, it
could make it interesting: One way to get through on the way there,
different path on the way back. I personally like it to change even if
there is someone IN the maze. Makes for more fun. >:) Just make sure
that this zone command is first, any others can be added after, but this
is the most important one, and should be done first. If you want to be
REALLY cruel, add the teleporter code in and then go nuts by adding
teleporters all over the maze. If you want to make a larger, or smaller
maze, then just look through the code for the 10's, and make those the
width of the maze, all the 9's would be width -1, and the 400 would be
rooms in zone * 4....you guys get the idea. It would take a little work,
but larger or smaller mazes could be done. I may do an update that can
detect the size of a maze and handle it accordingly.
The algorithm works more or less as follows:
I found the algorithm on the net. It's pretty simple actually and it
works for mazes of ANY shape (squares, cubes, hexagons, decahedrons, etc)
Draw out the map, with the shapes but all 'walls' being up. Go through
every wall, in a random way. If you can get to the room on the other
side of the wall through some other path, leave the wall, otherwise,
knock the wall out. That's why I used the track. The first part of the
code makes the walls, the next part does a 'card shuffle' (randomizes the
walls) and the last part goes through and decides. Then a clean-up part
removes all the BFS marks and add the NOTRACK.
<< Mazes [by Desmond Daignault] | Reply | View as text | Threaded | Multi Classing [by Garadon] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|