PROBE (16K ZX-81)
from Your Computer (December 1982), page 52-53

The object of this game is to fit seven keys in seven locks in as few goes as
possible. How good a cracksman are you?

Probe is a game program for the ZX-81 with 16K RAM that requires equal
measures of luck and skill for it to be completed in the minimum number of
moves. The essence of the game is to fit seven keys, which are all different,
into the correct locks in the minimum number of moves.

The game is original, and was first developed as a board game to rival the
popular game of Mastermind. In its original form the keys consisted of a
combination of pins mounted on a shaft, which were tried at various positions
on the board to penetrate the locks which consisted of plates with holes in
designed to fit specific keys. Its advantage over Mastermind is its
self-scoring ability, that is, a passive opponent is not required to report
the success or failure of each move.

A second version of the board game was also devised so that a second player
could actively participate. This version had locks on the opponent's side of
the board that were the reciprocal of the player's own locks. Unfortunately
the screen size on the ZX-81 is too small for this second version of the game.

YC8212w212052Probe-Fig#1.gif

The basis of ZX-81 Probe is that a key with up to three pins on it, can have
a possible seven combinations. If we have seven keys we only need seven locks
to complete the elements of a board game. If it is imagined that the keys are
pins and that the locks are holes, it will be seen that most keys will fit
into more than one lock, as shown in Figure 2:

YC8212w212052Probe-Fig#2.gif

However, if all the keys are to be fitted, the correct key must be found for
each lock.

The object of the game, therefore, is to fit each key into its correct lock.
The game is initially set up on the screen like this. First, the keys are set
out in sequence along the bottom of the screen and each one is numbered from
1 to 7. Next, the locks are shuffled by the computer, laid out across the
centre of the screen, and then covered by a grid or shield so that the player
cannot see the sequence. The beginner's game leaves the shield off.

A prompt  K?  appears at the bottom left-hand corner of the screen, asking
for the number of the key to be played. This is followed by a prompt asking
which lock the key is to be tried in  L?. If the key fits  and remember it
need not necessarily be the correct fit  the display will change as shown
in Figure 3:

YC8212w212052Probe-Fig#3.gif

Key 1 is shown above lock 2 which is blanked off to show that a key has been
fitted. If a key does not fit, the key stays put.

Several moves later you may conceivably get to the stage where, say, key 2
has been fitted into lock 1 and key 3 into lock 6. Key 4 has failed to fit in
any of the remaining unoccupied locks.

To find a home for key 4 it is necessary to move one of the other keys which
must be occupying key 4'S proper lock. The best chance of fitting key 4 is to
try locks 1 or 6. Let us therefore try it in lock 1. To do this we must first
move key 2 somewhere else, say lock 7. Therefore input:

   K? 2 L? 7

This fits and therefore leaves lock 1 free to try key 4 in it. Therefore input:

   K? 4 L? 1

The game continues in this manner until all seven keys have been housed. When
this point is reached your score is printed at the top of screen; the lower
score the better.

You cannot place a key into a lock that is already occupied. Keys always
retain the number they are given at the start of the game, they do not adopt
the number of the lock they are fitted into.

A key must always have a home either at the bottom of the board or in the
board, it cannot be pulled out of a lock and left out, it must find a new
lock to fit into before vacating its current position.

As for the program itself, lines 20 to 160 put the key, mask and lock shapes
into their respective strings.
Lines 170 to 190 allocate a position to each of the locks before they are
shuffled by lines 200 to 250 into a random sequence. After shuffling they are
sent off for the printing of the board, and all the keys, locks and key
numbers.

Line 253 jumps the printing of the screen over the locks if the beginner's
game is being played. Lines 500 to 520 ask you to enter the number of the key
to be moved and the number of the lock it is to be tried in. Line 525 stops
you trying to fit a key into a lock that is already occupied.

Lines 530 to 590 arc a logic gate and judge the compatibility of key and
lock. If they are compatible then you jump to line 620. Lines 600 and 610 are
used, if the key and lock are not compatible in which case a counter K(H) is
incremented by two so that the not-fit marker is printed in the correct
position.

Line 620 increments the fit marker for printing. Line 630 checks the flag
F(P) to see if the key P has previously been fitted. If it has, a different
print routine has to be used. Line 640 sets the variable L(P) equal to the
board position for key P.

Line 650 sets the flag F(P) equal to 1 for key P showing that from now on
that key is in play. Lines 1010 to 1050 print the locks, keys and key
numbers. Lines 1100 to 1125 are used when a key has been fitted. Line 1105
prints a solid blank over the lock to show that it is now occupied.

Line 1110 prints the key over the lock using counter C(H). Lines 1120 and
1125 print a mask in place of the key that was at the bottom of the board.
Line 1130 sends off for checking to see if all the keys have been fitted.

Lines 1200 to 1220 are used when a key was tried and failed to fit, in this
case line 1210 prints a copy of the key below the locks to show that it was
tried and failed. Lines 1300 to 1337 are used when a key is moved and fits
into another lock on the board. Line 1310 prints a screen over the vacated
lock to show that it is now empty.

Line 1320 prints the key above the new lock. Line 1330 prints a solid blank
over the new lock to show that it is occupied. Line 1335 sets the variable
P(L(P)) to 0 indicating that no key is fitted in that location.

Line 1337 sets the variable L(P) to the value of key P. Line 1500 to 1515
tests to see if all the locks are occupied. Line 1502 is used to update P(H)
with its new key. Lines 1505 to 1515 checks each lock in turn.

Lines 1517 onwards count the number of goes taken by adding up the counters
C() and K() and dividing by two. Remember the counters are increased by two
each time.


VARIABLES USED

C(H)	A counter used to locate the printing of copies of the key above the
	lock when it has fitted.
K(H)	A counter used to locate the printing of copies of the key below the
	lock when it was tried and failed to fit.
F(P)	Flag to indicate whether a particular key P has been placed on the board.
H(H)	The number of the lock in position H.
P(H)	The number of the key in position H.
L(P)	The last location of key P.
H	The lock position.
P	The key position.