“You Are in a Maze…”

See all articles from SYNC v1 n6
Author(s): Gary McGath
Publication: SYNC
Pub Details: SYNC v1 n6 (Volume 1, Issue 6)
Date: November/December 1981
Pages: 41

“…of twisty little passages, all alike.” This message, in Adventure of Zork, tells you that you have embarked on one of the most challenging phases of the game: mapping the maze and finding your way out. Even without the rest of the dungeon, a maze can make an exciting puzzle in itself—especially if there is a hungry dragon wandering through the maze looking for you.

The “Maze” program runs on the minimal ZX80 with 1K RAM. Each room of the maze has three doors leading to other rooms, or to freedom. The rooms are numbered, and you know which room you are in by the number that is displayed on the screen. You start off in room 1, just as the dragon is coming in through the exit. If the dragon is in an adjacent room, you can hear it.

You move by entering a 1, 2, or 3 to pick one of the doors, or you can stay where you are by typing a zero. The dragon always moves after you. If you should meet the dragon, you become his dinner. To win, you must find an exit before the dragon finds you.

A couple of pointers: (1) Since the dragon moves after you, you may both walk into the same room without your having previously heard the dragon. Thus, you can get eaten without warning. (2) It is not cheating to study the maze generation part of the program for any peculiarities that might help you. For example, it turns out that lower numbered doors tend to lead to lower numbered rooms. (3) Collectors of programming tricks should note the use of the “computed GO TO” in statement 450, in which the next statement executed is determined by a random number. This capability is a feature of ZX80 Basic and does not exist on many other Basics.

May you always elude the dragon in your wanderings.

  5 RANDOMISE
10 DIM A(16)
20 DIM B(16)
30 DIM C(16)
40 FOR I = 1 TO 16
50 LET A(I) = 0
60 LET B(I) = 0
70 LET C(I) = 0
80 NEXT I
90 FOR I = 1 TO 16
100 IF A(I)>0 THEN GO TO 140
110 GOSUB 800
130 IF NOT N=I THEN
LET A(I)=N
140 IF B(I)>0 THEN GO TO 170
150 GOSUB 800
160 IF NOT N=I THEN
LET B(I)=N
170 IF C(I)>0 THEN GO TO 200
180 GOSUB 800
190 IF NOT N=I THEN LET
C(I)=N
200 NEXT I
300 LET U=1
315 LET Z=RND(15)+1
316 LET D=Z
320 CLS
330 PRINT U
350 IF NOT(D=A(U) OR D=B(U)
OR D=C(U))THEN GO TO 380
360 PRINT "YOU HEAR THE
DRAGON"
380 INPUT X
400 IF X=1 THEN LET U=A(U)
410 IF X=2 THEN LET U=B(U)
420 IF X=3 THEN LET U=C(U)
430 IF U=D THEN GO TO 600
440 IF U=Z THEN GO TO 700
450 GO TO 480+(20*RND(3))
500 LET D=A(D)
510 GO TO 550
520 LET D=B(D)
530 GO TO 550
540 LET D=C(D)
550 IF NOT U=D THEN GO TO 320
600 PRINT "THE DRAGON CAUGHT
YOU"
610 STOP
700 PRINT "YOU GOT AWAY"
710 STOP
800 LET N=RND(16)
810 IF A(N)=0 THEN GO TO 860
830 IF B(N)=0 THEN GO TO 890
840 IF C(N)=0 THEN GO TO 930
850 GO TO 800
860 LET A(N)=I
870 RETURN
890 LET B(N)=I
900 RETURN
930 LET C(N)=I
940 RETURN

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.