DUNGEON OF DESPAIR by Donald Hughes from Sinclair User, June 1983 Putting the brains into monster heads Following our series on Basic programming Donald Hughes devises ways of building yourself a game with simple intelligence. HOW MANY TIMES have you wished you could write adventure programs? How many times have you started, only to cease an hour later, frustrated by the awful complexity? If the answer to the second question is too many times, you are probably approaching the problem from the wrong end. An adventure game should be split into two parts - the brain and the adventure. The brain is the interactive part of the program which communicates with the adventurer, answers queries, picks up items and drops them. The adventure can then be rendered into data suitable for the brain. The brain is a loop, normally large, which uses a READ statement to take data for the adventure from successive DATA statements. Normally the brain program will run its course once per adventure location, so when a location is left, it draws new data from the adventure. Using such a brain, each adventure location can be stored in one DATA statement of set format. You must start by deciding what initial intelligence the brain will have. I recommend you do not aim for anything more intelligent than the simple example. The example brain understands only one word at a time and they must be keywords. If the command given is not a keyword, the brain is so unreceptive that it proceeds merrily along as if it had found a keyword. It works, though, and you can write adventures, using the brain, in two hours. Starting with a brain similar to the example, you can add keywords slowly until it is reasonably intelligent, and you can have complex adventures, but start simply, or you will find yourself trying to debug a program which does not work far enough for you to find the bugs, let alone see what is not correct; and it will be back to the frustrations. Do not expect your first brain, or the example, to run adventures of a professional standard; that is not the aim - it is to let anyone starting on a Spectrum have fun with programs they thought were only in the realm of professionals. A simple brain operates in this way. The text of the first location is read in; the number of items in a room is read in; the items in the room are read into a string array, then printed-out along with a copy of the text; the monster in the room is read in, along with its strength. Logically, before the player ---------------------------------------- List of variables used in the program T$ = text rc = number of items in a room A$ = array of room contents M$ = monster name M = monster strength W$ = answer to fight/run option C$ = command word C = used in loops Z = used in loops S = your strength F$ = answer in fight routine Y$ = answer in take routine d$ = answer in drop routine e$ = exit direction ---------------------------------------- may take an item he must defeat the monster. Once the monster is dead, the brain asks what function is required. The functions understood are: Take - to pick up an item. Drop - to drop an item. Inve - produces an inventory. Leave - leaves the room. Those instructions, combined with an imaginative adventure, are sufficient to entertain. The brain then asks a question, depending on the keyword used. For example, What do you want to take? Type in, e.g. "sword". What do you wish to drop? Type in, e.g., "coin". If INVE was used, the brain prints out an inventory. When LEAVE is typed in, the brain asks in which direction. That is merely for show as, when a direction is typed in, it PRINTS "you are going to the next room"; PAUSES for a second; CLEARS the screen; and RESTARTS THE LOOP, reading in the next portion of DATA. One of the first improvements to the brain you should make is a way of flipping through the DATA to find any adventure location, so one can go N., S., E., W. The example brain suffices without that. In writing adventures, first examine the listing. The brain is obvious, lines 95 to 850. Remove the data statements, 1000 to 8000. Insert your own data, in this form: 1000 DATA "A",X,"B","B","B","M",S A is text describing the room; X is the number of items in the room and must be equal to the number of strings following it; B is a string, an item in the room; M is the name of the monster; S is the strength of the monster. Should you not want a monster, type in the DATA positions for M and S "none", 0. Try typing in the adventure below into your Spectrum and playing it to see the possibilities, within the limitations, of even a simple brain. You should have plenty of fun. After that, write your adventure for it. Real beginners should be very careful when typing in the adventure; a bug will make itself immediately and annoyingly apparent. To use the brain on a ZX-81, you will have to circumvent the "who needs READ statements" problem. Combat works this way; your strength is S; monster strength is M. In combat, this operation takes place LET S=S-(M*(RND+1)) which means a random figure varying between M and nearly M*2 is removed from your strength in defeating the monster. For different adventures, different Ss can be given, so only by choosing carefully what to fight can you win. ---------------------------------------- SCORE SHEET Due to the limitations of the brain, here is how to score your performance in this adventure: If you cheated with the priests, 0; if you took the heavenly being, 0; if you died, 0. You should have with you a sword, bag of coins, box of coins, ruby and Spectrum - the most valuable item. If you have all five, excellent; only four, good; only three, fair; only two, bad; only one - have you not played an adventure game previously? ----------------------------------------