------------------------------------------------------------"The Maze Run Game" from July, 1989------------------------------------------------------------ The dictionary defines a maze as "a network of intricatepaths, or a confused condition, or a mental perplexity."This month's DOWN TO BASIC program is a game called "MazeRun" which is based in part on all of those definitions ofmazes. It challenges you to navigate your way through amaze, collecting objects while you race against the clock.Although it does involve a bit of eye-hand coordination, itinvolves equal parts of coordination, logical thinking, andstrategy. The maze has been a part of human history for many thousandsof years. Although we usually think of mazes as a series ofsquiggly lines drawn on a piece of paper, they wereoriginally constructed using huge three-dimensionalpassageways. The intricate corridors which wound inside thepyramids of Egypt are an early example. Historians tell us that in ancient times, a maze was astructure composed of an intricate series of passageways andchambers; the "walls" which delineated the corridors weremade up of thick hedges or (better yet) stone walls. Mazeswere probably first designed to baffle enemies. Perhapsthose early maze designers reasoned that if they made it toofrustrating to find the throne room, the barbarian invadersmight just give up and go home. Mazes in History ---------------- Most labyrinth or maze designs had either branched pathswith misleading goals or one long circuitous path that ledto a central goal. One of the most powerful stories inGreek mythology deals with the half-man, half-bull minotaurdefending the center of a maze on the island of Crete. Manymedieval castles had elaborate mazes in their gardens usinghedges as dividers; they were as much for entertainment asthey were for visual beauty. Who will ever forget JackNicholson chasing Shelley Duvall through the frozen gardenmaze in the movie "The Shining"? I have always been fascinated with mazes. I guess everychild is first exposed to mazes in coloring and puzzlebooks. As a child, I vividly remember saving my allowanceso that I could buy a 29-cent book of puzzles. The book wasprinted on very coarse Grade-Z paper -- the same stuff theyused in Big Chief writing tablets. It was filled withpictures to color, dot-to-dot drawings to complete, andmazes to solve. I viewed every maze in the book as apersonal challenge, and would not rest until I had carefullytraced a path from every starting point to every "treasure"-- with as few false starts and dead ends as possible. As a teen-ager, I remember an afternoon TV game show called"The Money Maze". On that show, two married couples wouldcompete for the right to participate in the "bonus round".During that round, the husband would race like a rat througha large three-dimensional maze constructed on the floor ofthe TV studio, attempting to pick up hundred dollar billsscattered throughout the maze. At the same time, his wifewould stand on a platform far above the maze, screechinginstructions from her lofty vantage point. Although I lovedit, I believe the show was cancelled after a few weeks.Apparently, most people just did not recognize game showgenius when they saw it! How to Play ----------- This month's BASIC program is very similar to that old TVshow. To play the game, enter the program shown in theattached listing. (More detailed instructions on how toenter a BASIC program will follow). Once you have anerror-proof copy, type RUN and press ENTER. As you watch, ascreen-wide maze will be randomly constructed on the screen;the maze will be different every time you run the program.Once the maze is complete, each of the letters in the nameof the game -- Maze Run -- will be scattered throughout themaze. Your position in the maze will be represented with aninverse video "x"; you start the game in the center of thescreen. When you get the signal to go, you begin to move through themaze, using the arrow keys to steer your "x" marker. Youmust tap the arrow key once for each space on the screen.Some of you will want to tap the key repeatedly, whileothers will want to hold the key down and wait aboutone-half of a second for the automatic key repeat to kickin. The object of the game is to "run over" all sevenletters (M, A, Z, E, R, U, and N) in as little time aspossible. Your progress in finding all seven letters willbe shown on the top line of the screen. As soon as youcomplete the assignment, the program will display your score(the number of seconds it took you to finish). In all of mytesting, my best score was 59 seconds. Can you beat that? [Note: Those of you with the new enhanced keyboard -- andthat includes all SL and TL owners -- will use a differentset of keys for movement. There is a bug in either TandyBASIC or that keyboard which makes it impossible for BASICto detect the up arrow. On that keyboard, you will use HOMEto move up, DELETE to move left, END to move down, and PAGEDOWN to move right. Those four keys are located in acluster of six keys in the upper right hand portion of thekeyboard.] Before exiting, the program asks if you would like to solvethe same maze again. Can you do better given a secondchance? Or can your brother, sister, husband, or wifefinish in fewer seconds? Even if you do not want to solvethat same maze twice, you might want to try again with acompletely different maze. How It Works ------------ Lines 140 and 150 are used to initialize the screen and setup a few array variables. Lines 190 through 220 draw aborder around the edge of the 80-column screen. Notice theRANDOMIZE TIMER command in line 270; this command "seeds"BASIC's random number generator function with the number ofseconds which have elapsed since midnight (or since youturned on your computer if you do not have an internalclock). That seeding insures that you will get a slightlydifferent maze almost every time you run the program. Lines 260 through 490 actually construct the maze. Thetechnique used is an interesting one. Imagine you had arectangularly shaped back yard, with a number of evenlyspaced stakes all over the yard aligned in a north-south andeast-west direction. Pick any stake as your first one. Tiea string from your first stake to any of the foursurrounding stakes, but ONLY if that stake does not have anyother strings attached to it. Continue jumping in randomdirections from stake to stake until you reach a point wherethere are no more "empty" stakes. At that point, back up tothe previous stake and try again. If there are some emptystakes surrounding that one, follow the same procedure; ifnot, back up one more stake. If you follow this procedureto its logical conclusion (when you return all the way backto the first stake), then you will have a maze perfect forthis game -- with no dead ends and no sections which cannotbe reached. Lines 530 through 560 place the letters in the phrase "MazeRun" throughout the maze. Lines 570 through 590 prepare thetop line of the screen. Line 630 uses an interesting trick;the PCOPY 0,1 command transfers a complete copy of theexisting screen (referred to by the computer as screen #0)into a section of memory saved for screen #1. That savedcopy of the screen can be restored at any time with theopposite command -- PCOPY 1,0. Lines 630 and 640 alsoprepare the string variable K$; it contains the ASCII codesfor each of the four arrow keys. Lines 650 through 690 signal the player that the game isabout to begin. Variables X and Y contain the player'scurrent screen position; variables DX and DY contain thechanges in X and Y that will occur on the next move. Line730 clears the keyboard buffer, line 740 updates the screenclock, and line 750 ends the game if 1000 seconds haveelapsed. Lines 760 through 830 check the keyboard for movement, setvariables DX and DY, then check to see if movement in theintended direction is possible. Lines 870 and 880 areexecuted when a letter is encountered. The variable L isequal to seven initially (the number of letters in "MazeRun"); it is decremented each time a letter is "run over".The player's "x" marker is moved in lines 900 and 910. Once all seven letters have been found, lines 950 through1060 are executed, congratulating the player on his or herscore, offering the chance to repeat the same maze, andallowing the construction of a new maze. Subroutine 1100 isused several times in the main program to display a fiveline message, stored in array M$, in a window in the centerof the screen. Last Request ------------ I hope you will enjoy this simple game program. If you areparticularly ambitious, perhaps you can figure out how tomodify the program to save the "top ten" scores in a datafile. If you beat my score, be sure to write to ONETHOUSAND and brag about your expertise. Even if you do notbreak the "one minute" barrier, write with your comments,questions, and suggestions. If you would like a rapidresponse, be sure to include a self addressed stampedenvelope with your question. See you next month!