FUNCTION TAB(N AS INTEGER) AS STRING
TAB = SPACE$(N)
END FUNCTION
RANDOMIZE TIMER
PRINT TAB(22); "FOUR IN A ROW"
PRINT TAB(20); "CREATIVE COMPUTING"
PRINT TAB(18); "MORRISTOWN, NEW JERSEY"
PRINT : PRINT : PRINT
DIM B$(8, 8) AS STRING, L(8) AS DOUBLE, S(4) AS DOUBLE, F(4) AS DOUBLE
DIM V(16) AS DOUBLE, N(4) AS DOUBLE
DATA 1,100,500,1E20,1,800,4000,1E20
DATA 1,75,900,1E18,1,450,3000,1E18
FOR Z1 = 1 TO 16: READ V(Z1): NEXT
PRINT "THE GAME OF FOUR IN A ROW"
INPUT "DO YOU WANT INSTRUCTIONS? "; A$
IF A$ = "NO" THEN: GOTO 270: END IF
IF A$ = "YES" THEN: GOTO 210: END IF
PRINT "YES OR NO": GOTO 170
PRINT "THE GAME CONSISTS OF STACKING X'S"
PRINT "AND O'S (THE COMPUTER HAS O) UNTIL"
PRINT "ONE OF THE PLAYER'S GETS FOUR IN A"
PRINT "ROW VERTICALLY, HORIZONTALLY, OR "
PRINT "DIAGONALLY."
PRINT : PRINT
X$ = "X": O$ = "O"
FOR I = 1 TO 8: FOR J = 1 TO 8: B$(I, J) = "-": NEXT J: NEXT I
FOR Z1 = 1 TO 8: L(Z1) = 0: NEXT Z1
INPUT "DO YOU WANT TO GO FIRST? "; A$
IF A$ = "NO" THEN: GOTO 610: END IF
GOSUB 340
GOTO 450
FOR I = 8 TO 1 STEP -1
FOR J = 1 TO 8
PRINT " "; B$(I, J);
NEXT J
PRINT
NEXT I
PRINT " ";
FOR I = 1 TO 8: PRINT I;" "; : NEXT I
PRINT : PRINT
RETURN
PRINT "ILLEGAL MOVE, TRY AGAIN."
INPUT "A NUMBER BETWEEN 1 AND 8: "; M$
M = INT(VAL(M$))
IF M < 1 OR M > 8 THEN: GOTO 440: END IF
LL = L(M)
IF LL > 7 THEN: GOTO 440: END IF
L(M) = LL + 1: LL = LL + 1
B$(LL, M) = X$
PRINT
GOSUB 340
P$ = X$
GOSUB 1240
FOR Z = 1 TO 4
IF S(Z) < 4 THEN: GOTO 600: END IF
PRINT "Y O U W I N !!!"
GOTO ENDGAME
NEXT Z
M9 = 0: V1 = 0
N1 = 1
FOR M4 = 1 TO 8
LL = L(M4) + 1
IF LL > 8 THEN: GOTO 1080: END IF
VV = 1
P$ = O$: W = 0
M = M4
GOSUB 1240
FOR Z1 = 1 TO 4: N(Z1) = 0: NEXT Z1
FOR Z = 1 TO 4
SS = S(Z)
IF SS - W > 3 THEN: GOTO 1130: END IF
T = SS + F(Z)
IF T < 4 THEN: GOTO 780: END IF
VV = VV + 4
N(SS) = N(SS) + 1
NEXT Z
FOR I = 1 TO 4
NN = N(I) - 1
IF NN = -1 THEN: GOTO 840: END IF
I1 = 8 * W + 4 * SGN(NN) + I
VV = VV + V(I1) + NN * V(8 * W + I)
NEXT I
IF W = 1 THEN: GOTO 880: END IF
W = 1: P$ = X$
GOTO 690
LL = LL + 1
IF LL > 8 THEN: GOTO 1020: END IF
GOSUB 1240
FOR Z = 1 TO 4
IF S(Z) > 3 THEN: VV = 2: END IF
NEXT Z
IF VV < V1 THEN: GOTO 1080: END IF
IF VV > V1 THEN: N1 = 1: GOTO 1060: END IF
N1 = N1 + 1
IF RND(1) > 1 / N1 THEN: GOTO 1080: END IF
V1 = VV
M9 = M4
NEXT M4
IF M9 <> 0 THEN: GOTO 1120: END IF
PRINT "T I E G A M E ..."
GOTO ENDGAME
M = M9
PRINT "COMPUTER PICKS COLUMN "; M: PRINT
LL = L(M) + 1: L(M) = L(M) + 1
B$(LL, M) = O$
P$ = O$: GOSUB 340
GOSUB 1240
FOR Z = 1 TO 4
IF S(Z) < 4 THEN: GOTO 1220: END IF
PRINT "C O M P U T E R W I N S !!!"
GOTO ENDGAME
NEXT Z
GOTO 450
Q$ = X$
IF P$ = X$ THEN: Q$ = O$: END IF
D2 = 1: D1 = 0
Z = 0
GOSUB 1360
D1 = 1: D2 = 1
GOSUB 1360
D2 = 0: D1 = 1
GOSUB 1360
D2 = -1: D1 = 1
GOSUB 1360
RETURN
D = 1: SS = 1
T = 0
Z = Z + 1
C = 0
FOR K = 1 TO 3
M5 = M + K * D1: L1 = LL + K * D2
IF M5 < 1 OR L1 < 1 OR M5 > 8 OR L1 > 8 THEN: GOTO 1510: END IF
BB$ = B$(L1, M5)
IF C = 0 THEN: GOTO 1480: END IF
IF BB$ = Q$ THEN: K = 3: GOTO 1510: END IF
T = T + 1
GOTO 1510
IF BB$ = P$ THEN: SS = SS + 1: GOTO 1510: END IF
C = 1
GOTO 1450
NEXT K
IF D = 0 THEN: GOTO 1550: END IF
D = 0: D1 = -D1: D2 = -D2
GOTO 1390
S(Z) = SS
F(Z) = T
RETURN
ENDGAME:
|