AMAZING MAZE
from Home Computing Weekly, 26th April 1983

Get lost, easily, in the Amazing Maze

Suddenly you're landed in the middle of a maze ... but there's a
three-dimensional view to help you find your way out.
Matthew Taylor wrote his game for the 16K Spectrum.


It's very easy to get lost - especially on the harder options - in my Amazing
Maze program, for the l6K Spectrum. The program generates a random maze and
throws you into a random position right in the middle. A three-dimensional
picture is then drawn of what you can see, lost there in the middle of the
maze. You can move forward, turn left or right, ask for help or quit. Your
task is to find the exit (which is always in the top left hand corner) and
escape ...

First the program prints a list of options and asks you to choose one. You
are then asked if you want to know in which direction you are facing (shown
by an arrow underneath the word DIRECTION in the main maze display). This
seemingly futile indicator can be very useful.

After the maze has been generated, which takes about 30 seconds, the three
dimensional view is drawn, and the message, "F,L,R,Q or H?" is printed at the
bottom of the screen. You must type in your command and then press ENTER. The
commands are:
	F moves you one step forward
	L turns you to the left
	R turns you to the right
	Q quit. Hard luck, your score won't count for the high score!
	H help. Prints the map, which clears itself after 10 seconds,
            and 10 moves are added to your score.

The number of moves you have taken so far is displayed in the top right hand
corner of the screen and the best number of moves below it. These are the
number of actual steps you take, so this is a game of strategy not a real
time game. When you have escaped, or quit - shameful person - the list of
options is printed again. Now you can have another go with the same or a
different option or input "q" to quit.

The program fits into 16K, but only just, which explains the absence of REM
statements and the long multi-statement lines. There should be no problems
encountered when typing in the program as long as you do not add anything if
you are using a 16K Spectrum: just type in the program and SAVE it with
SAVE "MAZE" LINE 5. Just in case, here is an explanation of some of the lines:
	  20 There are 10 spaces inside the quotes
	6000 There are 9 spaces inside the quotes
	6030 There are 22 spaces inside the quotes

If you have a 48K Spectrum you might like to add some features which I would
have liked to add, but didn't have the memory, like monsters, treasure, an
oaken door and an axe to break it down, different levels, stairs ...


How it works

   5       sets high score to zero
  10-70    options set up screen
 100-116   set up screen
 120-196   set up variables for maze generation
 200-230   realises options
 240-280   generate "arrow"
 285-390   set up variable for play
 395       re-initialises variables for graphics each turn
 396       prints direction arrow if required
 397       traces route if required
 400-500   draw graphic display
 505-506   update moves
 510-560   INPUT, process and act on commands, error checking
 570       clears graphic display
5000-5100  print map of maze (see Hints on Conversion)
6000-6010  clear map area
6020-6050  clear graphic display
7000-7020  check forward move is valid and check for escape
9000-9110  opening display, INPUT options
9800-9940  finishing messages, update high score


Main variables

option      option
moves       number of moves taken so far
best        high score
arrow       1 if direction arrow is required
x,y         position in the maze, both during random generation and play
m(21,21)    maze
d           direction: 1 up, 2 right, 3 down, 4 left
x(4),y(4)   table of displacements using above
d(7)        table of distances used in drawing graphic view
e(4),f(4)   table of displacements to find square in m(21,21) to right
g(4),h(4)   as above but for left
x1-4,y1-4   positions of four corners when drawing graphic display
c           character number (CODE =c+128) of graphic to be printed when
            printing map (see Figure 1 and Hints on Conversion)


Hints on conversion

PLOT OVER 1; means "invert point" but is used as "unplot" in my program.

The graphic resolution on a Spectrum is 256x176. The square area for the
three dimensional display uses 0-175 in both X and Y directions.

DRAW X,Y means draw from current position to a position X,Y away; ie. X,Y are
relative displacements rather than absolute co-ordinates.

INPUT always uses the bottom line. You will have to be careful where you put
your INPUTs on the screen.

INPUT "..."; LINE a$ is no different to INPUT "...";a$ on other computers. The
LINE just prevents the Spectrum printing annoying quotes around your INPUT.

a$(1) means the first character in a$; ie. LEFT$(a$,1).

PRINT ' means print down a line as in ATOM BASIC.

Lines 5010 to 5060 print the maze in double resolution - four maze locations
to a character square. Therefore, the character to be printed has to be
calculated. This is quite easy on a Spectrum because Uncle Clive has
conveniently ordered the graphic characters in the Spectrum character set.

Figure 1

	 --- ---
	| 2 | 1 |
	 --- ---
	| 8 | 4 |
	 --- ---

Consider each character square divided into four smaller squares, each
smaller square numbered as in Figure 1. To find the code of the character
required, all that is needed is to add up the numbers in the small squares
which are to be printed and add 128 (code for a graphic space).
(For example, to find the code of:
	 --- ---
	| * | * |
	 --- ---
	| * |   |
	 --- ---
CODE=(1+2+8)+128=139 (check this on Figure 1).
If these characters are not so conveniently ordered on your computer then you
will probably need to set up a string array of these 16 characters.
