ATOMS (16K ZX81)
by B G Cornhill, Aylesbury, Buckinghamshire
from Your Computer (March 1982), Pages 67-69

This is a 5.7K program for playing the game Molecules on your expanded
ZX-81. The computer constructs a molecule from one to seven atoms in size
and you have to guess its shape. You do this by shining imaginary rays of
light and then trying to calculate the positions of the atoms from the
deflection recorded.

A ray of light striking an atom straight on is totally absorbed and
produces a black square at point of entry. Reflected rays are turned
through 90 degrees when they strike an atom a glancing blow. A ray entered
at 28 was turned left at the first atom it encountered, then left twice
more causing it to U-turn, then turned again by 90 degrees to exit at the
same place it entered.

A ray that glances an atom immediately on entry is reflected straight out
and marked by an inverse-video 0. Entering P allows you to plot guesses, or
alter any guesses you have made. When you have had enough, enter F. The
computer will then display the actual location.

To allow conversion to other machines, here are the program lines and their
various CHR$.

Lines 10 to 77 display the instructions on the screen.
Lines 80 to 330 draw the grid with all the numbers intact, and a blank grid.
Line 340 initialises the array used to hold the grid information. It is
  larger in size than required purely to facilitate the grid search and
  screen printing. The first figures are for the line, 0 at the top; the
  second figures are for the columns, 0 on the left.
Lines 350 to 370 ask for the number of atoms  one to seven. Seven seems to
  be enough, but this can be increased.
Lines 380 to 420 randomly locate the atoms to the array.
Line 430 is the starting point and re-entry point of the rest of the
  program. It is here you are asked the entry point. You enter your choice of
  1-8, 9-16, 17-24, 25-32.
Lines 1330 to 1400 is the routine for entering your guesses or editing your
  guesses.
Lines 1400 to 1480 is the end routine which displays the shape.
Lines 450 to 510 calculate which side you are entering from and send you to
  the correct routine.
Line 520 is an error check.
Lines 540 to 620 contain the routine for the light moving down the array
  and check ahead for either total absorption, deflection or passing straight
  through.
Line 640 exits if you are deflected to the right.
Line 670 exits if you are deflected to the left.
Lines 671 to 860 contain the routine which checks from left to right.
Lines 870 to 1090 is the routine which checks from bottom to top.
Lines 1100 to 1320 is the routine which checks from right to left.

Each of the direction routines must cater for entry part of the way into
the routine and for leaving it before it is finished. Hence, the absence of
Gosubs: they could confuse the return statements. For example, entry at 28
used the left-to-right routine, then bottom to top, then right to left,
then top to bottom, then right to left leaving at the entry point totally
deflected.

The use of the Q numbers is to allow the computer to place the correct
graphic symbol at the entry point and exit point. When you have entered the
program, line 1490 must be entered initially with the normal S command for
the word atoms. When you are ready to record, enter Run 1490 and it will
always start automatically on loading.

[There is an error in the magazine listing in line 990 which shows GOTO 10
but should be GOTO 1070. PF]
