1999Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: AFAP: As fast as possible, non linear... -->
<!--X-From-R13: "dhmnu Mfbsgubzr]" <dhmnuNfbsgubzr.arg> -->
<!--X-Date: Fri, 1 Jan 1999 20:39:50 &#45;0800 -->
<!--X-Message-Id: 000401be35f9$7fe38aa0$e5066520@k6 -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Re: AFAP: As fast as possible, non linear...</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:quzah#softhome,net">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00003.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00006.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00002.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00012.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00005">Author</A>
&nbsp;|&nbsp;<A HREF="#00005">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00005">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: AFAP: As fast as possible, non linear...</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: &lt;<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>&gt;</LI>
<LI><em>Subject</em>: [MUD-Dev] Re: AFAP: As fast as possible, non linear...</LI>
<LI><em>From</em>: "quzah [softhome]" &lt;<A HREF="mailto:quzah#softhome,net">quzah#softhome,net</A>&gt;</LI>
<LI><em>Date</em>: Fri, 1 Jan 1999 18:40:30 -0800</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
From: Greg Connor &lt;gconnor#nekodojo,org&gt;
Date: Friday, January 01, 1999 2:29 PM
Subject: [MUD-Dev] Re: AFAP: As fast as possible, non linear...


&gt;Your previous messages in this thread talked about optimization (i.e. "as
&gt;fast as possible" - thus the subject line), so I thought I would add some
&gt;general comments about optimizing that might be helpful for this example
&gt;(and might possibly stimulate thought and discussion about optimizing in
&gt;general)


Nod. The reason I titled it thusly was because before I attempted to do
a maze generator I did a tiny bit of searching on the topic. The first
three or four mentions/algorithms I turned up were regarding a particular
PASCAL implementation where they said something like "in Pascal it takes
just about an hour to generate a 10x10x10 maze." I quit searching then
and decided to make my own. Since this particular (found searching) method
for making mazes was the the one that showed up the most, I though that
everyone as a whole was saying it was the best/most common, and so I was
thinking "damn if that's the best [most used] and it takes an hour?!"

I don't know too much about optimizing, OS specifics, and the like and
what I know I've managed to teach myself, so most of my methods are sure
to be inefficient, and most of the time I don't know what I'm talking
about as much as I'd like to. At any rate, some day with luck, money
and free time I'll get to take a few classes on said subjects. But in
the mean time I'll have to settle for the best I can manage.

Anyway, that's the reason for the topic name.

&gt;quzah [softhome] wrote:
&gt;&gt;(1) Store only the inner E and S walls for each row. This fits nicely
&gt;&gt;into a short integer for an 8x8 maze, requiring only 15 bits of each
&gt;&gt;short integer. The even bits (starting with bit0) are used for "south
&gt;&gt;walls" and the odd bits (starting with bit1) are used for "east walls".
&gt;
&gt;
&gt;You seem to be using bitwise storage, which implies that you would need to
&gt;do bitwise AND/OR operations to get yes/no decisions or to change data in
&gt;the bit array.  This seems like it would be an optimization in the "space"
&gt;domain at the expense of the "time" domain... probably this would be a good
&gt;place to investigate if you really want something to run as fast as possible.


Again I'm not too sure what ways are faster than another, but the whole
idea was to keep it under a second and to keep it compact. I just didn't
want some horrid maze creator that stopped the entire MUD dead in its
tracks for an hour, minute, or even more than a second.

[snip re: space vs time]

&gt;&gt;(2) I only check east and south when generating the maze. If the room
&gt;&gt;to the east is unused, or south is unused, pick one and remove the wall.
&gt;&gt;
&gt;&gt;The outer wall of the maze is never used. In addition, it is not even
&gt;&gt;stored. It is assumed, and therefore it is never needed. Since it is
&gt;&gt;not needed, why bother keeping track of it?
&gt;
&gt;There is another optimization hidden here... sometimes you may choose to
&gt;store something that is redundant to speed up your lookups (such as all
&gt;four walls instead of only two).  If you are walking the maze, and your
&gt;position is 3,3, you will want to know whether you can go north, south,
&gt;east or west.  For east and south, no problem, look up 3,3 in the table.
&gt;But for north you have to subtract one from Y and lookup 3,2 for its
&gt;"south" number.  What is the performance penaly for subtracting (or
&gt;"decrementing" even) one of the integers?  
&gt;
&gt;You have also set up a number of "special cases" or "border cases" where
&gt;you actually need to do the equvalent of two IF's instead of one most of
&gt;the time.  For example, if you want to go north, from 3,3, you have to read
&gt;the value from 3.2, but if you want to go north from 3,0 the answer is
&gt;automatically No, there is no North from here.  This means every time you
&gt;push N the computer needs to calculate:
&gt;if direction is north 
&gt; if y = 0
&gt;    no
&gt;  else 
&gt;    lookup x,(y-1)
&gt;    is "south" open? return yes


Ah, yeah, this is a good idea. I think I will go back to using a single
'char' for each cell of the maze. I am rather happy with being able to
store each maze plain packed into 8 short integers (16 bits * 8), but I
think I will do it this way, and keep track of each direction in each
cell. It will take a bit more work (1 more line of code per shot) for
creating a doorway to the next cell, but I think I'll do this anyway.

The main reason is, the maze as is doesn't scale. Period.

&gt;There is a similar condition on the east and south frontier... only the
&gt;comparison is "less than 8" which a computer might translate as "subtract 8
&gt;and branch on minus"
&gt;
&gt;One way to optimize in this situation might be to store all four values as
&gt;another index to the array... then instead of all the IF's you just have
&gt;"lookup 3,3,0, and branch if zero".


So it would be something like this?

#define DIRNORTH 0
#define DIREAST  1
#define DIRSOUTH 2
#define DIRWEST  3
#define DIRMAX   4

char cell[x][y][DIRMAX];
...
if( cell[3][3][DIRNORTH] ) go_north();

I think I'll toy with that and see what I can do with it. :)

&gt;There's another place where you can choose to store actual data, or
&gt;remember an implicit assumption, which is the outer frontier (points past
&gt;8).  You said "Since it's not needed, why bother keeping track of it?"
&gt;Well, one reason might be to save the programmer additional grief when it
&gt;comes time to change the size.  Right now you are kind of stuck with 8
&gt;because of the reliance on bitwise operations, but let's assume you can get
&gt;around that or code it away.  What happens when you want to go to a 16x16
&gt;square instead of 8?  Replace all occurences of 8 with 16.  If you want to
&gt;specify any size square?  Replace 16 with "SIZE" and #define SIZE 16 at the
&gt;top.  If you decide you want rectangles instead of squares?  Replace SIZE
&gt;with either WIDTH or HEIGHT and set #defines.


Yes. It sucks to try and scale it up. I did yesterday for a short while.
I made it so you #define MAZESIZE_EIGHT if you wanted it to be an 8x8
maze, and if it wasn't defined it assumed a 16x16 maze. This worked fine
in theory since I just jumped up to an 'int' rather than a 'short int'.
Then I did a

#ifdef MAZESIZE_EIGHT
#define MAZESIZE 8
#else
#define MAZESIZE 16
#endif

and replaced all the correct occurences of "8" in the code with "MAZESIZE"
and all of the "7" in the code with "MAZESIZE-1". I had to redo a few of
the macros which were bitshifting by 3 to either do by 3 or 4 depending on
the size of the maze. In the end I deleted the whole thing (what I had
been doing yesterday, not the original) because I never did end up getting
it to work right. All in all, it doesn't scale. I'm sure someone could
get it to scale, I probabaly could, but it isn't worth my time right now.
I'm happy with the way it works for now, since it was my first "working"
first effort. It makes a nifty little maze, and now I know I can make one,
so it gives me something to improve upon, coupled with the added bonus of
knowing I succeded this far. :)

