SNAKE TRAP
by Peter Cooke
from ZX Computing Jun/Jul 1984


Don't get hissterical over this chase game from Pete Cooke in Leicester!

In this program, your snake (the grey squares) has to try and trap the
computer's snake (inverse 'c's). You can move using the arrowed keys 5 to 8.

The squares occupied by the snakes are contained in two 1 dimensional arrays,
A(50) and B(10). For the player's snake, two pointers, AA and AB, move by
POKEing in the new head at A(AA) and wiping out the tail at A(AB). Changing
(AA-AB) lengthens or shortens the snake.

As the computer's snake is always ten squares long, it only needs one pointer,
BB moving through the array. The old value of B(BB) is overwritten and the new
value replaces it.


Line by line

Here follows a breakdown of the program which should help you understand the
listing a little better:

90-660       Forms the game loop. The player's move is input
             and the computer line 150 checks that it is to an
             empty square. Line 130 allows for the player's
             snake finding food. Lines 300-550 check for
             the computer's snake. If the next square is a
             wall then it is either right or left at random.
1000-2050    Shows who has won the game and reruns the
             program for another game.
5000-6990    Sets up the variables and gives instructions.
7000-7200    Sets up the board.


Variables

A(50)         Positions of player's snake.
B(10)         Positions of the computer's snake.
AA,AB,BB      Pointers in the arrays.
P(4)          Codes for the four directions N, S, E and W.