CONNECT-4
from Home Computing Weekly, 20th September 1983

It's your move - against the Spectrum.

Try to get a row of four before the computer does,
in David Haworth's game of strategy for any Spectrum.


My game is a relaxed alternative to the usual shoot-em-up computer games. No
fast reactions are required - all you need is logic. The game is played in a
seven by six array, and the first player to get four squares in a row -
either horizontally, vertically or diagonally - wins.

The computer has first move, to compensate for its inferior intelligence. Its
moves are printed as 0 and yours are printed as X. As you play, the
computer's skill level will reflect your own skill level in understanding the
logic of the game and translating it into computer logic.

Unfortunately, in the 16K Spectrum there wasn't enough memory for all the
logic I wanted to include. If you have the 48K version, there is plenty of
scope to extend the program between lines 2940 and 3950. In particular, I
would suggest logic to make the computer play a more attacking game, and
logic to stop the computer from making random moves which are advantageous to
its human opponent. You could also improve the graphics, colour and sound.

How it works

The game is played in an array a(m,n), where m denotes the column and n the row
number, counting from the bottom row. Each element in the array can have one of
three values: +1 (occupied by the computer); -1 (occupied by the human player);
and 0 (empty).
  A winning row of 4 in any direction will therefore total +4 if the computer
has won and -4 if the player has won. A total of +3 or -3 in any row of four
elements indicates a potential winning move by the computer and human
respectively.

  Block by block, this is how the program works:
   1-3     assigns values to the variables used in the program. These remain
           fixed values, used to avoid use of numbers in program lines.
   5-7     print column numbers on screen.
  10-70    direct the program through the various subroutines in the proper
           sequence.
1000-2940  subroutine to determine the computer's move, by calculating the sum
           of all combinations of four elements in a row within the array.
           If this is three, then a potential winning moves is indicated. If
           the vacant space is on the bottom row, the computer occupies it
           and wins.
           If on higher rows, it first checks to see if the space below is
           occupied to determine if a winning move is possible.
2000-2620  Checks to see if a blocking move is required. This is a similar
           routine to the one above, except that the check is for a total
           of -3 in any row of four.
2700-2940  If no winning or blocking move has been found, the program proceeds
           to here, which will complete any line of two moves, for either
           computer or human, in the horizontal or vertical directions.
3950-3980  If no directed move is found, the program jumps here to make a
           random move for the computer.
5000-5270  subroutine to check if the game has been won.
6000-6120  subroutine to get player's move (print eight spaces in line 6070).
8000-8100  sets up array and draws frame. Note: CODE "FN" = 168, CODE "'" = 39,
           CODE "CAT" = 207.
9000-9120  end of game.


Variables
a   1
b   2 and so on until ...
g   7
z   0
k   7000
l   9000
p   9100
v   60 (note CODE "('less than' sign)" = 60


Hints on conversion
The program is written in simple BASIC with a minimum of graphics, so
conversion to other computers should be straightforward.



