<!--
	Title: (Adventures in Adventuring) Please Parse the Zork
	Author: Ken Rose
	Source: Softline, v1(4)
	Date: March 1982
	Transcription by Steve Derby
-->

<img class="float-right-half" src="/public/img/articles/softline-please-parse-the-zork/cover-image.jpg" alt="A cartoon of a table with various objects on it">

The most famous scientist in the whole wide world was
being interviewed just before going into retirement.

"Doctor," he was asked, "looking back over all of human
history, can you tell us, what is the outstanding invention,
the greatest contribution ever made by anyone during the
annals of man's history?"

"The thermos bottle," replied the sage.

"The thermos bottle? Do you mean to say that the thermos
bottle supersedes the use of fire . . . the thermos bottle
overshadows the wheel, electricity, the harnessing of the
atom, the airplane?"

"Yes. The thermos bottle."

"But why, sir?" He was pressed.

The wise scientist looked at his questioner. "Because,"
he said, "if you put something into it hot, it stays hot. And,
if you put something into it cold, it stays cold."

"So what?" said the interviewer.

The old man looked at him and tugged on his beard.
"How do it know?"

**Understanding Was Never Easy.** As is the case with so
many of our marvelous inventions, it only knows because
we tell it. And our faithful computer also only knows something
because we tell it, because we communicate with it.

Take the matter of adventure games, for instance. Let's
consider how an adventure game understands and interacts
with us. Along the way, we'll take a look at the state of the
art in adventure game understanding — Zork.

Most adventurers have seen or played the *Colossal Cave*
adventure — what's often called the original *Adventure* —
either on a main frame, mini, micro, or in the form of an
electronic game. You'll recall that communication within
the game is usually accomplished by giving two-word commands
consisting of a verb and a noun.

In a typical situation, you might say, "Get snake," to
which the computer might respond, "Okay," or, "The snake
bites you and you're dead" or "I don't understand." The
computer also understands a few one word or one letter
commands, such as "East" or "E" for "Go East" or "Inv" or
"I" for "Inventory," meaning "List out the items I have in
my possession."

In the program, there are word and noun tables. As each
word is input, it is looked up in the tables to see if it is
legitimate and to see if the verb and noun "go together."
An appropriate message is then selected from the text messages
contained in the program and printed to the screen.

Let's tell the computer to "Get snake." How does the
computer know that you have told it two words, get and
snake? A moment's reflection will bring you to the conclusion
that something recognizes the blank space between the
two words and says, "Aha, there is a blank space. The first
word must end here, and the second word must start after
the blank space." If this is what you imagined, you're exactly
right.

**You Should've Paid Attention When They Taught You
To Diagram Sentences.** The breaking down of a group of
words into its grammatical components is called parsing,
and the mechanism—the program logic, if you will—is
called a parser. Most adventure games use a very unsophisticated
parser similar to the one used in the original
*Adventure*.

Except *Zork*.

In 1977, David Lebling and Marc Blank decided to produce
a better parser. They did this because they greatly
enjoyed the original *Adventure* but were troubled by the
limits to communication with the game. Over the next
couple of years, they wrote *Zork* on a PDP computer, giving
their game the ability to recognize adjectives and to understand
conjunctions and multiple sentences.

Say you're in a room and find three buttons to push—
a red button, a green button, and a yellow button. In a
typical adventure game, one with a fairly unsophisticated
parser, the ensuing action might go like this:

"Push button," you say.

The computer responds, "Which one?" or, "I don't
understand."

After thinking it over, you go back to your original tack.

"Push red," you type, and the computer understands.

Only when you figure out that "Push red" is the two-word
command the computer is set up to respond to will
the computer do your bidding.

In *Zork*, you can say "Push red button" and the computer
understands exactly what you mean. In fact, *Zork* allows
you to string commands together. You can say, for instance,
"Push red button then push green button. Go north.", and
the computer would know just what to do. Once you get
into the habit of using this feature, it's very difficult to go
back to the old two-word mode. Another superlative command
in *Zork* is "Get all." This allows you to get every item
in a room without having to type in each item one at a
time. This command is complemented with a "Drop all"
command.

**Phoning It In.** You probably know already that a modem
(modulator/demodulator) is the device that you use to hook
up your computer through the phone lines to other computers.
You probably also know that there are bulletin boards
you can access that have all sorts of entertaining information
computer folks love. One of the major uses is trading
information and hints on adventure games.

In late 1979 and through 1980, bulletin boards were
buzzing with comments like "How do you open the egg?"
and "Is there anything worthwhile in the echo room? If
there is, how can I talk to the computer over the echos?"
*Zork* had started making the mainframe circuit and was
provoking a lot of interest. In fact, a *Zork* user group formed
in Milwaukee. In 1981, *Zork I* was brought out for the
Apple Computer and the bulletin board networks really
started humming with people looking for clues and hints.

According to Dave Lebling, about two-thirds of the
original *Zork* was used on the Apple version of *Zork I*.

In the fall of 1981, *Zork II*, which is about the same size
as *Zork I*, was brought out. It contained most of the remainder
of the original *Zork*, along with additional material.
*Zork III* is currently in the mill and will, according to
Lebling, finish up the series.

*Zork II* contains another new feature, one found in no
other currently available adventure — the ability to carry
on conversations with some of the characters you meet
along the way.

**Epicaresque.** But *Zork* has a larger attribute that makes
it different from all others—it is truly an epic adventure.
When you start out in *Zork I*, you are in a forest. As you
wander around, you eventually come to a house in a clearing.
After some trials and tribulations, you are able to enter
into the Great Underground Empire. Upon entering, you
must battle several nasty folks and, if you defeat them, you
can continue on your journey.

Your trip takes you down an underground river, through
a mine with strange machinery, and to weird and mysterious
temples and dungeons. Always lurking in the dark are the
mysterious grues, waiting to pounce on you if you give them
the slightest opportunity. There is one not-too-difficult
maze that must be thoroughly explored if you are to complete
the adventure successfully. The object of this adventure
is to collect treasures and store them. When you have
done this, you will find another opening into the empire
that puts you in position to tackle *Zork II*.

*Zork II* is subtitled "The Wizard of Frobozz." While you
can play it independently of *Zork I*, the practice you get in
*Zork I* will stand you in good stead, because *Zork II* is tough.
Not impossible, but tough.

**A Fierce and Funny Fellow.** As you journey down the
corridors of the Great Underground Empire, you will meet
and talk to the great Wizard of Frobozz himself. Unfortunately,
he doesn't like you very much, and with his affinity
for "F" words such as "float," "fall," and "fence," he'll give
you fits in completing his assignment. There is also a balloon
ride that takes you briefly out of the underground, a beautiful
princess with an affinity for unusual animals„ and a visit
to the Empire Savings Institution where you may meet the
gnome of Zurich.

Humor, adventure, multiple plot lines, and a really good
parser commend this adventure as the best there is at this
stage of the game.

Early on, we talked about the computer's recognizing
words in a table. Answering the question "How do it know?"
by referring to tables and parsing and all that jazz just may
not satisfy your curiosity. So let's go on.

**Stringing Along.** In Basic, there is a function called
string handling. A string variable differs from a numeric
(or real or integer) variable in that it's able to store letters
of the alphabet as well as representations of numbers and
most characters found on a keyboard. A string variable is
designated by a dollar sign ($) following a variable name,
and the information in the variable must be enclosed by
quotes. VI$ is a string variable named VI. VI$ = "piglet"
would tell the computer to store the word piglet in the
variable VI$. A function called *len* allows you to find out
how many characters are stored in a string variable. If we
ask the computer to *print len (VI$)* and VI$ = "piglet" the
computer will print the number six.

Another function, called *val*, allows you to find out what
the number value in a string variable is. If VI$ = "piglet"
and we say print *val (VI$)*, then the computer will print
0. But if VI$ = "72" then the computer will print 72 when
asked for the value of VI$. This doesn't seem like a big
deal, except that 72 in a string variable ain't really a number
in the same fashion as 72 in a number variable.

Another function of string handling in some Basics is
the ability to pluck out letters or blocks of letters from a
string. These functions are not available in all Basics, but
there is usually some way to emulate them.

They are *left$*, *right$* and *mid$*. Respectively, they can
select characters starting at the left side, right side, or the
middle of a string variable. If V1$ = "piglet" and we say
*print left$(VI$,2)*, the computer will print pi. Asking the
computer to *print right$ (VI$,2)* will cause the computer to
print et. And saying *print mid$ (VI$, 3,2)* will have the
computer print gl, because we have told it to print two
letters starting at the third letter.

What Happened to the Frog? With all this in mind, it's
time to take a look at the program listing that illustrates
these principles. Note that if your computer doesn't have
the *left$*, *right$*, or *mid$* functions, lines 235, 240, and 270
will have to be modified. Since what these lines do is look
through the string to find a blank, you can modify a get
routine or other string inspection routine, which your Basic
does understand, to do the same thing. In line 930, we
check for a yes or no answer by looking at the first character
at the left side of the string. This is also easily modifiable.
As always, if you have a question, drop me a note.

This little program also illustrates how a nine-word
vocabulary can be used in a lot of ways.

```
5 HOME : REM CLEAR SCREEN
10 REM HOW DO IT KNOW
15 REM DIM VARIABLES
20 DIM V1$(10),N1$(10)
25 REM LOAD DATA INTO VARIABLES
30 FOR A = 1 TO 4
35 READ V1$(A)
40 NEXT A
45 FOR A = 1 TO 5
50 READ N1$(A)
55 NEXT A
100 REM THE STORY STARTS HERE
105 PRINT "YOU'RE STANDING IN A ROOM. IN THE "
110 PRINT "MIDDLE OF THE ROOM ARE THESE ITEMS:
115 PRINT
170 REM LISTING OUT THE ITEMS
130 PRINT N1$(A)
135 NEXT
140 PRINT : PRINT
145 GOTO 200: REM GOING TO THE PARSER
150 REM BACK FROM THE PARSER. CARRYING OUT THE INSTRUCTIONS
155 IF V$ = "EAT" THEN GOTO 505
160 IF V$ = "SMELL" THEN GOTO 545
165 IF V$ = "DRINK" THEN GOTO 565
170 IF V$ = "GIVE" THEN GOTO 580
200 REM HERE'S HOW IT'S DONE
205 V$ = "":N$ = ""
210 PRINT "WHAT DO YOU WANT TO DO? ";
215 INPUT "";A$
220 REM NOW WE'LL BREAK DOWN THE INPUT
INTO VERB AND NOUN
225 REM FIRST GET THE VERB
230 FOR A = 1 TO LEN (A$)
235 IF MID$ (A$,A,1) = " " THEN X = A + 1:A = 0: GOTO 260: REM THIS LOOKS FOR THE BLANK SEPARATING THE WORDS
240 V$ = V$ + MID$ (A$,A,1)
245 NEXT A
250 X = A — 1: REM IN CASE THERE'S ONLY ONE WORD. IF X = THE WHOLE LENGTH OF THE STRING, THE NEXT LINE WILL
SEND YOU BACK TO THE BEGINNING
255 IF X = LEN (A$) THEN PRINT : PRINT "I CAN'T ";V$;" NOTHING.": PRINT : GOTO 100
260 REM NOW GET THE NOUN
265 IF X = LEN (A$) THEN PRINT : PRINT "I CAN'T ";V$;" NOTHING.": PRINT : GOTO 100
270 N$ = MID$ (A$,X, LEN (A$) — (X — 1))
275 REM CHECK TO SEE IF VERB IS GOOD
280 FOR A = 1 TO 5
285 IF V$ = V1$(A) THEN A = 0: GOTO 305: REM VERB IS O.K.
290 NEXT A
295 PRINT
300 PRINT "I CAN'T ";V$;" SOMETHING.": PRINT : GOTO 100
305 REM CHECK TO SEE IF NOUN IS GOOD
310 FOR A = 1 TO 5
315 IF N$ = N1$(A) THEN A = 0: GOTO 155: REM EVERYTHING CHECKS AND NOW WE'LL DO SOMETHING.
320 NEXT A
325 PRINT : PRINT "SORRY, THERE'S NO ";N$;" HERE.": PRINT : GOTO 100: REM SOMETHING'S WRONG SO WE HAVE TO START OVER
500 REM HERE'S WHERE THINGS HAPPEN
505 REM EATING THINGS
510 IF N$ = N1$(3) THEN CO = 1: PRINT : PRINT "I'M IN LOVE.": PRINT : GOTO 100
515 PRINT : PRINT "I CAN'T EAT A ";N$: PRINT : PRINT "BURP! I GUESS I CAN.": PRINT
520 FOR A = 1 TO 4
525 IF N$ = N1$(A) THEN N1$(A) = "":A = 0:GOTO 535
530 NEXT A
535 X = 0: FOR A = 1 TO 4:X = LEN (N1$(A)) + X: NEXT : IF X = 0 THEN GOTO 900: REM CHECKING TO SEE IF EVERYTHING EATEN
540 GOTO 100
545 REM SMELLING THINGS
550 IF N$ = N1$(1) THEN N$ = N1$(5)
555 IF N$ = N1$(3) THEN N$ = "SKUNK CABBAGE"
560 PRINT : PRINT "THAT SMELLS LIKE A"; N$;"" : PRINT : GOTO 100
565 REM DRINKING
570 IF N$ = N1$(4) THEN PRINT : PRINT "THAT WAS THE LAST BOTTLE OF SACRED ALE.": GOTO 900
575 PRINT : PRINT "YOU CAN'T.": PRINT : GOTO 100
580 REM GIVING THINGS A WAY
585 IF N$ = N1$(1) THEN PRINT : PRINT "WHAT? ";: GOTO 595
590 PRINT "YOU CAN'T GIVE A ";N$; "ANYTHING." : PRINT : GOTO 100
595 INPUT "";N$ : IF LEN (n1$(2)) > 0 AND N$ = N1$(2) AND CO > 0 THEN GOTO 800
600 PRINT : GOTO 100
800 REM AND HERE'S THE WINNING OUTCOME OF THE GAME
805 PRINT : PRINT "THERE IS A CLAP OF THUNDER AND THE "
810 PRINT "HIGH PRIEST OF YORE APPEARS, MARRIES"
815 PRINT "YOU AND THE PRINCESS, GIVES YOU HALF"
820 PRINT "A KINGDOM AND LEAVES. YOU HAVE WON.
825 PRINT "UNFORTUNATELY, THE PRINCESS HAS JUST"
830 PRINT "TURNED BACK INTO A GOAT."
835 END
900 REM AND HERE'S THE LOSING OUTCOME
905 PRINT : PRINT "OH OH. YOU HAVE OFFENDED MARVIN, CHIEF"
910 PRINT "GOD OF ADVENTURE PLAYERS AND BARBERS."
915 PRINT "HOWEVER, HE MAY GIVE YOU JUST ONE OR"
920 PRINT "MORE CHANCES TO PLAY AGAIN."
925 PRINT
930 PRINT "DO YOU WANT TO? ";: INPUT "";A$: IF LEFT$ (A$,1) = "Y" THEN RESTORE : GOTO 30
935 END
950 DATA "EAT","DRINK","SMELL","GIVE "
955 DATA "GOAT","FLOWER", "BOTTLE","PRINCESS"
```
