01-05-2026, 10:35 AM
Here's a classic text-based Tic Tac Toe game — pure nostalgia, no graphics, just clean text and old-school terminal vibes. And yes — the computer is intentionally easy to beat (as promised) :-)
Code:
' ==========================
' TIC TAC TOE
' Human (Player 1) = X
' Computer (Player 2) = O
' ==========================
randomize clock() ' Initialize random numbers
visible board = dim(3, 3)
visible row
visible col
visible player
visible moveCount
visible win
player = 1
moveCount = 0
' Initialize board
for row = 0 to 2
for col = 0 to 2
board[row][col] = " "
next
next
' MAIN GAME loop
do
DrawBoard()
if player = 1 then
' HUMAN TURN
pln
pln "Your turn (X)"
write "Enter row (0-2): ";
row = rln(1,TYPE_NUMBER)
write "Enter column (0-2): ";
col = rln(1,TYPE_NUMBER)
if row < 0 or row > 2 or col < 0 or col > 2 then
pln "Invalid position!"
wait 3000
elseif board[row][col] <> " " then
pln "That spot is taken!"
wait 3000
else
board[row][col] = "X"
moveCount = moveCount + 1
CheckWinner()
if win = 1 then GameOver()
player = 2
endif
else
' COMPUTER TURN .... no AI :)
pln
write "Computer is thinking..."
wait 3000
do
row = round(rnd() * 2)
col = round(rnd() * 2)
until board[row][col] = " "
pln "["+row+","+col+"]"
board[row][col] = "O"
moveCount = moveCount + 1
CheckWinner()
if win = 1 then GameOver()
player = 1
endif
until moveCount = 9
' DRAW GAME
DrawBoard()
pln
pln "It's a DRAW!"
system("pause")
end
'------------
' FUNCTIONS
'------------
function DrawBoard()
pln
pln " TIC TAC TOE"
pln
pln " 0 1 2 "
pln " +---+---+---+"
for row = 0 to 2
pln row+" | "+ board[row][0]+ " | "+ board[row][1]+ " | "+ board[row][2]+ " | "
if row < 3 then pln " +---+---+---+"
next
endfunc
function CheckWinner()
win = 0
' Rows
for row = 0 to 2
if board[row][0] <> " " and
board[row][0] = board[row][1] and
board[row][1] = board[row][2] then win = 1
next
' Columns
for col = 0 to 2
if board[0][col] <> " " and
board[0][col] = board[1][col] and
board[1][col] = board[2][col] then win = 1
next
' Diagonals
if board[0][0] <> " " and
board[0][0] = board[1][1] and
board[1][1] = board[2][2] then win = 1
if board[0][2] <> " " and
board[0][2] = board[1][1] and
board[1][1] = board[2][0] then win = 1
endfunc
function GameOver()
DrawBoard()
pln
if player = 1 then
pln "YOU WIN!"
else
pln "COMPUTER WINS!"
endif
system("pause")
end
endfunc


for the computer ...hope this new version make the computer unbeatable .... lol