Quatro
- Type
- Game
- Category
- Four-in-a-row strategy game
- Author
- Jeremy Birn
- Published in
- Antic, February 1987 (Vol. 5, No. 10), Game of the Month
- Year
- 1987
- Language
- Atari BASIC (with a machine-language DLI)
- Requirements
- Any Atari 8-bit computer, any memory size, Atari BASIC, one or two joysticks; disk or cassette
About the program
Quatro is four-in-a-row, the game Antic called "Blind Man's Morris or 'Connect-4'", laid on its side. Instead of dropping counters down columns, you choose one of six horizontal tracks, and your square slides to the rightmost empty space in it. The first player to line up four squares horizontally, vertically or diagonally wins. It was the February 1987 Game of the Month and the first published program by Jeremy Birn, a student from Delmar, New York. The magazine called the computer opponent "truly formidable".
Typing it in
The listing is plain Atari BASIC, but the magazine gave special instructions. Quatro "will not RUN properly if the lines weren't typed perfectly and in the proper order", because of the way Atari BASIC builds its variable name table as you type. Fixing typos can leave old, unused names behind. So once your copy is correct and SAVEd: remove TYPO II, LIST the program to disk or cassette, type NEW, ENTER it back and SAVE it again. That rebuilds a clean variable table. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program.
How to play
While the title shows, the six coloured tracks are drawn. The two text lines at the bottom, Black (player 1) and White (player 2), set who plays each side. Move the stick up and down to choose a line, and left and right to choose Stick 1, Stick 2, Computer or Random. Two joysticks, one joystick shared, you against the Atari, or the Atari against itself are all possible. Press the trigger or START to begin.
On a joystick turn, move the flashing yellow stripe to a track and press the trigger. Hold SELECT to abandon a game. If all six tracks fill up with no line of four, it's a draw. To beat the computer, Birn suggested setting up two winning threats at once (it can only block one), or a threat where a block opens up a winning square just to its left. Watching Computer against Random, or Random against Random, teaches you the patterns.
How it works
The screen is GRAPHICS 7 with an altered display list. A display list interrupt on every line reads its colours from a lookup table starting at the address in the variable SET. A plain POKE SET+Y,COLOR therefore changes the background colour of row Y alone, which is how the program draws the striped tracks and highlights whose turn it is. The DLI lives in the low part of page 6 and is set up by the self-contained subroutine at lines 30000–31000. Birn offered it to other programmers: GOSUB 30000, then POKE the colours you want into the table. You can also redirect it to other colour registers (codes 18–21 for the player colours, 22–26 for playfield registers 0–4). He pointed out that this one routine replaces a whole chain of hand-written DLIs.
The computer player looks at every legal move, scoring each one for the advantage it gives and for any threat it hands to the opponent. It plays its first move at random.
Listing
2 REM QUATRO
4 REM BY JEREMY BIRN
6 REM (c) 1987, ANTIC PUBLISHING
10 GRAPHICS 7:POKE 708,0:POKE 709,0:POKE 710,0:A1=9
20 DIM D(3,1),B(9,7),P(1),H(6),P$(42)
30 DL=PEEK(560)+PEEK(561)*256:POKE DL+85,71:POKE DL+88,12
40 ? " QUATRO":POKE 752,1:? " BY JEREMY BIRN"
50 ? " ANTIC MAGAZINE '87"
60 GOSUB 30000:REM CALL UDLI
65 POKE 708,14:POKE 709,0:POKE 710,190
70 POKE CA,26:POKE CB,26
80 POKE SET+82,190:POKE SET+83,190
90 RESTORE
100 FOR T=1 TO 6:FOR Y=0 TO 5:X=T*16+Y*2+50:POKE SET+T*13+Y-5,X
110 POKE SET+T*13-Y-6,X:NEXT Y:NEXT T
120 FOR T=0 TO 3:READ X,Y:D(T,0)=X:D(T,1)=Y:NEXT T:DATA 1,1,0,1,-1,1,-1,0
130 P$=" RANDOM STICK 1 STICK 2COMPUTERBLACKWHITE":P(0)=2:P(1)=4
140 ? #6;CHR$(125):? CHR$(125);:POKE SET+82,0:POKE SET+83,0:POKE DL+85,198
150 POKE DL+88,134:POKE DL+89,144:POKE DL+90,130:POKE SET+83,190:POKE 77,0
160 GOSUB 490:X=P(0)*8:? " BLACK: ";P$(X-7,X);" WHITE: ";:X=P(1)*8
170 ? P$(X-7,X):? "ADJUST WITH JOYSTICK: TRIGGER TO START":? CHR$(29);
180 POKE SET+81-A,0:POKE SET+A+80,164
190 K=STICK(0):P=PEEK(53279):IF NOT STRIG(0) OR P=6 THEN 230
200 IF K=13 OR K=14 OR P=5 THEN GOSUB 490:A= NOT A:GOTO 180
210 IF K<14 OR P=3 THEN K=P(A):K=K+1:K=K-4*(K=5):P(A)=K:GOTO 160
220 GOTO 190
230 POKE SET+A+80,0:? CHR$(29);CHR$(156);:FOR Y=1 TO 6:H(Y)=8:NEXT Y:N=1
240 POKE DL+90,140:POKE SET+83,0:POKE DL+89,135:POKE SET+82,178
250 A=PEEK(53770)>127:FOR X=0 TO 9:FOR Y=0 TO 7:B(X,Y)=0:NEXT Y:NEXT X
260 ? :? CHR$(28);:GOSUB 680:IF N=49 THEN ? " A TIE GAME!!!":GOTO 540
270 POKE SET+80+A,164:? N;". ";P$(33+5*A,37+5*A);" TURN.";
280 B=P(A)-2:T=0:ON P(A) GOSUB 350,410,410,560
290 X=H(T):H(T)=X-1:COLOR 2-A:FOR D=X*20-16 TO X*20-1:PLOT D,T*13-10
300 DRAWTO D,T*13-1:NEXT D:Y=T:B(X,Y)=A+1
310 FOR D=0 TO 3:GOSUB 360:IF R<3 THEN NEXT D:GOTO 330
320 FOR T=1 TO 5:? CHR$(30);:NEXT T:? "WINS!!!";:T=0:R=T:COLOR 3:GOTO 500
330 POKE SET+80+A,0:A= NOT A:N=N+1:GOTO 260
340 T=INT(6*RND(1))+1:IF H(T) THEN RETURN
350 POKE 53279,4:GOTO 340
360 T=1:R=0
370 IF B(X+T*D(D,0),Y+T*D(D,1))=A+1 THEN T=T+1:R=R+1:GOTO 370
380 T=-1
390 IF B(X+T*D(D,0),Y+T*D(D,1))=A+1 THEN T=T-1:R=R+1:GOTO 390
400 RETURN
410 T=T+1:IF NOT H(T) THEN 410
420 R=SET+T*13-6:BN=PEEK(R):X=4:D=1
430 X=X+1:IF X=5 THEN POKE R,255*D:POKE R+1,255*D:X=0:D= NOT D
440 IF PEEK(53279)=5 THEN POP :POKE R,BN:POKE R+1,BN:GOTO 140
450 POKE 77,0:K=STICK(B):IF STRIG(B) AND K=15 THEN 430
460 POKE R,BN:POKE R+1,BN:K=(K=14):K=K*2-1:IF NOT STRIG(B) THEN RETURN
470 T=T-K:T=T+6*( NOT T):T=T-6*(T=7):IF NOT H(T) THEN 470
480 GOTO 420
490 FOR C=15 TO 0 STEP -1:SOUND 0,121,10,C:NEXT C:RETURN
500 POKE 710,15* NOT A:FOR BN=-1 TO 1 STEP 2:T=(BN=1)
510 B=X+T*D(D,0):K=Y+T*D(D,1):IF B(B,K)<>A+1 THEN NEXT BN:GOTO 540
520 T=T+BN:FOR N=B*20-13 TO B*20-4:PLOT N,K*13-8:DRAWTO N,K*13-3:NEXT N
530 GOSUB 490:GOTO 510
540 POKE 77,0:IF STRIG(0) AND PEEK(53279)=7 THEN POKE 710,PEEK(20):GOTO 540
550 POKE 710,190:GOTO 140
560 B=0:BN=-10^11:P=B:IF N<3 THEN 350
570 GOSUB 680:POKE 53279,P:C=0:P=P+1:IF P=7 THEN T=B:RETURN
580 X=H(P):Y=P:IF NOT X THEN 570
590 FOR D=0 TO 3:GOSUB 360:C=C+R:IF R=2 THEN C=C+20
600 IF R>2 THEN T=P:RETURN
610 NEXT D:A= NOT A:FOR D=0 TO 3:GOSUB 360:C=C+R:IF R=2 THEN C=C+10
620 IF R>2 THEN C=C+SET
630 NEXT D:A= NOT A:IF X=1 OR N<6 THEN 660
640 X=X-1:FOR D=0 TO 3:GOSUB 360:C=C-200*(R>2):NEXT D:A= NOT A
650 FOR D=0 TO 3:GOSUB 360:C=C-3000*(R>2):NEXT D:A= NOT A
660 IF C>BN THEN BN=C:B=P
670 GOTO 570
680 IF PEEK(53279)>5 THEN RETURN
690 POP :POP :GOTO 140
25000 REM THE UNIVERSAL DLI:
30000 RESTORE 30040:FOR T=1536 TO 1568:READ D:POKE T,D:NEXT T
30010 READ CA,CB:SET=T:D=PEEK(560)+PEEK(561)*256+2:POKE D,240:N=0:POKE 512,1:POKE 513,6
30020 D=D+1:POKE SET+N,PEEK(712):T=PEEK(D):IF T=65 THEN POKE 1556,33+N:POKE 54286,192:RETURN
30030 T=T-128*(T>127):POKE D,T+128:POKE SET+N,PEEK(712):N=N+1:D=D+2*(T>64):GOTO 30020
30040 DATA 33,72,138,72,174,0,6,189,0,6,141,10,212,141,24,208,141,26
30050 DATA 208,224,152,208,2,162,32,232,142,0,6,104,170,104,64,1550,1553
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: QUATRO.BAS.
Credits
- Program listing: Quatro — program listing (Antic, February 1987 (Vol. 5, No. 10), Game of the Month) — Jeremy Birn
- Picture: The empty board. Every scan line's colour comes from the DLI lookup table. — Jeremy Birn (program); screenshot by the site
- Antic, February 1987 - Vol. 5 No. 10: article (atarimagazines.com) — Jeremy Birn, 1987
- Antic disk, February 1987 - Vol. 5 No. 10: QUATRO.BAS (detokenized listing) — AtariMagazines.com (Kevin Savetz), 1987
