★ AMSTRAD CPC ★ GAMESLIST ★ FOUR IN A ROW (c) COMPUTING WITH THE AMSTRAD ★ |
Computing with the Amstrad |
DUDLEY BROOKE adapts Connect 4 FOUR in a row is a computer adaptation of the well known game Connect 4. You can play either a human opponent or the computer. If you prefer you can even sit back and watch the computer compete against itself. To get started just follow the onscreen prompts to identify the players. Once into the game all you need to do to place a counter is select a column by positioning the arrow using the cursor keys, then press Copy to confirm your choice. Lines 1490-2370 contain the algorithm for choosing the computer's move, and it can be a ruthless opponent. The routine only changes one major variable col, so it would be fairly easy for anyone wishing to write their own algorithm to implement it within the framework of the rest of the program. The “check against arrays” routine (lines 1950-2130) searches the arrays for an offered string tst$. If a match is found it returns with col set to the appropriate column in which to drop the counter. The program has been designed for speed, and the computer will not take more than 10 seconds to arrive at a decision. To achieve this the position of each counter is stored four times in four string arrays and these correspond to the four directions in which a winning line may be made-either in a column, a row or diagonally. This allows the speed of the INSTR command to be used to search for a match. In general, single letter variables are not passed to other routines, the notable exception being p which is either 1 or -1 and identifies the current player. The program is quite complex, especially the routines which handle the selection of the computer's move, and particularly the arithmetic expressions which access the strings storing the game position. Any typing errors with these could be quite difficult to debug, but given this little clue and the checksums, you have some advantage. CWTA |
|
|