' Othello Revision by William Yu 1995
' This game requires EGA or VGA
' You can modify this so it can run on any screen mode you wish
' I haven't documented this game because I'm too lazy, and besides
' that, I don't know what half of my program means! :)
' To change user/computer colors you have to change the variables
' PC and PLAYERC and modify some of the other code to match up
' with your selected color.
' Enjoy this game, the computer does random moves so it'll be a snap
' to kick its butt. Modify it so the computer at least has a chance.
' I don't know much on strategy so I don't know how to make the computer
' think for itself.
' I always program things in a rush, so don't expect too much from it.
DEFINT A-Z
CLS
PRINT "Othello Revision by William Yu 1995": PRINT
PRINT "Select Video Type"
PRINT
PRINT "1. EGA"
PRINT "2. VGA"
LOCATE , , 1
DO
G$ = INPUT$(1)
LOOP UNTIL G$ = "1" OR G$ = "2"
IF G$ = "1" THEN SCREEN 7
IF G$ = "2" THEN SCREEN 13
BEGINGAME:
X = 0: Y = 0: W = 230: Z = 190
IF G$ = "2" THEN
FOR C = 16 TO 31
LINE (X, Y)-(W, Z), C, B
X = X + 1: Y = Y + 1: W = W - 1: Z = Z - 1
NEXT C
ELSE
LINE (15, 15)-(215, 175), 15, B
LINE (14, 14)-(216, 176), 7, B
LINE (13, 13)-(217, 177), 8, B
END IF
IF G$ = "2" THEN PAINT (150, 100), 7, 31 ELSE PAINT (150, 100), 7, 15
FOR X = 35 TO 205 STEP 20
LINE (X, 15)-(X, 175), 15
NEXT X
FOR Y = 31 TO 180 STEP 16
LINE (15, Y)-(215, Y), 15
NEXT Y
PC = 12
PLAYERC = 9
CIRCLE (105, 87), 7, PLAYERC
PAINT (105, 87), PLAYERC
CIRCLE (125, 87), 7, PC
PAINT (125, 87), PC
CIRCLE (105, 103), 7, PC
PAINT (105, 103), PC
CIRCLE (125, 103), 7, PLAYERC
PAINT (125, 103), PLAYERC
LOCATE 2, 32: COLOR 15: PRINT "OTHELLO"
LINE (95, 79)-(115, 95), 0, B
X = 95: Y = 79: W = 115: Z = 95
CIRCLE (275, 30), 7, PLAYERC
PAINT (275, 30), PLAYERC
LOCATE 9, 32: PRINT "PLAYERS"
LOCATE 11, 31: PRINT "1. ONE"
LOCATE 13, 31: PRINT "2. TWO"
DO
A$ = INPUT$(1)
LOOP UNTIL A$ = "1" OR A$ = "2"
LOCATE 9, 32: PRINT SPACE$(7)
LOCATE 11, 31: PRINT SPACE$(6)
LOCATE 13, 31: PRINT SPACE$(6)
IF A$ = "1" THEN PLAYER = 1 ELSE PLAYER = 2
LOCATE 20, 32: PRINT CHR$(34); : COLOR 10: PRINT "P"; : COLOR 15: PRINT CHR$(34); "ass"
LOCATE 22, 32: PRINT CHR$(34); : COLOR 10: PRINT "Q"; : COLOR 15: PRINT CHR$(34); "uit"
BOX = 4
DO
IF PLAYERC = 12 AND PLAYER = 1 THEN GOSUB COMPUTER
V$ = INKEY$
IF V$ = CHR$(0) + "P" THEN GOSUB DOWN
IF V$ = CHR$(0) + "K" THEN GOSUB LEFT
IF V$ = CHR$(0) + "M" THEN GOSUB RIGHT
IF V$ = CHR$(0) + "H" THEN GOSUB UP
IF UCASE$(V$) = "P" THEN SWAP PLAYERC, PC: PAINT (275, 30), PLAYERC, 0
IF UCASE$(V$) = "Q" THEN GOTO OTHELLOEND
IF V$ = CHR$(13) THEN GOSUB PUTSQUARE
IF V$ = CHR$(27) THEN GOTO OTHELLOEND
LOOP
LEFT:
IF X = 15 THEN RETURN
LINE (X, Y)-(W, Z), 15, B
X = X - 20: W = W - 20
LINE (X, Y)-(W, Z), 0, B
RETURN
RIGHT:
IF W = 215 THEN RETURN
LINE (X, Y)-(W, Z), 15, B
X = X + 20: W = W + 20
LINE (X, Y)-(W, Z), 0, B
RETURN
DOWN:
IF Z = 175 THEN RETURN
LINE (X, Y)-(W, Z), 15, B
Y = Y + 16: Z = Z + 16
LINE (X, Y)-(W, Z), 0, B
RETURN
UP:
IF Y = 15 THEN RETURN
LINE (X, Y)-(W, Z), 15, B
Y = Y - 16: Z = Z - 16
LINE (X, Y)-(W, Z), 0, B
RETURN
COMPUTER:
LOCATE 9, 31: COLOR 14: PRINT "COMPUTING"
BACKX = X
BACKY = Y
AGAIN = 0
DO
V$ = INKEY$
IF V$ = CHR$(27) THEN GOTO DECIDEWINNER
RANDOMIZE TIMER
RNY = INT(RND * 10) + 1
RNX = INT(RND * 10) + 1
IF RNY = 1 THEN Y = 15 ELSE Y = 15 + ((RNY - 1) * 16)
IF RNX = 1 THEN X = 15 ELSE X = 15 + ((RNX - 1) * 20)
GOSUB PUTSQUARE
AGAIN = AGAIN + 1
IF AGAIN = 250 THEN
LOCATE 9, 31: COLOR 11: PRINT " PASS! "
SLEEP 1
SWAP PLAYERC, PC
PAINT (275, 30), PLAYERC, 0
LOCATE 9, 31: PRINT SPACE$(9)
X = BACKX
Y = BACKY
RETURN
END IF
LOOP UNTIL VALID = 1
IF VALID <> 1 THEN
FOR Y = 15 TO 170 STEP 16
FOR X = 15 TO 200 STEP 20
GOSUB PUTSQUARE
IF VALID = 1 THEN EXIT FOR
NEXT X
IF VALID = 1 THEN EXIT FOR
NEXT Y
X = BACKX
Y = BACKY
END IF
LOCATE 9, 31: PRINT SPACE$(9)
X = BACKX
Y = BACKY
RETURN
PUTSQUARE:
VALID = -1
Colour = POINT(X + 10, Y + 10)
IF Colour <> 7 THEN
IF PLAYERC = 12 AND PLAYER = 1 THEN
RETURN
ELSE
LOCATE 10, 31: COLOR 10: PRINT "OCCUPIED!": SLEEP 1: LOCATE 10, 31: PRINT SPACE$(9): RETURN
END IF
END IF
' Check side on Right
N = X + 20
M = N
C = 0
FOR R = N TO 200 STEP 20
C = POINT(R + 10, Y + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R - 20
FOR R = M TO N STEP 20
PAINT (R + 10, Y + 10), PLAYERC, 7
NEXT R
END IF
' Check side on Left
N = X - 20
M = N
C = 0
FOR R = N TO 10 STEP -20
C = POINT(R + 10, Y + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R + 20
FOR R = N TO M STEP 20
PAINT (R + 10, Y + 10), PLAYERC, 7
NEXT R
END IF
' Check Up
N = Y - 18
M = N
C = 0
FOR R = N TO 10 STEP -16
C = POINT(X + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R + 16
FOR R = N TO M STEP 16
PAINT (X + 10, R + 10), PLAYERC, 7
NEXT R
END IF
' Check Down
N = Y + 14
M = N
C = 0
FOR R = N TO 170 STEP 16
C = POINT(X + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R - 14
FOR R = M TO N STEP 16
PAINT (X + 10, R + 10), PLAYERC, 7
NEXT R
END IF
' Check Diagonals
' Right & Down
N = Y + 14
F = X + 20
M = N
G = F
C = 0
FOR R = N TO 170 STEP 16
C = POINT(F + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
F = F + 20
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R - 14
F = X + 20
FOR R = M TO N STEP 16
PAINT (F + 10, R + 10), PLAYERC, 7
F = F + 20
NEXT R
END IF
' Right & Up
N = Y - 18
F = X - 20
M = N
G = F
C = 0
FOR R = N TO 10 STEP -16
C = POINT(F + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
F = F - 20
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R + 16
F = F + 20
FOR R = N TO M STEP 16
PAINT (F + 10, R + 10), PLAYERC, 7
F = F + 20
NEXT R
END IF
' Left & Down
N = Y + 14
F = X - 20
M = N
G = F
C = 0
FOR R = N TO 170 STEP 16
C = POINT(F + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
F = F - 20
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R - 14
F = X - 20
FOR R = M TO N STEP 16
PAINT (F + 10, R + 10), PLAYERC, 7
F = F - 20
NEXT R
END IF
' Left & Up
N = Y - 18
F = X + 20
M = N
G = F
C = 0
FOR R = N TO 10 STEP -16
C = POINT(F + 10, R + 10)
IF C = 7 THEN EXIT FOR
IF C = PLAYERC THEN EXIT FOR
F = F + 20
NEXT R
IF C = PLAYERC AND N <> R THEN
VALID = 1
N = R + 16
F = F - 20
FOR R = N TO M STEP 16
PAINT (F + 10, R + 10), PLAYERC, 7
F = F - 20
NEXT R
END IF
IF VALID = -1 THEN
IF PLAYER = 1 AND PLAYERC = 12 THEN
ELSE
LOCATE 9, 32: COLOR 14: PRINT "ILLEGAL"
LOCATE 11, 33: PRINT "MOVE!"
SLEEP 1
LOCATE 9, 32: PRINT SPACE$(9)
LOCATE 11, 33: PRINT SPACE$(5)
END IF
RETURN
ELSE
BOX = BOX + 1
END IF
CIRCLE (X + 10, Y + 8), 7, PLAYERC
PAINT (X + 10, Y + 8), PLAYERC
SWAP PLAYERC, PC
PAINT (275, 30), PLAYERC, 0
IF BOX = 100 THEN LOCATE 9, 31: PRINT SPACE$(9): GOTO DECIDEWINNER
RETURN
DECIDEWINNER:
BLUE = 0
RED = 0
LOCATE 20, 31: PRINT SPACE$(9)
LOCATE 22, 31: PRINT SPACE$(9)
LOCATE 8, 33: COLOR 10: PRINT "FINAL"
LOCATE 10, 33: PRINT "SCORE"
LOCATE 13, 31: COLOR 9: PRINT "BLUE:"
LOCATE 15, 31: COLOR 12: PRINT "RED: "
COLOR 15
Y = 24
DO
FOR X = 25 TO 220 STEP 20
CL = POINT(X, Y)
IF CL = 9 THEN BLUE = BLUE + 1: LOCATE 13, 36: PRINT BLUE
IF CL = 12 THEN RED = RED + 1: LOCATE 15, 36: PRINT RED
NEXT X
Y = Y + 16
LOOP UNTIL Y >= 170
COLOR 14
IF BLUE > RED THEN LOCATE 19, 31: PRINT "BLUE WINS!"
IF RED > BLUE THEN LOCATE 19, 31: PRINT "RED WINS!"
IF BLUE = RED THEN LOCATE 19, 31: PRINT "IT'S A TIE"
LOCATE 25, 1: PRINT "ANOTHER GAME [Y/N] "; : COLOR 12
DO
A$ = INPUT$(1)
ANS$ = UCASE$(A$)
LOOP UNTIL ANS$ = "Y" OR ANS$ = "N"
IF UCASE$(A$) = "Y" THEN CLS : GOTO BEGINGAME
OTHELLOEND:
SCREEN 0, 0, , 0: CLS
WIDTH 80, 25