&gt;Then there is the question of how to fill an arbitrary-sized space with
&gt;maze, like a circle.  Well, you immediately start thinking about how to
&gt;"store" the values at the edges rather than "assume" they are there :)
&gt;Assumptions like "where the edges are" are something that need to decide
&gt;early on whether you want to go for "more code" or "more data".


Nod. I hadn't even thought of other shapes yet. I was just trying for a
tiny little working maze generator. However, I think I'm going to make
it scaleable, at least as far as X and Y go, rectangular, plus Z number
of plains. (Circles, triangles and such will have to wait until I'm
feeling a bit more gutsy, and have a bit more know-how.)

&gt;&gt;I "cheat recurrsion" by using a switch/loop, and avoid any overhead that
&gt;&gt;the recurrsion normally would produce. In addition, I was (I'm sure it
&gt;&gt;was very inefficient) running out of stack space in the early versions
&gt;&gt;of the old generator, and this avoids that aspect all together.
&gt;
&gt;This is a clever technique.  If an algorithm is recursive, you can make a
&gt;recursive function, or "simulate" recursion with your own "stack" (such as
&gt;an array and counter).  You may still run out of "stack" but at least you
&gt;have more control over memory usage (ie. you don't have to store "return
&gt;address" of the calling function :)


I faked calling itself by having it not change the case variable and just
keeping track of the current "path" we were working in. I have a link to
stack-free recursion, but it's a bit beyond me, which is why I though up
doing it this way.

All in all, I am pretty pleased with myself, having made one that works
in its current size, is fairly quick, doesn't really use recursion and
should not really lag a mud down. Thanks everyone for the replies. Feel
free to keep commenting/sharing ideas, I appreciate all the help and
discussion.

Now I have to decide if I want to rewrite it now, or continue with my
latest idea. I'm thinking of hard-coding in objects. A single item will
represent all swords in the game. When Boffo wants a sword, he will go
and get one made to his specifications - but it will still be a single
VNUM for the sword. It's values will just be set differently:

obj-&gt;value[0] = BLADE_WIDTH_NARROW;
obj-&gt;value[1] = BLADE_SHAPE_CURVED;
obj-&gt;value[2] = 60; /* blade_length in cm */
...

Something like that. Then it will be either re-strung to get a different
short description and its long description will be generated when it is
looked at, or something like that. Shrug. Anyway. Thanks all for the
info, input and help.

Quzah.



</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00003.html">[MUD-Dev] Info about different skill systems</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00006.html">[MUD-Dev] Re: MUD Design doc (long)</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00002.html">[MUD-Dev] Re: AFAP: As fast as possible, non linear...</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00012.html">[MUD-Dev] ADMIN: New text formatting rule for MUD-Dev</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00005"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00005"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>[MUD-Dev] Re: MUD Design doc - Combat</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00032" HREF="msg00032.html">[MUD-Dev] Re: MUD Design doc - Combat</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Mon 04 Jan 1999, 06:29 GMT
<UL>
<LI><strong><A NAME="00034" HREF="msg00034.html">[MUD-Dev] Re: MUD Design doc - Combat</A></strong>, 
cynbe <a href="mailto:cynbe#muq,org">cynbe#muq,org</a>, Mon 04 Jan 1999, 08:37 GMT
</LI>
</UL>
</LI>
</ul>
</LI>
<LI><strong><A NAME="00014" HREF="msg00014.html">[MUD-Dev] Re: AFAP: As fast as possible, non linear...</A></strong>, 
quzah [softhome] <a href="mailto:quzah#softhome,net">quzah#softhome,net</a>, Tue 29 Dec 1998, 08:27 GMT
<UL>
<LI><strong><A NAME="00002" HREF="msg00002.html">[MUD-Dev] Re: AFAP: As fast as possible, non linear...</A></strong>, 
Greg Connor <a href="mailto:gconnor#nekodojo,org">gconnor#nekodojo,org</a>, Sat 02 Jan 1999, 00:09 GMT
</LI>
</UL>
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00005" HREF="msg00005.html">[MUD-Dev] Re: AFAP: As fast as possible, non linear...</A></strong>, 
quzah [softhome] <a href="mailto:quzah#softhome,net">quzah#softhome,net</a>, Sat 02 Jan 1999, 04:39 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00012" HREF="msg00012.html">[MUD-Dev] ADMIN: New text formatting rule for MUD-Dev</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Sun 27 Dec 1998, 21:15 GMT
<LI><strong><A NAME="00011" HREF="msg00011.html">[MUD-Dev] META: 1998 Topic Summary</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Sun 27 Dec 1998, 09:49 GMT
<LI><strong><A NAME="00010" HREF="msg00010.html">[MUD-Dev] Terragen</A></strong>, 
Vadim Tkachenko <a href="mailto:vt#freehold,crocodile.org">vt#freehold,crocodile.org</a>, Fri 25 Dec 1998, 07:49 GMT
<LI><strong><A NAME="00008" HREF="msg00008.html">[MUD-Dev] Re: MUD Design doc (long)</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Thu 24 Dec 1998, 07:57 GMT
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>