Newsgroups: rec.arts.int-fiction
Path: gmd.de!xlink.net!howland.reston.ans.net!agate!doc.ic.ac.uk!uknet!pavo.csi.cam.ac.uk!ojwb1
From: ojwb1@cl.cam.ac.uk (O.J.W. Betts)
Subject: Re: Teleportation? Magic words? Not really! (was: Original Adventure)
Message-ID: <1993Aug15.151503.28895@infodev.cam.ac.uk>
Sender: news@infodev.cam.ac.uk (USENET news)
Nntp-Posting-Host: over.cl.cam.ac.uk
Organization: U of Cambridge Computer Lab, UK
References: <)> <Aug.8.14.32.04.1993.9522@math.rutgers.edu> <)> <MAP.93Aug14005742@gaak.NIC.DSI.Net>
Date: Sun, 15 Aug 1993 15:15:03 GMT
Lines: 85

In article <MAP.93Aug14005742@gaak.NIC.DSI.Net>, map@NIC.DSI.Net (Michael Patton) writes:
|> In article <neilg.745186283@sfu.ca> neilg@malibu.sfu.ca (Neil K. Guy) writes:
|> 
|>    >a) "Shorthand movement commands", that move you a short distance
|> 
|>     I'd love to be able to implement a feature like this in my TADS
|>    game.  [...]  This command would appear to the user as an extension
|>    of the "go" command.  S/he could just type "go to x" or "run to the
|>    mad scientist's laboratory" and off they'd go.
|> 
|>     Unfortunately this sort of thing requires a hell of a lot of work to
|>    set up, and I sure haven't figured out a neat way of doing it.
|> 
|> It doesn't seem that hard to me, let me try and outline how I'd do
|> it...  This would be easiest if the underlying system did it as some
|> list manipulation stuff can make it better, but it _can_ be done with
|> a fixed array...if your game's average fanout (number of neighbor
|> rooms) is N and you want to allow going M rooms away, an array of N^M
|> elements should give you this "on average".

That's way too many - it's just a simple "shortest route in a maze"
problem.  You need one integer per room and flags to indicate if the
player has traversed each connection between rooms.

|> [algorithm deleted]

For simplicity I'll use 'link' to refer to a link between rooms that has
been traversed by the player. Okay, here's what to do:

(a) Set all the room flags to 'infinity', the highest possible value ie
32767 if they're 16 bit ints.

(b) Set the room flag of the player's current location to 0.

(c) Execute the following C-style pseudo-code:

 fDone=1;
 do
  {
  for( all rooms )
   {
   if (flag(room)<infinity)
    {
    for( all links )
     {
     if (flag(room->link)>flag(room)+1) /* this copes with 1 way links */
      {
      flag(room->link)=flag(room)+1
      fDone=0;
      }
     }
    }
   }
  } while (!fDone);

(d) The player can reach a room if-and-only-if flag(room) is not infinity

(e) If this is the case, an optimal route from here to there is given by:

 current=0;
 room=here;
 while (room!=there)
  {
  for ( all links )
   {
   if (flag(room->link)==current+1)
    {
    room=room->link;
    current=current+1;
    printf("moved to room %s\n",room->desc);
    break; /* exit for loop */
    }
   }
  /* ought to check that it has moved somewhere just in case */
  }

That's about it. The above code might not be completely right, but
the idea is sound (I've implemented it before). You can do it more
neatly with recursion, but many adventure writing languages don't
have it, and it's a bit unpredicatabl in terms of space requirements.

Ol

PS Feel free to use the above idea in you're own games. I'd be interested
in hearing of the results.
