home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 232 / 232.d81 / t.textadvstru < prev    next >
Text File  |  2022-08-26  |  11KB  |  394 lines

  1. u
  2.       TEXT ADVENTURE STRUCTURES
  3.             by Paul Panks
  4.  
  5.  
  6.     Since the mid-1970s, attempts have
  7. been made to write text adventures
  8. using a variety of methods. Zork (to
  9. use an early example) was originally
  10. written at M.I.T. on a PDP series
  11. mainframe (using an obscure
  12. programming language known as MUDDLE).
  13. Zork was then translated into FORTRAN
  14. IV by unknown persons, and by 1979
  15. Infocom was formed to sell Zork to the
  16. computer industry at large.
  17.  
  18.     The fact that Zork was plainly
  19. inspired from the original Adventure
  20. by Will Crowther and Don Woods
  21. suggested that adventure games were
  22. appealing enough to stick around for
  23. awhile.
  24.  
  25.     By the time Zork took off, smaller
  26. memory personal computers were
  27. becoming commonplace. And so many
  28. people took it upon themselves to
  29. write adventure game drivers to fit an
  30. entire adventure game into a limited
  31. amount of RAM. People like Scott Adams
  32. and David Malmberg developed adventure
  33. games based on the two-word parser of
  34. the original Adventure.
  35.  
  36.     The structure of a text adventure
  37. is essentially the same today. You
  38. have several key components, including
  39. the parser and data structures. The
  40. parser can be a simple (or complex)
  41. routine. It is essentially responsible
  42. for breaking down small sentences into
  43. individual words useful to the
  44. computer. Once matched against an
  45. array of data within the data
  46. structures themselves, the computer
  47. then branches to specific subroutines
  48. in order to effectively process the
  49. inputed data.
  50.  
  51.     Data structures (on the other
  52. hand) rely both on numerical and
  53. alphanumerical data. Since data
  54. structures are almost entirely made up
  55. of a word list, the computer adventure
  56. can convert each word or phrase into a
  57. number used by the parser. So one can
  58. have an almost limitless word list
  59. consisting of verbs, nouns, adjectives
  60. and common phrases.
  61.  
  62.     Just what does a parser or data
  63. structure look like? While a parser
  64. can vary wildly from one adventure to
  65. the next, data structures are more or
  66. less the same across all adventure
  67. games.
  68.  
  69.     A very simple two-word parser
  70. might look like this:
  71.  
  72. 100 v=0:n=0: ne$="": n$="": n2$="":
  73.     v$="": v2$="": pr=0: pt=0: nm=0:
  74.     bz=0:FOR X=1 TO 10: wd$(x)="":
  75.     NEXT x :INPUT A$: pt=1: nm=0:
  76.     D$=A$: FOR a=1 TO LEN(D$)
  77. 101 IF MID$(D$, a, 1)=" " THEN
  78.     A$=MID$(D$,pt,a-pt):
  79.     pt=a+1:nm=nm+1:wd$(nm)=A$
  80. 102 NEXT a:nm=nm+1:
  81.     a$=MID$(D$$,pt,a-pt): wd$(nm)= A$
  82. 103 v$=wd$(1):ne$=wd$(2):
  83.     IF wd$(3)="and" OR
  84.     wd$(3)="then" THEN v2$=wd$(4):
  85.     n2$=wd$(5): co=1
  86. 104 IF wd$(3)="in" OR wd$(3)="from"
  87.     OR wd$(3)="to"
  88.     THEN v$=wd$(1): ne$=wd$(2): pr=1:
  89.     bz=1
  90.  
  91.     What lines 100 through 105
  92. accomplish is to break the sentence
  93. into individual words, and then assign
  94. each of those words into a string
  95. array -- wd$(nm). "nm" equals the
  96. number of words entered in this case.
  97. The parser also allows from complex
  98. commands, including PUT and GET FROM
  99. (e.g. "put medallion in bag", "get
  100. medallion from bag", "give medallion
  101. to hobbit", etc.)
  102.  
  103.     The next step is to check the
  104. entered data against a word list. This
  105. can be accomplished as follows:
  106.  
  107. 105 v=0:FOR x=1 TO 30:IF v$=vb$(x)
  108.     THEN v=x:x=30
  109. 106 NEXT:IF v=0 THEN
  110.     PRINT"What? Check your verb.":
  111.     GOTO 100
  112. 107 n=0:FOR x=1 TO 299:IF ne$=no$(x)
  113.     THEN n=x:x=299
  114. 108 NEXT:IF n=0 THEN
  115.     PRINT"Huh? Check your noun.":
  116.     GOTO 100
  117. 109 ON v GOSUB 120, 130, 140, 150,
  118.     160, 170, 180, 190, 200, 210
  119. 110 IF co=1 THEN co=0:GOTO 105
  120. 111 GOTO 100
  121.  
  122.     Note Lines 105 and 107. Line 105
  123. assumes the data table has a total of
  124. 30 verbs, and checks it against the
  125. values stored in vb$(x) or v2$. If a
  126. match is found, v is set to x (v=x),
  127. and the parser jumps to Line 106. If a
  128. match is not found (v=0), then the
  129. message "What? Check your verb" is
  130. printed out and the parser returns to
  131. Line 100.
  132.  
  133.     Line 107 checks for a valid noun,
  134. and assigns n to x if found (n=x). If
  135. not, n=0 and the message "Huh? Check
  136. your noun" is displayed, sending the
  137. parser back to Line 100.
  138.  
  139.     Line 109 branches off to verb
  140. subroutines based on the value stored
  141. in v (ON v GOSUB...). In my own verb
  142. table, I set my verbs as follows:
  143.  
  144. 1 - Go
  145. 2 - Get/Take
  146. 3 - Drop
  147. 4 - Inventory
  148. 5 - look
  149. 6 - examine
  150. 7 - read
  151. 8 - use
  152. 9 - climb
  153. 10 - light
  154.  
  155.     Ten verbs should be enough for
  156. most adventures, although with a
  157. larger verb list, the adventure game
  158. can become far more playable and
  159. interesting.
  160.  
  161.     Also, note Line 110. IF co equals
  162. 1 (IF co=1), then we set it back to 0
  163. (THEN co=0) and hop back over to
  164. process the input again (to Line 105).
  165. This ensures that if a larger command
  166. has been entered -- "get sword and
  167. then go east" -- the parser recognizes
  168. it and works each command separately
  169. ("get sword" followed by "go east").
  170. The advanced Infocom parsers used in
  171. Zork and other adventures utilized
  172. such a parser system.
  173.  
  174.     Now on to data structures. What do
  175. they look like? Well, they can look
  176. like anything you want, so long as
  177. they contain the basis of the
  178. adventure game. For the purposes of
  179. this article, I will list a short data
  180. table and explain what each DATA
  181. statement means.
  182.  
  183.     A simple data table might look
  184. like this:
  185.  
  186. 500 DATA "go", 1, "get", 2, "take", 2,
  187.     "drop", 3, "inventory", 4, "look",
  188.     5, "examine", 6
  189.  
  190. 501 DATA "read", 7, "use", 8, "climb",
  191.     9, "light", 10
  192.  
  193. 502 DATA "north", 99, "south", 99,
  194.     "east", 99 "west", 99, "up", 99,
  195.     "down", 99
  196.  
  197. 503 DATA "lantern", 17, "oil", 5,
  198.     "torch", "book", 12, "food", 1,
  199.     "wine", 1, "water", 2, "well", 2,
  200.     "altar", 5, "bible", 5
  201.  
  202. 504 DATA "rope", 6, "barrels", 6,
  203.     "knapsack", 6
  204.  
  205. 505 DATA "ogre", 23, "werewolf", 18,
  206.     "villager", 2, "clerk", 3,
  207.     "priest", 5, "bartender", 1,
  208.     "paladin", 17, "hobbit", 24
  209.  
  210. 506 DATA "goblin", 28, "knight", 31,
  211.     "barbarian", 29, "dragon", 20,
  212.     "vampire", 33, "ghost,
  213.     38, "spider", 40
  214.  
  215.     Lines 500 through 501 list the
  216. appropriate verbs understood by the
  217. adventure game. In this instance, the
  218. verbs are followed by the appropriate
  219. verb number. The verb number is
  220. important because you can assign
  221. multiple verb names to the same verb
  222. number. In the case of "get" and
  223. "take" verbs, this branches to the
  224. same routine simply because both verbs
  225. do essentially the same thing. Such a
  226. verb list would allow you to create an
  227. entire dictionary of verbs that are
  228. different words but do much the same
  229. action or actions.
  230.  
  231.     Lines 502 through 506 contain the
  232. noun list used by the adventure. Each
  233. name is again followed by a number.
  234. But this time each number isn't a noun
  235. number, as it was in the above verb
  236. list. No, this time we are actually
  237. listing the noun locations for each
  238. object. For example, the lantern is
  239. located in room number 17, the oil in
  240. room 5, and the torch in room 6. This
  241. may also relate to monsters throughout
  242. the adventure, as the "ogre" lives in
  243. room 23, and the "werewolf" in room
  244. 18.
  245.  
  246.     This simple data table is very
  247. limited, but it can be used as the
  248. starting basis for a more complex
  249. adventure. Also, remember that the
  250. player needs to be able to move about
  251. the adventure game. A data table for
  252. moving about the adventure would
  253. suffice as well.
  254.  
  255.     Such a data table might resemble
  256. the following:
  257.  
  258. 507 REM N, S, E, W, U, D
  259. 508 DATA0, 2, 0, 0, 4, 0:
  260.     REM Room 1 (Tavern)
  261.  
  262. 509 DATA1, 7, 3, 5, 0, 0:
  263.     REM Room 2 (Village Well)
  264.  
  265. 510 DATA0, 0, 0, 2, 0, 0:
  266.     REM Room 3 (Town Shop)
  267.  
  268. 511 DATA0, 1,10, 0, 0, 1:
  269.     REM Room 4 (Upstairs Hall)
  270.  
  271. 512 DATA0, 0, 2, 6, 0, 0:
  272.     REM Room 5 (Village Church)
  273.  
  274. 513 DATA0, 0, 5, 0, 0, 0:
  275.     REM Room 6 (Storage Room)
  276.  
  277. 514 DATA2, 8, 0, 0, 0, 0:
  278.     REM Room 7 (In the Forest)
  279.  
  280. 515 DATA7, 9,11,12, 0, 0:
  281.     REM Room 8 (By a Clearing)
  282.  
  283. 516 DATA8,13, 0, 0, 0, 0:
  284.     REM Room 9 (On a Bridge)
  285.  
  286. 517 DATA0, 0, 0, 4, 0, 0:
  287.     REM Room 10(Small Room)
  288.  
  289. 518 DATA0, 0, 0, 8, 0, 0:
  290.     REM Room 11(By the Lake)
  291.  
  292. 519 DATA0, 0, 8, 0, 0, 0:
  293.     REM Room 12(By a Boulder)
  294.  
  295. 520 DATA9, 0, 0,14, 0, 0:
  296.     REM Room 13(By the Castle)
  297.  
  298. 521 DATA0, 0,13,15, 0, 0:
  299.     REM Room 14(In the Hall)
  300.  
  301. 522 DATA16,0,14, 0, 0, 0:
  302.     REM Room 15(In the Parlor)
  303.  
  304. 523 DATA0,15, 0, 0, 0, 0:
  305.     REM Room 16(By the Throne)
  306.  
  307.     Line 507 is a REM statement that
  308. doesn't do anything remarkable. But
  309. what it does list is each cardinal
  310. direction the next DATA statement