Amazing program from BASIC Computer Games

The maze program is one of the games in the famous 101 BASIC Computer Games published in 1978. In the book it is called 'Amazing' and the code available in Vintage BASIC. I have rewritten it in COMAL-80 for the Commodore 64 and cleaned it up.

COMAL-80 edition

0010 DIM visited(25,25)
0020 DIM cells(25,25)
0030 DIM d(10)
0040 
0050 // Constants
0060 no_floor:=%00000001
0070 no_right_wall:=%00000010
0080 
0090 LOOP 
0100   PRINT "WHAT ARE YOUR LENGTH AND WIDTH"
0110   INPUT rows,cols
0120   EXIT WHEN rows>1 AND rows<=25 AND cols>1 AND cols<=25
0130   PRINT "MEANINGLESS DIMENSIONS. TRY AGAIN"
0140 ENDLOOP 
0150 totcells:=rows*cols
0160 FOR q:=1 TO rows DO
0170   FOR z:=1 TO cols DO
0180     visited(q,z):=FALSE
0190     cells(q,z):=0
0200   ENDFOR z
0210 ENDFOR q
0220 bottom:=FALSE
0230 entry:=RND(1,cols)
0240 PRINT 
0250 // Print top
0260 FOR c:=1 TO cols DO
0270   IF c=entry THEN
0280     PRINT ".  ",
0290   ELSE 
0300     PRINT ".--",
0310   ENDIF 
0320 ENDFOR c
0330 PRINT "."
0340 r:=1
0350 c:=entry
0360 cellinx:=1
0370 visited(r,c):=TRUE
0380 REPEAT 
0390 l580:
0400   dx:=0
0410   IF c<>1 THEN
0420     IF visited(r,c-1)=FALSE THEN
0430       dx:=dx+1
0440       d(dx):=1
0450     ENDIF 
0460   ENDIF 
0470   IF c<>cols THEN
0480     IF visited(r,c+1)=TRUE THEN
0490       GOTO l750
0500     ENDIF 
0510     dx:=dx+1
0520     d(dx):=2
0530   ENDIF 
0540   IF r>1 THEN
0550     IF visited(r-1,c)=FALSE THEN
0560       dx:=dx+1
0570       d(dx):=3
0580     ENDIF 
0590   ENDIF 
0600 l750:
0610   IF r<rows THEN
0620     IF visited(r+1,c)=TRUE THEN
0630       GOTO l820
0640     ENDIF 
0650   ELSE 
0660     IF bottom=TRUE THEN
0670       GOTO l820
0680     ENDIF 
0690   ENDIF 
0700   dx:=dx+1
0710   d(dx):=4
0720 l820:
0730   IF dx=0 THEN
0740     findvisited
0750     GOTO l580
0760   ENDIF 
0770   x:=RND(1,dx)
0780   IF d(x)=4 THEN
0790     cells(r,c):=cells(r,c) BITOR no_floor
0800     r:=r+1
0810     IF r>rows THEN
0820       bottom:=TRUE
0830       r:=1
0840       c:=0
0850       findvisited
0860       GOTO l580
0870     ENDIF 
0880   ENDIF 
0890   IF d(x)=3 THEN
0900     r:=r-1
0910     cells(r,c):=no_floor
0920   ENDIF 
0930   IF d(x)=2 THEN
0940     cells(r,c):=cells(r,c) BITOR no_right_wall
0950     c:=c+1
0960   ENDIF 
0970   IF d(x)=1 THEN
0980     c:=c-1
0990     cells(r,c):=no_right_wall
1000   ENDIF 
1010   cellinx:=cellinx+1
1020   visited(r,c):=TRUE
1030 UNTIL cellinx>=totcells
1040 // Print maze
1050 FOR r:=1 TO rows DO
1060   PRINT "!",
1070   FOR c:=1 TO cols DO
1080     IF cells(r,c) BITAND no_right_wall=0 THEN
1090       PRINT "  !",
1100     ELSE 
1110       PRINT "   ",
1120     ENDIF 
1130   ENDFOR c
1140   PRINT 
1150   FOR c:=1 TO cols DO
1160     IF cells(r,c) BITAND no_floor=0 THEN
1170       PRINT ":--",
1180     ELSE 
1190       PRINT ":  ",
1200     ENDIF 
1210   ENDFOR c
1220   PRINT ":"
1230 ENDFOR r
1240 END 
1250 
1260 PROC findvisited 
1270   REPEAT 
1280     c:=c+1
1290     IF c>cols THEN
1300       r:=r+1
1310       IF r>rows THEN
1320         r:=1
1330       ENDIF 
1340       c:=1
1350     ENDIF 
1360   UNTIL visited(r,c)=TRUE
1370 ENDPROC findvisited



Sidst opdateret: 2018/09/18
Website vedligeholdt af Søren Roug