REM This
is a sample QBASIC program from MS
-DOS
5 (June
1990)
vmode = TRUE
LOCATE 10, 15:
PRINT "No graphics screen mode available; cannot run REVERSI.BAS" GS.stat = START
GS.dLevel = "Novice"
InitGame
DrawGameBoard
UserMove
DisplayMsg "You have no valid moves. Select pass."
LINE (0, 420)-(640, 447), 3, BF
GS.mDisplay = FALSE
GS.stat = COMP
ComputerMove
GameOver
ComputerMove
DisplayMsg "Computer has no valid moves. Your Turn."
GS.stat = HUMAN
UserMove
GameOver
DisplayMsg "Game Over"
BadMode:
vmode = FALSE
FUNCTION CheckPath
(i
, IBound
, IStep
, j
, JBound
, JStep
, Opponent
)
done = FALSE
IF GG
(i
, j
).player
= GBoard
THEN count = 0
done = TRUE
count = count + 1
i = i + IStep
j = j + JStep
count = 0
done = TRUE
done = TRUE
CheckPath = count
BestMove = -99
IF GG
(row
, col
).nTake
> 0 THEN value = GG(row, col).nTake + GW(row, col)
value = GG(row, col).nTake + GW(row, col)
IF col
< 5 THEN value
= value
+ ABS(10 * GG
(1, 1).player
= COMP
) IF col
> 4 THEN value
= value
+ ABS(10 * GG
(1, 8).player
= COMP
) IF GG
(1, col
).player
<> COMP
THEN value
= value
+ 5 * (GG
(1, col
).player
= HUMAN
) IF col
> 1 AND GG
(1, col
- 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(1, col
- 1).player
= HUMAN
) IF col
< 8 AND GG
(1, col
+ 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(1, col
+ 1).player
= HUMAN
) IF GG
(8, col
).player
<> COMP
THEN value
= value
+ 5 * (GG
(8, col
).player
= HUMAN
) IF col
> 1 AND GG
(8, col
- 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(8, col
- 1).player
= HUMAN
) IF col
< 8 AND GG
(8, col
+ 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(8, col
+ 1).player
= HUMAN
) IF col
< 5 THEN value
= value
+ ABS(10 * GG
(8, 1).player
= COMP
) IF col
> 4 THEN value
= value
+ ABS(10 * GG
(8, 8).player
= COMP
) IF row
< 5 THEN value
= value
+ ABS(10 * GG
(1, 1).player
= COMP
) IF row
> 4 THEN value
= value
+ ABS(10 * GG
(8, 1).player
= COMP
) IF GG
(row
, 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
, 1).player
= HUMAN
) IF row
> 1 AND GG
(row
- 1, 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
- 1, 1).player
= HUMAN
) IF row
< 8 AND GG
(row
+ 1, 1).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
+ 1, 1).player
= HUMAN
) IF GG
(row
, 8).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
, 8).player
= HUMAN
) IF row
> 1 AND GG
(row
- 1, 8).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
- 1, 8).player
= HUMAN
) IF row
< 8 AND GG
(row
+ 1, 8).player
<> COMP
THEN value
= value
+ 5 * (GG
(row
+ 1, 8).player
= HUMAN
) IF row
< 5 THEN value
= value
+ ABS(10 * GG
(1, 8).player
= COMP
) IF row
> 4 THEN value
= value
+ ABS(10 * GG
(8, 8).player
= COMP
) BestMove = value
bestrow = row
bestcol = col
TakeBlocks bestrow, bestcol, COMP
GS.stat = HUMAN
a$(1) = "The object of Reversi is to finish the game with more of your red"
a$(2) = "circles on the board than the computer has of blue (Monochrome"
a$(3) = "monitors will show red as white and blue as black)."
a$(4) = ""
a$(5) = "1) You and the computer play by the same rules."
a$(6) = "2) To make a legal move, at least one of the computer's circles"
a$(7) = " must lie in a horizontal, vertical, or diagonal line between"
a$(8) = " one of your existing circles and the square where you want to"
a$(9) = " move. Use the arrow keys to position the cursor on the square"
a$(10) = " and hit Enter or the Space Bar."
a$(11) = "3) You can choose Pass from the game controls menu on your first"
a$(12) = " move to force the computer to play first."
a$(13) = "4) After your first move, you cannot pass if you can make a legal"
a$(14) = " move."
a$(15) = "5) If you cannot make a legal move, you must choose Pass"
a$(16) = "6) When neither you nor the computer can make a legal move, the"
a$(17) = " game is over."
a$(18) = "7) The one with the most circles wins."
LINE (0, 0)-(640, 480), BG
, BF
LINE (39, 15)-(590, 450), 0, B
PAINT (200, 200), GBoard
, 0 LINE (590, 25)-(600, 460), 0, BF
LINE (50, 450)-(600, 460), 0, BF
DrawGameBoard
DrawCursor GS.curRow, GS.curCol
LX = (640 - 8 * (slen + 8)) / 2
LINE (LX
- 1, 420)-(640 - LX
, 447), 0, B
PAINT (LX
+ 10, 430), GBoard
, 0 GS.mDisplay = TRUE
SUB DrawCursor
(row
, col
) IF GG
(row
, col
).nTake
> 0 THEN CIRCLE (GG
(row
, col
).cx
, GG
(row
, col
).cy
), 15, HUMAN
CIRCLE (GG
(row
, col
).cx
, GG
(row
, col
).cy
), 14, HUMAN
lc = 0
IF GG
(row
, col
).player
= 0 THEN lc
= 7 LINE (GG
(row
, col
).cx
, GG
(row
, col
).cy
- 15)-(GG
(row
, col
).cx
, GG
(row
, col
).cy
+ 15), lc
LINE (GG
(row
, col
).cx
- 1, GG
(row
, col
).cy
- 15)-(GG
(row
, col
).cx
- 1, GG
(row
, col
).cy
+ 15), lc
LINE (GG
(row
, col
).cx
+ 15, GG
(row
, col
).cy
)-(GG
(row
, col
).cx
- 15, GG
(row
, col
).cy
), lc
LINE (0, 0)-(640, 480), BG
, BF
LINE (239, 15)-(400, 40), 0, B
LINE (39, 260)-(231, 390), 0, B
LINE (39, 70)-(231, 220), 0, B
LINE (269, 70)-(591, 390), 0, B
PAINT (300, 25), GBoard
, 0 PAINT (150, 350), GBoard
, 0 PAINT (150, 124), GBoard
, 0 PAINT (450, 225), GBoard
, 0 LINE (400, 25)-(410, 50), 0, BF
LINE (250, 40)-(410, 50), 0, BF
LINE (231, 80)-(240, 230), 0, BF
LINE (50, 220)-(240, 230), 0, BF
LINE (590, 80)-(600, 400), 0, BF
LINE (280, 390)-(600, 400), 0, BF
LINE (231, 270)-(240, 400), 0, BF
LINE (50, 390)-(240, 400), 0, BF
LINE (270, 70 + i
* 40)-(590, 70 + i
* 40), 0 LINE (270 + i
* 40, 70)-(270 + i
* 40, 390), 0 LINE (269 + i
* 40, 70)-(269 + i
* 40, 390), 0
IF GG
(row
, col
).player
<> GBoard
THEN DrawGamePiece row, col, GG(row, col).player
SUB DrawGamePiece
(row
, col
, GpColor
)
LINE (232 + col
* 40, 33 + row
* 40)-(267 + col
* 40, 67 + row
* 40), 7, BF
CIRCLE (GG
(row
, col
).cx
, GG
(row
, col
).cy
), 15, 0 PAINT (GG
(row
, col
).cx
, GG
(row
, col
).cy
), GpColor
, 0 PAINT (235 + col
* 40, 35 + row
* 40), CHR$(85), 0 CIRCLE (GG
(row
, col
).cx
, GG
(row
, col
).cy
), 15, GpColor
CIRCLE (GG
(row
, col
).cx
, GG
(row
, col
).cy
), 14, GpColor
PAINT (GG
(row
, col
).cx
, GG
(row
, col
).cy
), GpColor
, GpColor
Scorediff = GS.rScore - GS.bScore
DisplayMsg "Tie Game"
DisplayMsg "You lost by"
DisplayMsg "You won by"
LINE (0, 420)-(640, 447), BG
, BF
HUMAN = 4
COMP = 1
BG = 3
GBoard = 8
HUMAN = 7
COMP = 0
BG = 7
GBoard = 1
GBoard = 85
GS.curCol = 5
GS.curRow = 3
GS.stat = FMOVE
GS.bScore = 2
GS.rScore = 2
GS.mDisplay = FALSE
GG(row, col).player = GBoard
GG(row, col).nTake = 0
GG(row, col).cx = 270 + (col - .5) * 40
GG(row, col).cy = 70 + (row - .5) * 40
GW(row, col) = 2
GW(1, 1) = 99
GW(1, 8) = 99
GW(8, 1) = 99
GW(8, 8) = 99
GW(i, j) = 5
GW(j, i) = 5
GG(4, 4).player = HUMAN
GG(5, 4).player = COMP
GG(4, 5).player = COMP
GG(5, 5).player = HUMAN
SUB TakeBlocks
(row
, col
, player
)
GG(row, col).player = player
DrawGamePiece row, col, player
FOR i
= 1 TO GP
(row
, col
, 1) GG(row, col - i).player = player
DrawGamePiece row, col - i, player
FOR i
= 1 TO GP
(row
, col
, 2) GG(row, col + i).player = player
DrawGamePiece row, col + i, player
FOR i
= 1 TO GP
(row
, col
, 3) GG(row - i, col).player = player
DrawGamePiece row - i, col, player
FOR i
= 1 TO GP
(row
, col
, 4) GG(row + i, col).player = player
DrawGamePiece row + i, col, player
FOR i
= 1 TO GP
(row
, col
, 5) GG(row - i, col - i).player = player
DrawGamePiece row - i, col - i, player
FOR i
= 1 TO GP
(row
, col
, 6) GG(row + i, col + i).player = player
DrawGamePiece row + i, col + i, player
FOR i
= 1 TO GP
(row
, col
, 7) GG(row - i, col + i).player = player
DrawGamePiece row - i, col + i, player
FOR i
= 1 TO GP
(row
, col
, 8) GG(row + i, col - i).player = player
DrawGamePiece row + i, col - i, player
GS.rScore = GS.rScore + GG(row, col).nTake + 1
GS.bScore = GS.bScore - GG(row, col).nTake
GS.bScore = GS.bScore + GG(row, col).nTake + 1
GS.rScore = GS.rScore - GG(row, col).nTake
DrawCursor GS.curRow, GS.curCol
LINE (0, 420)-(640, 447), BG
, BF
GS.mDisplay = FALSE
DrawGamePiece GS.curRow, GS.curCol, GG(GS.curRow, GS.curCol).player
GS.curRow = EBLOCK
GS.curRow = GS.curRow - 1
GS.curRow = BBLOCK
GS.curRow = GS.curRow + 1
GS.curCol = EBLOCK
GS.curCol = GS.curCol - 1
GS.curCol = BBLOCK
GS.curCol = GS.curCol + 1
DrawCursor GS.curRow, GS.curCol
GS.stat = START
DisplayMsg "You passed. Computer will make first move."
GS.stat = COMP
DisplayMsg "You can only pass on your first turn."
DisplayHelp
GS.dLevel = "Expert"
GS.dLevel = "Novice"
PRINT "Difficulty: "; GS.dLevel;
IF GG
(GS.curRow
, GS.curCol
).nTake
> 0 THEN TakeBlocks GS.curRow, GS.curCol, HUMAN
GS.stat = COMP
DisplayMsg "Invalid move. Move to a space where the cursor is a circle."
GS.stat = QUIT
ValidMove = FALSE
GG(row, col).nTake = 0
IF GG
(row
, col
).player
= GBoard
THEN GP(row, col, 1) = CheckPath(row, row, 0, col - 1, 0, -1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 1)
GP(row, col, 2) = CheckPath(row, row, 0, col + 1, 9, 1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 2)
GP(row, col, 3) = CheckPath(row - 1, 0, -1, col, col, 0, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 3)
GP(row, col, 4) = CheckPath(row + 1, 9, 1, col, col, 0, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 4)
GP(row, col, 5) = CheckPath(row - 1, 0, -1, col - 1, 0, -1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 5)
GP(row, col, 6) = CheckPath(row + 1, 9, 1, col + 1, 9, 1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 6)
GP(row, col, 7) = CheckPath(row - 1, 0, -1, col + 1, 9, 1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 7)
GP(row, col, 8) = CheckPath(row + 1, 9, 1, col - 1, 0, -1, Opponent)
GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 8)
IF GG
(row
, col
).nTake
> 0 THEN ValidMove
= TRUE