100 WINDOW 512,201,0,0:CLS
110 REPeat program
120 screen
130 instruct
140 init
150 val=RND(1):IF val AND type=1 THEN computer
160 IF val AND type=2 THEN player_2
170 REPeat game
190 check_move:IF draw=1 THEN EXIT game
200 player_1
210 IF win THEN win=1:EXIT game
230 check_move:IF draw=1 THEN EXIT game
240 IF type=1 THEN computer:ELSE player_2
250 IF win THEN win=2:EXIT game
260 END REPeat game
270 BEEP 0,1,254,3,1
280 RECOL 0,2,1,5,4,3,6,7:RECOL #0,0,2,1,5,4,3,6,7
290 BEEP:FLASH #0,1:PAPER #0,1:INK #0,7:CSIZE #0,3,1:AT #0,0,5
300 IF win=1 THEN PRINT #0,"  PLAYER 1 WINS !"
310 IF win=2 AND type=1 THEN PRINT #0,"THE COMPUTER WINS !"
320 IF win=2 AND type=2 THEN PRINT #0,"  PLAYER 2 WINS !"
330 IF draw=1 THEN PRINT #0,"  MATCH DRAWN"
340 CSIZE #0,2,0:FLASH #0,0:AT #0,3,12:PRINT #0,"Press any key":PAUSE
350 END REPeat program
360 DEFine PROCedure computer
370 next_player 0:hs=0:n=0:ht=0
380 REPeat find_move
390 IF n=7 THEN EXIT find_move:ELSE n=n+1
400 IF a(n,1) THEN NEXT find_move
410 colour=4:score 1:s1=s+wn*30+4-ABS(n-4):IF ht=0 THEN ht=n
420 IF win THEN ht=n:EXIT find_move
440 colour=6:score 1:IF win AND level=1 THEN ht=n:EXIT find_move
445 IF level=2 THEN 
447 s1=s1+s+wn*50
450 IF y>1 AND NOT win THEN y=y-1:score -1:IF win THEN NEXT find_move
470 END IF 
480 IF s1=hs AND RND<.5 THEN ht=n
490 IF s1>hs THEN hs=s1:ht=n
500 END REPeat find_move
510 n=ht:arrow n,0:PAUSE 20:counter 4
520 CURSOR 330,165:p2s=p2s+s:PRINT INT(p2s);"   "
530 END DEFine 
540 DEFine PROCedure player_1
550 next_player 1:n=1:arrow n,0
560 REPeat move_arrow
570 k$=INKEY$(-1):IF k$=" " AND a(n,1)=0 THEN EXIT move_arrow
580 arrow n,2:IF n<7 THEN n=n+1:ELSE n=1
590 arrow n,0:BEEP 500,1,254,3,1
600 END REPeat move_arrow
610 counter 6:CURSOR 330,130:p1s=p1s+s:PRINT INT(p1s);"   "
620 END DEFine 
630 DEFine PROCedure player_2
640 next_player 0:n=1:arrow n,0
650 REPeat move_arrow
660 k$=INKEY$(-1):IF k$=" " AND a(n,1)=0 THEN EXIT move_arrow
670 arrow n,2:IF n<7 THEN n=n+1:ELSE n=1
680 arrow n,0:BEEP 500,1,254,3,1
690 END REPeat move_arrow
700 counter 4:CURSOR 330,165:p2s=p2s+s:PRINT INT(p2s);"   "
710 END DEFine 
720 DEFine PROCedure counter(colour)
730 FOR down=1 TO 7:IF a(n,down) THEN EXIT down
740 a(n,down-1)=colour:arrow n,2:x=x+3:FILL 1
750 FOR y=70 TO 94-down*12 STEP -12:INK colour:CIRCLE x,y,5:BEEP 100,y:PAUSE 5:INK 1:CIRCLE x,y,5
760 INK colour:CIRCLE x,y,5:FILL 0:score 0
770 INK 0:PAPER 7:OVER 0
780 END DEFine 
790 DEFine PROCedure check_move
800 count=0:FOR n=1 TO 7:IF a(n,1) THEN count=count+1
810 draw=count=7
820 END DEFine 
830 DEFine PROCedure score(u)
840 IF u>=0 THEN y=7-u:FOR down=1 TO 6:IF a(n,down) THEN y=down-u:EXIT down
850 q=4:FOR inc=1 TO 3:IF a(n,y+inc)<>colour THEN q=inc:EXIT inc
860 w=4:FOR inc=1 TO 3:IF a(n,y-inc)<>colour THEN w=inc:EXIT inc
870 s=5^(q+w-1):wn=(q+w)>3
880 q=4:FOR inc=1 TO 3:IF a(n+inc,y)<>colour THEN q=inc:EXIT inc
890 w=4:FOR inc=1 TO 3:IF a(n-inc,y)<>colour THEN w=inc:EXIT inc
900 s=s+5^(q+w-1):IF q+w>3 AND (a(n+q,y)=0 OR a(n-w,y)=0) THEN wn=wn+1+(a(n+q,y+1)>0)+(a(n-w,y+1)>0)
910 q=4:FOR inc=1 TO 3:IF a(n+inc,y+inc)<>colour THEN q=inc:EXIT inc
920 w=4:FOR inc=1 TO 3:IF a(n-inc,y-inc)<>colour THEN w=inc:EXIT inc
930 s=s+5^(q+w-1):IF q+w>3 AND (a(n+q,y+q)=0 OR a(n-w,y-w)=0) THEN wn=wn+1+(a(n+q,y+q+1)>0)+(a(n-w,y-w+1)>0)
940 q=4:FOR inc=1 TO 3:IF a(n-inc,y+inc)<>colour THEN q=inc:EXIT inc
950 w=4:FOR inc=1 TO 3:IF a(n+inc,y-inc)<>colour THEN w=inc:EXIT inc
960 s=s+5^(q+w-1):IF q+w>3 AND (a(n-q,y+q)=0 OR a(n+w,y-w)=0) THEN wn=wn+1+(a(n-q,y+q+1)>0)+(a(n+w,y-w+1)>0)
965 win=s>625
970 END DEFine 
980 DEFine PROCedure init
990 CSIZE 2,0:INK 2:CURSOR 300,45:PRINT "GAME TYPE"
1000 INK 1:CURSOR 305,60:IF type=1 THEN PRINT "COMPUTER":ELSE PRINT "2 PLAYER"
1010 CURSOR 330,70:IF level=1 THEN PRINT "Easy":ELSE IF level=2 THEN PRINT "Hard"
1020 DIM a(8,8):p1s=0:p2s=0:win=0:OVER 0
1025 FOR x=0 TO 8:a(x,0)=-1:a(x,7)=-1:a(x,8)=-1
1027 FOR y=1 TO 6:a(0,y)=-1:a(8,y)=-1
1030 END DEFine 
1040 DEFine PROCedure next_player(f1)
1050 OVER 0:PAPER 7:FLASH f1:INK 2:CURSOR 310,120:PRINT "PLAYER 1"
1060 CURSOR 310,155:FLASH NOT f1:IF type=2 THEN PRINT "PLAYER 2":ELSE PRINT "COMPUTER"
1070 FLASH 0
1080 END DEFine 
1090 DEFine PROCedure screen
1100 MODE 8:PAPER #0,2:CLS #0:PAPER 2:INK 7:CLS:CSIZE 0,1
1110 BLOCK 244,154,14,43,0:BLOCK 240,150,16,45,5
1120 BLOCK 149,159,287,40,0:BLOCK 154,163,278,34,0:BLOCK 150,161,280,35,7
1130 a$="LINK-4":OVER 1:CURSOR 320,10:INK 0:PRINT a$:CURSOR 319,9:INK 7:PRINT a$
1145 INK 1:FOR y=10 TO 70 STEP 12
1150 FOR x=15 TO 87 STEP 12:FILL 1:CIRCLE x,y,5
1155 END FOR y:FILL 0
1170 END DEFine 
1180 DEFine PROCedure arrow(n,i)
1190 x=n*12:INK i:FILL 1
1200 LINE x+2,88 TO x+2,92 TO x+6,93 TO x+6,88 TO x+2,88,x,88 TO x+8,88 TO x+4,82 TO x,88
1210 FILL 0
1220 END DEFine 
1230 DEFine PROCedure instruct
1240 CSIZE 2,0:CURSOR 300,45:INK 2:PRINT "GAME PLAY"
1250 INK 0:RESTORE :FOR y=60 TO 110 STEP 10:READ a$:CURSOR 290,y:PRINT a$
1260 DATA "Try to link","4 of your","pieces in a","row before","your chosen","opponent"
1270 CURSOR 320,150:INK 2:PRINT "SELECT"
1280 CURSOR 282,167:INK 0:PRINT "(1) COMPUTER":CURSOR 282,177:PRINT "(2) 2 PLAYER"
1290 type=select_type:level=0
1300 IF type=1 THEN 
1310 BLOCK 150,28,280,168,7:CURSOR 282,167:PRINT "(1) EASY":CURSOR 282,177:PRINT "(2) HARD"
1320 level=select_type
1325 END IF 
1330 BLOCK 150,161,280,35,7
1340 END DEFine 
1350 DEFine FuNction select_type
1360 REPeat wait:k$=INKEY$(-1):IF k$ INSTR "12" THEN BEEP 1000,20:RETurn k$
1370 END DEFine 
2000 DEFine PROCedure map
2010 FOR iy=0 TO 8
2020 FOR ix=0 TO 8:PRINT !a(iy,ix);
2030 PRINT:END FOR iy
2040 END DEFine 
