Newsgroups: rec.arts.int-fiction
Path: gmd.de!Germany.EU.net!EU.net!howland.reston.ans.net!torn!watserv2.uwaterloo.ca!undergrad.math.uwaterloo.ca!mlvanbie
From: mlvanbie@undergrad.math.uwaterloo.ca (Michael Van Biesbrouck)
Subject: Re: Prolog for writing IF?
Message-ID: <CMxqDG.C62@undergrad.math.uwaterloo.ca>
Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
Organization: University of Waterloo
References: <yjc-170394003032@b61539.student.cwru.edu> <2m9o9v$6tv@news.bu.edu> <yjc-170394143230@b61539.student.cwru.edu> <2mae2b$u5j@msuinfo.cl.msu.edu>
Date: Sat, 19 Mar 1994 23:24:52 GMT
Lines: 67

In article <2mae2b$u5j@msuinfo.cl.msu.edu>,
Steve Dunham <dunham@cl-next4.cl.msu.edu> wrote:
>Jerome Chan (yjc@po.cwru.edu) wrote:
>: Adventure in prolog by Dennis Merrit ISBN
>: 0-387-97315-X/3-540-97315-X. I'm wondering if anyone else has
>: written adventures in prolog? It looks _really_ easy, I'm surprised
>: that I don't see this mentioned in this ng.
>
>It would be nice if somebody who has seen this book could write a
>short example and post it (or put it in the if-archive).

Since writing adventures in Prolog (or other declarative languages)
interests me, I took a look at this book several months ago.  It
develops a single (very short) adventure, but uses several different
techniques to implement it.

If I remember correctly, it used Prolog's symbol input facilities to get
the input and didn't have an interesting parser.  These two problems
mean that without changing the input structure there were fairly severe
limitations.  I think that synonyms, punctuation and sentence structure
were all problems.

The adventure locatations and objects were largely implemented inside
the verbs, so making a new adventure would require rewriting most of the
code.  I was also disapointed with the introduction to Prolog that it
provided.  Overall, I found it very small-scale in both structure and
vision.  Despite these comments, however, this book does appear as a
resource in the Prolog FAQs.

Prolog allows you to take much more general approaches.  I suggest that
you try writing a `real' parser (tokenize to symbols, then parse the
symbols into a standard format) and verbs that accept objects.  Then you
can implement the adventure as a series of special cases followed by
more generic parts.  Something like:

look_at(_):-player_blinded, write("You can't see a thing!"), nl.

look_at(medusa):-here(medusa), kill_off_player("The sight of the
                               once-lovely woman turns you to stone").

look_at(sun):-blind_player.

look_at(Obj):-here(Obj), visible(Obj), long_description(Obj);
              write("You can't see that here."), nl.

This implementation assumes that assert is used in the code, but this is
not necessary (and is very inefficient in some versions of Prolog).  For
some implementations, the first and the second half of the last rules
might be required to fail (green cuts), or perhaps everything will
succeed with final cuts.

Predicates like here really should be (or be implemented using)
located_at(Obj, Loc) so that NPCs can run around stealing objects and
the player can command "go to the fountain" and take the shortest known
path for here to there.

The only problem with setting up a Prolog adventure is undo.  It
doesn't seem to be a very easy thing to do correctly in an unlimited
way.  If you want just one level of undo and are passing the current
state of the adventure to each rule, then sending the old state around
will work.

-- 
Michael Van Biesbrouck, UW CSC Librarian
gopher://descartes.uwaterloo.ca/h0/mathSOC/.csc/.www/.mlvanbie/homepage.html
	Spin-doctors are like evil anti-librarians; they're
	the Dark Side of the Force. -- Bruce Sterling
