[MUD-Dev] AFAP: As fast as possible, non linear...

quzah quzah
Sun Dec 13 22:45:49 CET 1998


Hiya all.

I'm finishing up a tiny maze generator, and all I need is a
tad bit of a speed gain. (Or more than a tad. :) I'm using
a 10x10x10 cube, generated a plane at a time (10x10). I am
linking them through one exit per plane (up/down), with the
bottom level's exit leading "out". Here's the basic rundown:

void mazePunch( char startX, char startY, char startZ, bool nuke){
   static char path[100];
   static char used;

   /* if nuke, zero the path, simple linear for() loop */
   /* then trash 'used' */

   /*
    startX and startY determine this planes 'current' location.
    {
    If any neighbor is zero (unused), note it (valid).
    Pick from the list of valid neighbors at random to use.
    Knock out the wall, them to us.
    Increment 'used'.
    If current == 0, increment 'used'.
    Knock out the wall, us to them.
    }
    {
    If no neighbors were zero, and we are zero, punch a hole
    from us to any valid neighbor (valid this time being an
    in bounds coord.) Increment 'used' since we are no longer
    zero.
    }
    if( used < 100 )
       recursive call with new coords for x and y.
    else return
    */
}

That about does it. The only thing I don't like about it is that
that I have a crappy way of getting the new coords for the next
recursive call. I'm currently using:

   mazePunch( number_range(0,9), number_range(0,9), FALSE );

Now, I know there has to be a much faster, non linear way to do
this, but I haven't thought of it yet, so I though it time I got
a bit of help for this snippet. :) The rest I'm pretty pleased
with. I'm thinking it should be pretty fast if I get around the
coord picking I'm using now. So, does anyone have a quick way
to grab a zero coord? (Oh, hmm, I just thought of a way I'll
try, but I'll post this anyway. I'll just run the list of used
and grab a random one of those with a zero neighbor. -- Anyway
while I try that, does anyone have any other faster/better ways
to do the coord grabbing?)

Thanks in advance.

Quzah.





More information about the mud-dev-archive mailing list