Interactive Fiction and Natural Language Processing David J. Snyder 1 What is Interactive Fiction? “Interactive fiction, often abbreviated as IF, is a simulated environment in which players use text commands to control characters.” Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Interactive_fiction April 5, 2005 Best known example is a series of “text adventure games” produced by a company called Infocom in the 1980s. 2 The classic example is ZORK ZORK has been made available as freeware by Activision, the current owner of the Infocom properties, and is available for download at http://www.infocom-if.org/downloads/downloads.html 3 A Short History All IF has one common ancestor- the game ADVENTURE. “In 1975, Will Crowther wrote the first text adventure game, Adventure. It was programmed in Fortran for the PDP-10 In 1976, Don Woods discovered Adventure while working at the Stanford Artificial Intelligence Lab, and obtained Crowther's permission to expand the game. Crowther's original version was more or less realistic; Woods' changes were reminiscent of the writings of J.R.R. Tolkien, and included a troll, elves, and a volcano inspired by Mount Doom. “ Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Interactive_fiction April 5, 2005 Also know as ADVENT and Colossal Cave 4 Adventure Continues “My idea was that it would be a computer game that would not be intimidating to non-computer people, and that was one of the reasons why I made it so that the player directs the game with natural language input, instead of more standardized commands. My kids thought it was a lot of fun." — William Crowther The Colossal Cave Adventure page http://www.rickadams.org/adventure/a_history.html April 5, 2005 5 Adventure Examples Commands (Adventure) “only accepts commands of one or two words…” Montfort,2003. page 108 Examples- “IN”, “N”, “GET SILVER”, “DROP KEYS”, “LAMP ON”, “XYZZY”, “PLUGH” Adventure – Solving in in Easy Steps From The Rom Ranger- Dr. Digital http://www.textfiles.com/100/adventur.txt April 5, 2005 Location “YOU ARE AT A COMPLEX JUNCTION. A LOW HANDS AND KNEES PASSAGE FROM THE NORTH JOINS A HIGHER CRAWL FROM THE EAST TO MAKE A WALKING-PASSAGE GOING WEST. THERE IS ALSO A LARGE ROOM ABOVE. THE AIR IS DAMP HERE.” Montfort, Nick 2003 Twisty Little Passages :An Approach to Interactive Fiction Cambridge, MA:The MIT Press page 88 6 ZORK Zork was developed by students at MIT’s Laboratory of Computer Science as a follow-up to Adventure. It was originally written in MDL, a LISP variant that allowed for the creation of user-defined data types. The vocabulary of the mainframe version included 908 words of which 71 were distinct actions. Leibling, P. David, Marc S. Blank and Timothy A. Anderson 1979 “Zork: A Computerized Fantasy Simulation Game” IEEE Computer 12(4)(April): 51-59. http://www.csd.uwo.ca/~pete/Infocom/Articles/ieee.html April 5, 2005 7 ZORK Object ;"An object: A stack of Zorkmid bills (Zorkmids are the currency of Zork)“ <OBJECT ["BILLS" "STACK" "PILE"] ;"The object's name and synonyms." ["NEAT" "200" "ZORKM"] ;"Adjectives which refer to the object." "stack of zorkmid bills" < + ,OVISON, READBIT, TAKEBIT, BURNBIT> ;"Properties of the object: it's visible, readable, takeable, flammable" BILLS-OBJECT ( ) ;"The contents of the object (always empty for this object)." 8 ZORK Object (cont) [ODESC1 "200 neatly stacked zorkmid bills are here." ;"The long description." ODESCO "On the floor sit 200 neatly stacked zorkmid bills." ;"The initial long description (when first seen by the player)." OSIZE 10 ;"The object's weight." OTVAL 15 ;"The value of the object: points for finding it and saving it." OFVAL 10 OREAD ,ZORKMID-FACE ;"What to print when the object is read."] ;"The elements of an object with tokens naming them are rare (few objects are readable and thus need OREAD slots). The other slots are common to all objects."> 9 Zork Object (cont) ;"The object function for the Zorkmid bills. It is there mostly to make a few sarcastic comments.“ <DEFINE BILLS-OBJECT ( ) <SETG BANK-SOLVE!-FLAG T> <COND (<VERB? "BURN"> <TELL "Nothing like having money to burn!"> <>) ;"Prints sarcasm but doesn't handle the command (accomplished by returning the false object <>). This allows BURN also to deal with it." (<VERB? "EAT"> <TELL "Talk about eating rich foods!"> ;"Doesn't allow EAT to run (by returning a non-false.")>> Leibling, Blank Anderson. 1979 10 “You are Dealing with a Fairly Stupid Parser” Montfort.2003 page 107 • First verifies all words in the command are in its vocabulary. Leibling, Blank, Anderson. 1979 • • Attempts to reduce the command to a verb and an optional direct object and indirect object. Verbs are mapped to known actions. Prepositions are considered part of the verb for determining an action. For example “Look under” would be distinct from “Look at” and handled differently. Leibling, P. David. 1980 “Zork and the Future of Computerized Fantasy Simulations” Byte (December) http://www.csd.uwo.ca/~pete/Infocom/Articles/byte.html April 10, 2005 11 “Stupid Parser” Continued The same verb can map to two different internal action representations. “Knock down the thief with rusty knife” [<action STRIKE> <object THIEF> <object RUSTY-KNIFE> “Knock on the thief” [<action RAP> <object THIEF> Leibling, Blank, Anderson. 1979 12 “Stupid Parser” Continued If an object is omitted and only one available object is associated with the command, the parser will attempt to use that. For example, if you enter the command “Attack”, the command attack is associated with a direct object of type “villain” and an indirect object “weapon”. If there is only “villain” type object present (for example “Troll” and you are only carrying one weapon (“sword”), they are placed in the appropriate spots in the attack verb frame and the command succeeds without further action required. However, if you are carrying two or more weapons, or nothing that is normally recognized as a weapon, the interactor will be asked what object to use and the answer will be rolled in as the object in the command. Leibling, Blank, Anderson. 1979 13 Parser Continued Adjectives are used to distinguish between like objects. For example, the “red button” or the “blue button” and are otherwise ignored. They can be combined with “all” and “but” to specify groups of objects. Adverbs were considered but not found a good use for. “The problem is to think of reason why you would not do everything ‘quietly’, ‘carefully’ or whatever.” Leibling. 1980 Determiners are completed ignored. Leibling, Blank, Anderson. 1979 14 ZORK Verb ;"The definition of the `verb' READ: "<ADD-ACTION "READ" "Read" [(,READBIT REACH AOBJS ROBJS TRY) ;"restrictions on characteristics and location of objects for defaulting - filling in an unadorned `READ' command. The object must be readable and accessible." ["READ" READER] DRIVER] ;"READER is the function, and the form `READ object' is preferred (the `driver')" [(,READBIT REACH AOBJS ROBJS TRY) "WITH" OBJ ["READ" READER]] ;"specification for `READ obj1 WITH obj2'" [(,READBIT REACH AOBJS ROBJS TRY) "THROU" OBJ ["READ" READER]] ;"specification for `READ obj1 THROUGH obj2'">;“ Synonyms for READ:"<VSYNONYM "READ" "SKIM">;"READER is the general reading function:“ 15 ZORK Verb (cont) DEFINE READER ( ) <COND (<NOT <LIT?,HERE>> ;"There must be light to read." <TELL "It is impossible to read in the dark."<) (<AND <NOT <EMPTY? <PRSI>>> ;"<PRSI> is the indirect object. If there is one, the player is trying to use something as a magnifying glass." <NOT <TRNN <PRSI>,TRANSBIT>> ;"If so, it better be transparent!"> <TELL "How does one look through a " 1 <ODESC2 <PRSI>> "?"> ;"It failed the test, so print sarcasm") (<NOT <TRNN <PRSO>,READBIT>> ;"The direct object should be readable." <TELL "How can I read a " 1 <ODESC2 <PRSO>> "?"> ;"It's not.") (<OBJECT-ACTION> ;"Now the object read gets a chance.") (ELSE ;"It didn't handle it, so print text." <TELL <OREAD <PRSO>>,LONG-TELL1>)>> Leibling, Blank, Anderson. 1979 16 Infocom Games Arthur: The Quest for Excalibur(1989) Ballyhoo(1986) Beyond Zork: The Coconut of Quendor (1987) Border Zone (1987) Bureaucracy (1987) Cutthroats (1984) Deadline (1982) Enchanter (1983) Hitchhiker’s Guide to the Galaxy (1984) Hollywood Hijinx (1986) Infidel (1983) James Clavell’s Shogun (1989) Journey: The Quest Begins (1989) Leather Goddesses of Phobos (1986) The Lurking Horror (1987) A Mind Forever Voyaging (1985) Moonmist (1986) Nord and Bert Couldn’t Make Head Or Tail Of It (1987) Planetfall (1983) Plundered Hearts (1987) Seastalker (1984) Sherlock: The Riddle of the Crown Jewels (1987) Sorcerer (1984) Spellbreaker (1985) Starcross (1982) Stationfall (1987) Suspect (1984) Suspended (1983) Trinity (1986) Wishbringer (1985) Witness (1983) Zork I (1980) Zork II (1981) Zork III (1982) Zork Zero (1988) Montfort. 2003 Page 122-124 17 The OZ Project The OZ Project was a research program out of Carnegie Mellon dedicated to the development of Interactive Drama. “We use the phrase ``interactive drama'' to mean the presentation by computers of rich, highly interactive worlds, inhabited by dynamic and complex characters, and shaped by aesthetically pleasing stories…. `highly interactive’ indicates the interactor is choosing what to do, say, and think at all times…” Kelso, Margaret Thomas, Peter Weyhrauch and Joseph Bates. 1992 “Dramatic Presenence” Technical Report CMU-CS-92-195 School of Computer Science Carnegie Mellon University Pittsburgh, PA, December Originally appeared in PRESENCE- The Journal of Teleoperators and Virtual Environments 2:1 http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/oz/web/papers/CMU-CS-92.195.pos Excerpt at http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/oz/web/overview2.html April 12, 2005 18 High Level View of OZ Matteas, Michael. 1997 An Oz-Centric Review of Interactive Drama and Believable Agents Technical Report CMU-CS-97-156 School of Computer Science Carnegie Mellon University Pittsburgh, PA. June http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/oz/web/papers/CMU-CS-97-156.html April 11, 2005 19 Believable Agents “In an interactive environment, eccentric personalities … cover up … limitations.” “(Joseph) Bates (of Oz) recommends modeling … after … the highly engaging characters of cartoons, comics, and the theater of the absurd.” Graceful degradation- “unanswerable questions are handled in a way that neither halts the conversation nor break’s the user’s willing suspension of disbelief.” Ryan, Marie-Laure. 2001 Narrative as Virtual Reality Baltimore: The Johns Hopkins University Press Page 314 20 Believable Agents – other issues “Incomplete or Ungrammatical Input” Failure- “Can have personality specific effects… Misunderstanding is expected.” Consistency – “It would be difficult to accept as believable an agent that says things it cannot understand.” Loyall, A. Bryan. 1997 “Some Requirements and Approaches for Natural Language in a Believable Agent” Creating Personalities for Synthetic Actors: Towards Autonomous Personality Agents (Lecture notes in computer science; 1195 : Lecture notes in artificial intelligence) Robert Trappl; Paola Petta (Eds.) New York: Springer Pages 117-118 21 ELIZA Effect “the tendency for people to treat programs that respond to them (people) as if they (programs) had more intelligence than they (programs) really do.” Stern, Andrew. 2002 “Virtual Babyz: Believable agents with Narrative Intelligence” Narrative Intelligence Michael Mateas and Phoebe Sengers (Eds.) Philadelphia: Benjamins Publishing Company Page 217 “People who knew very well that they were conversing with a machine soon forgot that fact, just as theater goers, in the grip of suspended disbelief, soon forget that the action they are witnessing is not ‘real’…. They would often demand to be permitted to converse with the system in private, and would, after conversing with it for a time, insist, in spite of my explanations, that the machine really understood them.” Weizenbaum, Joseph. 1976 Computer Power and Human Reason San Francisco: W.H. Freeman and Company Page 189 22 ELIZA Transcript “Do you think that I can use the computer this morning? WHY DO YOU ASK? I might be able some additional telcomp sales. WHY AREN’T YOU SURE? My prospective customers have never seen a demonstration of the system. DOES THIS MEAN VERY MUCH TO YOU? Of course it does. YOU SEEM VERY POSITIVE ABOUT THAT. This is ridiculous. WHAT DO YOU MEAN THIS IS RIDICULOUS? Is there any reason why I can’t use the computer now? TELL ME MORE ABOUT YOUR PROSPECTIVE CUSTOMERS. Please dial me up on 491-1850” Murray, Janet. 1997 Hamlet on the Holodeck: The Future of Narrative in Cyberspace New York: Free Press Page 70 As reported by Daniel G. Bobrow of Bolt Beranak and Newman (BBN) in the December 1968 issue of the SIGART Newsletter Murray. 1997 page 289 23 Façade: an experiment in interactive drama “In Façade, you, the player, using your own name and gender, play the character of a long-time friend of Grace and Trip, an attractive and materially successful couple in their early thirties. During an evening get-together at their apartment that quickly turns ugly, you become entangled in the high-conflict dissolution of Grace and Trip’s marriage. No one is safe as the accusations fly, sides are taken and irreversible decisions are forced to be made. By the end of this intense one-act play you will have changed the course of Grace and Trip’s lives – motivating you to replay the drama to find out how your interaction could make things turn out differently the next time.” Matteas, Micheal and Andrew Stern. 2003 Façade: An Experiment in Building a Fully-Realized Interactive Drama Game Developers Conference, Game Design Track, March http://www.quvu.net/interactivestory.net/papers/MateasSternGDC03.pdf April 12, 2005 24 Trip and Grace Matteas and Stern. 2003 25 Façade - Goals 15-20 minutes of “emotionally intense, unified, dramatic, action.” Player should not be just an observer, but should have a significant effect on events without obvious branch points (like a Choose Your Own Adventure or hypertext would have.) Should be repeatable 6-7 times without player necessarily feeling s/he has exhausted all the possibilities Matteas and Stern. 2003 26 Façade Player interacts through movement and some gestures using the mouse and through typing in spoken dialog. Characters respond with spoken dialog and actions. Drama manager controls story beats. Changed about once a minute. Players actions are interpreted as “discourse acts”, “a concise summary of the general meaning”. These discourse acts are interpreted differently depending on the beat and effect the choice of future beats. Matteas and Stern. 2003 27 Discourse Acts Most have an option to refer to a character. “agree referTo <topic> disagree praise positive exclamation ally negative exclamation criticize light express happy criticize harsh express laugh oppose express sad flirt express angry pacify maybeUnsure provoke dontUnderstand greet thank goodbye apologizeExcuseMe getAttention intimate judgment suggestionAdvice misc-custom destructiveManipulation jokeTestLimits inappropriate bug comfort kiss physicallyFavor wanderAway” Matteas and Stern 2002 Page 15 Unrecognizable text maps to a discourse act “systemDoesNotUnderstand” Matteas and Stern 2002 Page 16 28 Façade – Natural Language Understanding Understanding is Broad and Shallow. Not concerned with syntax or semantics, but with the pragmatic effects. Phase 1 turns surface text into discourse acts. Phase 1 rules are generally shared across all beats. Rules map “islands” of text. Phase 2 determines what effect the discourse act has on behavior of the characters Mateas, Michael and Andrew Stern. 2004 “Natural Language Understanding in Façade: Surface Text Processing” Best Paper Award, Technologies for Interactive Digital Storytelling and Entertainment (TIDSE),, Darmstadt, Germany, June Page 2 http://www.quvu.net/interactivestory.net/papers/MateasSternTIDSE04. pdf April 11, 2005 29 Pattern Sub-language (X Y) (X | Y) ([X]) * ? (tand X Y) (tor X Y) (toc X) (tnot X) exactly X and Y exactly X or Y optional Many words One word X and Y in the string in any order X or Y in the string X in the string X not in the string Basically regular expressions with some shortcuts to allow easy typing. Mateas and Stern. 2004 Page 5 30 Template Language ;; A template rule for agreement (defrule global-agree-rule1 (template (toc (love (to | it | that)))) => (assert (iAgree))) iAgree will combine with other rules to determine addressed (potentially none) to produce DAAgree Mateas and Stern. 2004 Page 5 31 Positional Facts Rules can provide positional information about where the match occurs. ;;Rule for recognitional positional “is” fact (defrule positional_Is (template (tor am are is seem seems sound sounds look looks)) => (assert (iIs ?startpos ?endpos))) ;;Rule for recognizing positional “positive description fact (defrule positional_PersonalPosDesc (template (tor buddy comrade confidant friend genius go-getter pal sweetheart)) => (assert (iPersonalPosDesc ?startpos ?endpos)) ;; Rule for recognizing praise (defrule Praise_you_are_PersonPOs (template ({iPersonPosDesc} | (you [{iIs}] [a|my] {iPersonPosDesc} *))) => Mateas and Stern. 2004 (assert (iPraise))) Page 7 32 Sample Rules Processing “Hello, Grace” Pseudocode: “hello” iGreet “grace” iCharacter(Grace) iGreet and iCharacter(?x) DAGreet(?x) means DAGreet(Grace) Mateas and Stern. 2004 Page 2 Additional iGreet rules would be written for other greetings than hello. Mateas and Stern. 2004 Page 3 33 Rules Additional Rules can be specified to use WORDNET for synonym and hyponym relationships. For example, a rule could apply to “alcoholic beverage” and if you said “I’d like some Chablis”, the parser would determine that “Chablis” is a kind of wine which is a kind of alcoholic beverage and that rule potentially applies. Rules can also support stemming. Mateas, Michael and Andrew Stern. 2002 “Architecture, Authorial Idioms and Early Observations of the Interactive Drama Façade “ CMU-CS-02-198 December 5, 2002 http://reports-archive.adm.cs.cmu.edu/anon/2002/CMU-CS-02-198.pdf Page 16 34 April 11, 2005 Rule Ranking • • • • First tier of rules handle low-level patterns (like is rule) Second tier handles idiomatic expressions (~1000 pertinent to the domain) Third tier handles negation Final tier looks for key words and combinations (like in positional example) to produce final discourse act. Mateas and Stern. 2004 Page 9 35 Rules ~800 template rules compile to ~6800 internal rules Mateas and Stern. 2004 Page 7 Rules “err on the side of being overly permissive.” Statements made by players may be misinterpreted and the characters aren’t going to be correcting anyone’s grammar. Matteas and Stern 2002 Page 28 36 Discourse Act Examples (DAAgree ?char) (DADisagree ?char) (DAPositiveExcl ?char) (DANegExcl ?char) (DAExpress ?char ?type) Certainly. No doubt. I would love to. No way. Fat chance. Get real. Not by a long shot. Yeah. Wow. Breath of fresh air. Damn. That really sucks. How awful. D’oh. I’m thrilled. That bums me out. ha ha (laughter) It really pisses me off (angry) (DAMaybeUnsure ?char) I don’t know. Maybe. I guess so. You’ve lost me. (DaThank ?char) Thanks a lot (DaGreet ?char) Hello. What’s up. (DAAlly ?char) I like you. You are my friend. I’m here for you. (DAOppose ?char) Kiss off. You’re the worst. I hate you. (DADontUnderstand ?char)I’m confused. I don’t get it. What are you talking about. Mateas and Stern. 2004 Page 3 37 Discourse Act Examples (cont) (DAApologize ?char) I’m sorry. My bad. How can I make this up to you. (DAPraise ?char) You’re a genius. What a sweetheart you are. (DACriticize ?char ?level) You’re weird. (light) What a dipshit. (harsh) (DAFlirt ?char) You look gorgeous. Kiss me. (DAPacify ?char) Calm down. Relax, guys. Take it easy. (DAExplain ?param ?char) Grace is lying. Trip is having an affair. (DAAdvice ?param ?char) You should get a divorce. Try to work it out. (DAReferTo ?char ?obj) I like the couch. Your wedding picture looks nice. (DAIntimate ?char) What’s wrong? Let it all out. Talk to me. (DAGoodbye ?char) Catch you later. So long. I’m out of here. (DAInappapriate ?char) “slut” (DAMisc ?char ?type) I’d like a drink. Is this a bad time. Should I leave. Mateas and Stern. 2004 Page 4 38 Phase 2 Reaction rules map discourse acts to reaction. Unlike the phase 1 rules, the templates for reaction rules are beat-specific. There also some shared global context. Each beat maps some or all ~40 discourse acts to 5-10 local reactions. Matteas and Stern 2002 Page 16-17 39 Typical Reactions Local “Player is mildly agreeing with the question/situation posed to her in this beat. Player is strongly agreeing with the question/situation posed to her in this beat. Player is mildly disagreeing with the question/situation posed to her in this beat. Player is strongly disagreeing with the question/situation posed to her in this beat. Player is not giving a direct answer to the question/situation posed to her in this beat.” Global - hundreds “Player has referred to an object in the room Player has done an affinitity move (e.g. praise, criticize, flirt) Player has referred to a related topic (e.g. marriage, divorce, infidelity) Player had repetitively pushed on a topic. Player has referred to the content of a previous beat.” If no reaction applies, system must deflect. Matteas and Stern 2002 Page 16-17 40 Beats Each Beat has “goals” and a “gist”. The gist generally occurs when all beat goals have been met. Before a gist occurs, reactions are consider “mixins”, causing the characters to react but not resolving the beat. After a beat gist occurs, one reaction will be a “transitionout.” There is one transition-out per beat. Mixins and transitions-out may have effect global state. To handle interrupts, beat goals have “repeat dialog alternatives” and “reestablish” dialog. “Drama manager” aka “beat sequencer” chooses next beat based on rules and interactions. Matteas and Stern 2002 Page 17-19 41 Trip and Grace Matteas and Stern. 2003 42 INFORM INFORM is one of the languages most commonly used by Text Adventure hobbyists today. It produces code that runs on the same virtual “ZMachine” that was used to run ZORK and various other Infocom games when they were released commercially. Nelson, Graham. 2001 The Inform Designers Manual Fourth Edition St Charles, IL: The Interactive Fiction Library http://www.inform-fiction.org/manual/DM4.pdf April 10, 2005 Page I 43 Inform Parser Grammar COMMAND <oops-word><word> | <action phrase> | <order> <oops-word> “oops” | “o” <order> <actor> “,” <action phrase> <actor> <noun phrase> <action phrase> <verb phrase> | <verb phrase> <then-word> <action phrase> <then-word> “.” | “then” <verb phrase> <again-word> | <imperative verb> <grammar line> <again-word> “again” | “g” <grammar line> <noun phrase > | <preposition> <noun phrase> | <grammar line> <noun phrase> <preposition> <noun phrase> | … <preposition> “on” | “under” … <noun phrase> <basic np> | <basic np> <connective> <noun phrase>|… <connective> <and-word> | <conjuction> | <but-word> <disjunction> <and-word> “,” | “and” <but-word> “but”| “except” Nelson. 2001 pages 245-246, 250 44 Inform Parse Parse of sentence “conan, put every sword in the box” Nelson. 2001 pages 250 45 Links and Resources Interactive Fiction Archive- http://www.ifarchive.org ZORK- http://www.infocom-if.org/downloads/downloads.html Hitchhiker’s Guide to the Galaxyhttp://www.bbc.co.uk/radio4/hitchhikers/game.shtml Hamlet- The Text Adventurehttp://www.robinjohnson.f9.co.uk/adventure/hamlet.html Façade (coming soon, hopefully)http://www.quvu.net/interactivestory.net Group Blog- http://www.grandtextauto.org Rec.arts.int-fiction and Rec.games.int-fiction 46