High Speed Mazer
Gary E. Marsa
This update of previously published "Maze Generator" uses machine language to construct a random maze in less than two seconds – for PET, VIC, and 64. Also, there's "Munchmaze," a fast-action strategy game to show off the maze utility, with versions for the PET and 64.
If you tried Charles Bond's "Maze Generator" in the December 1981 COMPUTE!, you'll remember how fascinating it was to watch the maze being constructed on the screen right before your eyes. It's a clever program and lacks only one thing – speed. It takes my PET about 38 seconds to construct a full-screen maze. After watching it make several mazes, it occurred to me that a machine language version would be much faster.
The machine language maze generator was written on an Upgrade PET, and conversions for Original ROMs and 4.0 ROMs were incorporated into the loader program (Program 1). Also included are versions for the VIC-20 (Program 2) and the 64 (Program 3).
The PET version uses 176 bytes and will fit into one of the cassette buffers. It uses the second cassette buffer, but 4.0 BASIC users may prefer to use the first cassette buffer. If so, change the value of S in line 120 to 634. If you would like to use one or both buffers for utility programs, instructions for loading machine language into high RAM are given at the end of the loader (lines 450 on).
The VIC-20 version occupies 201 bytes and must be loaded into high memory because it's too large for the cassette buffer. The extra bytes in this version are needed to handle color. Screen and border are both white, and the maze color is chosen randomly. All colors except black and white are used.
While typing in the loader program, make special note of DATA items beginning with an asterisk (*) or a plus sign (+). Be sure to include these symbols. When you've finished typing, be sure to SAVE the program before RUNning it. When the program is RUN, it first POKEs the machine language into memory and then offers a demonstration. Mazes will be constructed on your screen as long as you keep pressing keys.
Speeding Up The Maze
Converting Charles Bond's algorithm from BASIC to machine language was accomplished by a nearly line-by-line translation of the original BASIC program. Although the machine language program executes far faster than the original BASIC program, the maze does not appear on the screen instantaneously. But the motion is so fast it's hard to follow with your eyes. I timed the PET maze construction at 1.65 seconds. The VIC and 64 versions take about half as much time.
The mazes are 39 columns by 23 rows on the PET and 64, and 21 columns by 21 rows on the VIC. These are maximum sizes. Changing the maze dimensions is possible, but not particularly easy, especially if you want to center the maze on the screen. You can try this:
PET & 64 : POKE S + 37,C (where C is > 10 or <40) POKE S + 53,R (where R is > 10 or <24) VIC: POKE S + 62,C (where C is > 10 or <22) POKE S + 78,R (where R is > 10 or <22)
C is the number of columns, R the number of rows, and S the SYS address minus eight. C and R must be odd numbers. Mazes smaller than the maximum size will not be centered, but will start in the upper-left-hand corner of the screen.
Shortly after converting the maze generator to machine language, I wrote a machine language game called "Munchmaze," in which a character hurries through the maze dropping bread crumbs as it goes. You move your character around with the appropriate keys and try to munch as many of the bread crumbs as you can before the character catches you. The game ends when the two characters collide or when you accumulate 10,000 points.
There are three speed levels: slow, moderate, and fast. Both characters move at the same speed, but the computer character beats you on the corners. Also, you have to change directions manually; it doesn't. The computer moves its character according to the same "left-turn rule" used by the mouse in Charles Bond's original maze generator program. You must be aware of this in order to find temporary hiding places.
There's another tricky feature, too. Sometimes, when the two characters are moving from opposite directions toward each other, the computer character goes right on by and no collision occurs. Just breathe a sigh of relief and continue munching – you were lucky.
The maze in Munchmaze is not constructed on the screen, but in another area of RAM. It is then transferred to the screen, where the maze appears all at once; then there is a one-second delay before the action begins. If you break out of the program for any reason just type SYS 12311 to restart.
Programs 4 and 5 are versions of Munchmaze for 4.0 and Upgrade PETs, respectively. Program 6 is a 64 version of Munchmaze.
Special Note To 8032 And Fat Forty Owners
Because of keyboard differences between "old style" 40-column PETs and "Fat Forties," Munchmaze will not work properly on Fat Forties, or 8032s. Your machine is a "Fat Forty" if a bell rings when you turn it on.
Munchmaze 4.0 will work properly on these computers if you type in these two lines instead of the ones that appear in the listings:
13314 DATA 255, 255, 255, 40, 0, 182 13320 DATA 184, 180, 178, 160, 32, 58
A game of "Munchmaze" being played on the 64.