Re: Maze Code [LONG]

From: Doppleganger Software (doppsoft@junctionnet.com)
Date: 02/16/97


>I was curious if you were still working on generating mazes within
>CircleMUD and still planning on releasing it?  I would be quite
>interested in what you have to offer in that field.

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.
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
|    Or send 'info circle' to majordomo@cspo.queensu.ca     |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST