Classic Computer Magazine Archive COMPUTE! ISSUE 53 / OCTOBER 1984 / PAGE 26

A Parser's Tale Thom Adventure Games Work

Charles Brannon, Program Editor

We all know that so far computers are not truly intelligent. Like all machines, computers operate in a consistent, logical, and straightforward way. Unlike people, computers are unable to make arbitrary decisions. Everything is black and white. That's why so many programmers, bent by weeks of midnight programming, cry. "Do what I mean, not what I say!"

Computers make decisions much like your home thermostat. The thermostat does not know that it is too warm, and therefore it needs to turn on the air conditioner. Two dissimilar metals, bound together, twist as one metal expands farther than the other. The metal plates make contact with the air conditioner switch, and separate when they cool down, releasing the air conditioner. A computerized thermostat would be no more aware of its function than the mechanical one. Machines operate in a predictable fashion.

Yet adventure games appear to be smart. In an adventure, you are playing in a specialized world, created by a programmer and administered by the computer. The descriptions paint a mental picture, and as you play you get the illusion that the adventure world is a complete, though tiny, universe. The computer seems to understand what you say, as long as you use the right vocabulary. You can open doors, light lamps, fight with trolls, converse with aliens, question criminals, dig for treasure, even ask for help. While you are playing an adventure, you can remain unaware that you are solving and rearranging a complex data base.

Adventure games, sometimes described as interactive fiction, have a basic story line, characters, and a setting. The setting may be a medieval dungeon, a distant planet (in a galaxy far, far away), an alien spaceship, or even a modern shopping mall. You are usually the protagonist, but you are not there in person. Instead, you command your alter ego, who acts out your commands.

Your persona may be a sword-wielding treasure seeker, a detective, or an average, hapless urbanite. You control your character by giving it commands like GO WEST or EAT HOUSE. In fact, you are commanding the computer to carry out your actions. Some adventures let you be more detailed, as in OPEN THE MANILA ENVELOPE, TAKE OUT THE LETTER, AND READ IT TO ME. In order to follow your orders, the computer must break the sentence into subcommands by checking for commas, periods, and conjunctions. Words like IT must be replaced with the most recent object. Adjectives and articles should be discarded. The sentence would become OPEN ENVELOPE/[REMOVE] LETTER/READ [LETTER].

Parsing

The process of breaking down and interpreting your command is called parsing. A parser routine within the program breaks each subcommand into an action verb (such as GO, OPEN, or READ) and an object (LETTER, HOUSE). The verb is then looked up in a dictionary of commands and replaced by a number. Most adventure games offer several synonyms. EXAMINE and LOOK are assigned the same number. The number causes the computer to jump to a specific subprogram that handles that action.

The object of a sentence is also turned into a number. This is a little more difficult. For example, the adventure might describe a room with an "old brown bag on the table." The player might say OPEN BAG, or GET THE BROWN BAG, or even TAKE OLD SACK. But BROWN BAG, BAG, and OLD SACK are all reduced to the same number. The GET/TAKE/PICK UP routine then uses that number to handle the request. For example, EAT POISON and EAT TREE must be handled in very different ways.

The more advanced parsers have even more to deal with. If ou entered SEE WHAT'S IN BAG, the adventure could k it down to SEE BAG. SEE nonymous with EXAMINE. EXAMINE routine checks its data base to see just what a BAG is, noting qualities such as the fact that a bag must be opened to see what's inside. You may then be told to open the bag first, or the adventure could assume that's what you've implied.

The Game Data Base

In a way, an adventure is an application like a disk operating system (DOS). In DOS, you use commands to manipulate files, for example, ERASE TEST. An adventure is no different, except you are manipulating the adventure's data base. An adventure data base consists of a map which describes how rooms or locales are linked together, objects such as treasure, and the status of various objects and situations.

You may be right next to another room, but unless the map allows direct movement to it (through a door, window, or transporter beam), you have to take another route. A room description includes legal exits and where the exits lead to, what objects the room contains, and room status, such as whether it's dark or lit. When you remove an object from a room, the room "forgets" that object. When you drop an object, the object is added to the room's description. Your player's status also has to be updated when you pick up an object, lose an object, gain powers, or get hurt. Some realtime adventures (where the clock keeps ticking and action keeps happening while you are deciding what to do) even take into account player fatigue. Your alter ego must sleep to regain energy.

Objects must be monitored. A lamp has a certain fuel supply, which is used up over time. The lamp can be either on or off, which temporarily affects the room description, lighting up a dark room. Some objects are incomplete in themselves, and must be assembled with other objects. For example, you could separately collect a bottle, some string, and some cooking oil. If it occurred to you to MAKE LAMP, the three items would become a crude lamp. A new object has been created, replacing the three separate ones. Don't think that you can make anything you want, though. Unless the programmer planned ahead to specifically allow you to create a lamp, you couldn't assemble one, even if you had all the necessary parts.

There are also variables for global status, such as the time of day. In a space adventure, there may be a status for the entire ship, like fuel and shields remaining. In more complex adventures, other people are like independent objects, with their own characteristics and descriptions. All these qualities, though, are numbers, and these numbers let a computer make arbitrary decisions. You can't GO NORTH if there is no north exit. If you have no sword, you can't fight with it. Unless you have a lamp, you cannot see within a dark room. The computer does not decide these things as a person would. It just understands statements like:

IF OBJECT = 10 THEN PRINT
"YOU CANNOT SEE HERE."

Anticipated Actions

The most difficult part of designing an adventure is not creating the basic plot and world, but in anticipating the actions the player might take. Again, there is nothing open-ended in an adventure. Every possible action you may try has to have been predicted and programmed for. Some players become frustrated by the illusion, and don't understand why they can't get the computer to do what they want. Certain synonyms just aren't in the adventure dictionary. You may be faced with a locked door, but without a key. "But, aha!," you say, "I have a crowbar that worked on another door." You try the crowbar, and it doesn't work. The programmer either forgot about the crowbar, or never intended it to be that easy.

It can be disturbing when you penetrate the illusion and realize you are the one being programmed. The adventure may have many solutions, but you are just trying to figure out one of the predetermined actions planned for you. No action you take could be described as creative or innovative, since the programmer already knew that you would try it. An adventure tries to make you feel that you are participating and affecting the outcome of the adventure, but you are really just solving a complex puzzle or maze. If you realize this, the frustration may disappear, and you can concentrate on cracking the programmer's schemes. You aren't really playing against the computer, but trying to unravel a cleverly contrived mystery.