I ordered a PicoCalc in November. After a brief wait and lots of emails to customs, I finally got it delivered today! I booted it up with PicoMite MMBASIC gave me serious nostalgia, reminding me of my first programming adventures with BASIC back in the day...
Anyway, I messed around with the device and just wrote a simple circle-drawing thingy...
while not keydown(KEY_ESCAPE, true)
i = 0
while i < sizeof(plybullets)
b = plybullets[i]
b.pos.x = b.pos.x + b.spd.x
b.pos.y = b.pos.y + b.spd.y
if b.pos.x < -b.size.x or b.pos.x >= 256 or b.pos.y < -b.size.y or b.pos.y >= 224
free key plybullets, i
else
hit = false
for y = EROWS - 1 to 0
for x = 0 to ECOLS - 1
e = enms[x][y]
if e and Collides(b, e)
e.stm = e.stm - 1
if e.stm <= 0 enms[x][y] = unset
hit = true
break
endif
next
if hit break
next
if hit free key plybullets, i
else i = i + 1
endif
wend
i = 0
while i < sizeof(enmbullets)
b = enmbullets[i]
b.pos.x = b.pos.x + b.spd.x
b.pos.y = b.pos.y + b.spd.y
if b.pos.x < -b.size.x or b.pos.x >= 256 or b.pos.y < -b.size.y or b.pos.y >= 224
free key enmbullets, i
else
i = i + 1
endif
wend
divet = divet - 1
if divet <= 0
clear tmp
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
if enms[x][y] and enms[x][y].p = unset tmp[sizeof(tmp)] = enms[x][y]
next
if sizeof(tmp)
e = tmp[rnd(sizeof(tmp))]
e.p = 0
e.c[0].x = e.pos.x; e.c[0].y = e.pos.y
e.c[1].x = rnd(242); e.c[1].y = 224
e.c[2].x = rnd(242); e.c[2].y = 224
e.c[3].x = e.pos.x; e.c[3].y = e.pos.y
divet = 120 + rnd(3)*60
else
divet = 60
endif
endif
enmshoott = enmshoott - 1
if enmshoott < 0
enmshoott = 180 + rnd(3)*60
clear tmp
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
if enms[x][y] for i = 0 to enms[x][y].p <> unset tmp[sizeof(tmp)] = enms[x][y]
next
if sizeof(tmp)
e = tmp[rnd(sizeof(tmp))]
dx = ply.pos.x - e.pos.x
dy = ply.pos.y - e.pos.y
k = sqr(dx*dx + dy*dy)
if k > 0
dx = 2*dx/k
dy = 2*dy/k
enmbullets[sizeof(enmbullets)] = [
pos: Point(e.pos.x + e.size.x/2 - 2, e.pos.y + e.size.y/2 - 2),
size: Point(4, 4),
spd: Point(dx, dy)]
endif
endif
endif
enmsa = (enmsa + 1)%360
for y = 0 to EROWS - 1
offsx = 128 - ECOLS*8 + sin(rad(enmsa + y*22.5))*24
offsy = 24
for x = 0 to ECOLS - 1
e = enms[x][y]
if e
gx = x*16 + offsx + 1; gy = y*16 + offsy + 1
if typeof(e.p)
e.p = e.p + 0.005
if e.p >= 1
e.p = unset
e.pos.x = gx; e.pos.y = gy
else
e.c[3].x = gx; e.c[3].y = gy
EvalCBCD(e.pos, e.c, e.p)
e.a = atan2(e.pos.y, e.pos.x) - 0.5*PI
if e.p < 0.2 e.a = e.a*5*e.p
elseif e.p >= 0.8 e.a = e.a*(1 - e.p)/0.2
EvalCBC(e.pos, e.c, e.p)
endif
else
e.pos.x = gx
e.pos.y = gy
endif
endif
next
next
set color 0, 0, 0
cls
set color 255, 255, 255
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
e = enms[x][y]
if e and e.p = unset draw image e.img, e.pos.x, e.pos.y
next
for y = 0 to EROWS - 1 for x = 0 to ECOLS - 1
e = enms[x][y]
if e and typeof(e.p)
draw image xform e.img, e.pos.x + 7, e.pos.y + 7, 1, 1, e.a, 7, 7
endif
next
draw image plyImg, ply.pos.x, ply.pos.y
set color 255, 255, 255
foreach b in plybullets draw rect b.pos.x, b.pos.y, b.size.x, b.size.y, true
set color 0, 255, 255
foreach b in enmbullets draw rect b.pos.x, b.pos.y, b.size.x, b.size.y, true
set color 255, 255, 255
set caret 0, 0
wln sizeof(plybullets)
wln sizeof(enmbullets)
function CreateBitmap(data, r, g, b)
img = createimage(sizeof(data[0]), sizeof(data))
set image img
for y = 0 to sizeof(data) - 1 for x = 0 to sizeof(data[0]) - 1
set color data[y][x]*r, data[y][x]*g, data[y][x]*b
set pixel x, y
next
set image primary
set image colorkey img, 0, 0, 0
return img
endfunc
CONNECT 4
- Be the first player to get 4 of your chips in a row horizontally, vertically, or diagonally
- Connect 4 was invented by Howard Wexler and Ned Strongin in 1974
- It's a text based game, no graphics, no GUI, just an old classic terminal style game
Note :
Behold "asm...endasm" is in the program
Code:
'===========================================
'
' CONNECT 4 - ALMOST UNBEATABLE VERSION
' - Be the first player to get
' 4 of your chips in a row
' horizontally, vertically, or diagonally
' - Connect 4 was invented by
' Howard Wexler and Ned Strongin
' in 1974
'
' Note :
' Behold "asm...endasm" is in the program :)
'
'============================================
' constant
constant ROWS = 6 ' indices 0 to 5
constant COLS = 7 ' indices 0 to 6
constant CONNECT = 4
pln "CONNECT FOUR - Human (X) vs Computer (O)"
InitBoard()
turn = 0 ' Computer starts first
printBoard()
'-----------
' MAIN loop
'-----------
do
if turn = 1 then
' Human's turn
pln
write "Your move - Enter column (1 to "+ COLS+ "): "; cmd = rln(1,TYPE_NUMBER)
colInput = cmd
if colInput >= 1 and colInput <= COLS then
col0 = colInput - 1
if IsValidMove(col0) then
PlaceChip(1, col0)
pln "You placed in column "+ colInput
wait 2000
printBoard()
turn = 0
else
pln "Column is full! Try another."
endif
else
pln "Invalid column. Enter 1 to "+ COLS
endif
else
' Computer's turn
write "Computer is thinking..."
wait 300
AITurn()
printBoard()
turn = 1
endif
' Check win/draw
if CheckWinInColumn(1, -1) then
pln "You win! Congratulations!"
' mimic a gosub to label AskReplay
asm
move @0 AskReplay:
call @0
endasm
elseif CheckWinInColumn(2, -1) then
pln "Computer wins! Better luck next time."
' mimic a gosub to label AskReplay
asm
move @0 AskReplay:
call @0
endasm
elseif BoardFull() then
pln "It's a draw!"
' mimic a gosub to label AskReplay
asm
move @0 AskReplay:
call @0
endasm
endif
loop
'sub-routine
asm
AskReplay:
endasm
do
write "Play again? (Y/N)"; again = rln(1,TYPE_STRING)
pln
until upper(again)="Y" or upper(again)="N"
if upper(again) = "Y" then
again = "n"
InitBoard()
turn = 0 ' Computer starts again
printBoard()
' return to whereever we were called from.
asm
ret
endasm
else
pln "Thanks for playing! Goodbye!"
pln
system("pause")
end
endif
' -----------------------------
' functions
' -----------------------------
function InitBoard()
for r = 0 to ROWS - 1
for c = 0 to COLS - 1
board[r][c] = 0
next
next
endfunc
function printBoard()
pln
pln
for r = 0 to ROWS - 1
for c = 0 to COLS - 1
chip = " "
if board[r][c] = 1 then chip = "X"
if board[r][c] = 2 then chip = "O"
write "["+ chip+ "]"
next
pln
next
for c = 0 to COLS - 1
write " "+ (c + 1) + " "
next
pln
endfunc
function IsValidMove (col)
return (board[0][col] = 0)
endfunc
function PlaceChip (player, col)
for r = ROWS - 1 to 0 step -1
if board[r][col] = 0 then
board[r][col] = player
break
endif
next
endfunc
' Returns the row where a chip would land in column 'col'
function GetDropRow(col)
for r = ROWS - 1 to 0 step -1
if board[r][col] = 0 then
return r
endif
next
return -1
endfunc
' col = -1 ? full board check; else simulate move in col
function CheckWinInColumn (player, col)
if col = -1 then
for r = 0 to ROWS - 1
for c = 0 to COLS - 1
if board[r][c] = player then
if CheckPattern(player, r, c) then
return 1
break
endif
endif
next
next
return 0
endif
if not IsValidMove(col) then
return 0
endif
dropRow = -1
for r = ROWS - 1 to 0 step -1
if board[r][col] = 0 then
dropRow = r
break
endif
next
' Horizontal
if c <= COLS - CONNECT then
match = -1
for k = 0 to CONNECT - 1
if board[r][c + k] <> player then match = 0
next
if match then ok = -1
endif
' Vertical
if r <= ROWS - CONNECT then
match = -1
for k = 0 to CONNECT - 1
if board[r + k][c] <> player then match = 0
next
if match then ok = -1
endif
' Diagonal \
if r <= ROWS - CONNECT and c <= COLS - CONNECT then
match = -1
for k = 0 to CONNECT - 1
if board[r + k][c + k] <> player then match = 0
next
if match then ok = -1
endif
' Diagonal /
if r >= CONNECT - 1 and c <= COLS - CONNECT then
match = -1
for k = 0 to CONNECT - 1
if board[r - k][c + k] <> player then match = 0
next
if match then ok = -1
endif
return ok
endfunc
function BoardFull ()
full = 1
for c = 0 to COLS - 1
if board[0][c] = 0 then
full = 0
break
endif
next
return full
endfunc
' Returns winning column for 'player', or -1 if none
function FindWinningMove (player)
for c = 0 to COLS - 1
if IsValidMove(c) then
if CheckWinInColumn(player, c) then
return c
endif
endif
next
return -1
endfunc
' Evaluates the board from the perspective of 'player'
function EvaluateBoard(player)
opp = 3 - player ' opponent: 1<->2
score = 0
me2 = 0 ; me3 = 0
opp2 = 0 ; opp3 = 0
' --- Horizontal ---
for r = 0 to ROWS - 1
for c = 0 to COLS - CONNECT
me = 0 ; opponent = 0
for k = 0 to CONNECT - 1
cell = board[r][c + k]
if cell = player then me = me + 1
elseif cell = opp then opponent = opponent + 1
next
if opponent = 0 then
if me = 2 then me2 = me2 + 1
if me = 3 then me3 = me3 + 1
endif
if me = 0 then
if opponent = 2 then opp2 = opp2 + 1
if opponent = 3 then opp3 = opp3 + 1
endif
next
next
' --- Vertical ---
for c = 0 to COLS - 1
for r = 0 to ROWS - CONNECT
me = 0 ; opponent = 0
for k = 0 to CONNECT - 1
cell = board[r + k][c]
if cell = player then me = me + 1
elseif cell = opp then opponent = opponent + 1
next
if opponent = 0 then
if me = 2 then me2 = me2 + 1
if me = 3 then me3 = me3 + 1
endif
if me = 0 then
if opponent = 2 then opp2 = opp2 + 1
if opponent = 3 then opp3 = opp3 + 1
endif
next
next
' --- Diagonal \ ---
for r = 0 to ROWS - CONNECT
for c = 0 to COLS - CONNECT
me = 0 ; opponent = 0
for k = 0 to CONNECT - 1
cell = board[r + k][c + k]
if cell = player then me = me + 1
elseif cell = opp then opponent = opponent + 1
next
if opponent = 0 then
if me = 2 then me2 = me2 + 1
if me = 3 then me3 = me3 + 1
endif
if me = 0 then
if opponent = 2 then opp2 = opp2 + 1
if opponent = 3 then opp3 = opp3 + 1
endif
next
next
' --- Diagonal / ---
for r = CONNECT - 1 to ROWS - 1
for c = 0 to COLS - CONNECT
me = 0 ; opponent = 0
for k = 0 to CONNECT - 1
cell = board[r - k][c + k]
if cell = player then me = me + 1
elseif cell = opp then opponent = opponent + 1
next
if opponent = 0 then
if me = 2 then me2 = me2 + 1
if me = 3 then me3 = me3 + 1
endif
if me = 0 then
if opponent = 2 then opp2 = opp2 + 1
if opponent = 3 then opp3 = opp3 + 1
endif
next
next
' Improved AI turn
function AITurn()
col = -1
action = ""
' 1. Can computer win right now?
col = FindWinningMove(2)
if col >= 0 then
action = " (wins!)"
asm
jmp place_move:
endasm
endif
' 2. Must block human's immediate win?
col = FindWinningMove(1)
if col >= 0 then
action = " (blocks you!)"
asm
jmp place_move:
endasm
endif
' 3. Take center column (3) if available — strongest opening
if IsValidMove(3) then
col = 3
action = " (takes center)"
asm
jmp place_move:
endasm
endif
' 4. Evaluate all valid moves and pick best one
bestScore = -999999
bestCol = -1
for c = 0 to COLS - 1
if IsValidMove(c) then
r = GetDropRow(c)
board[r][c] = 2 ' simulate AI move
score = EvaluateBoard(2)
board[r][c] = 0 ' undo
if score > bestScore then
bestScore = score
bestCol = c
endif
endif
next
if bestCol >= 0 then
col = bestCol
action = " (strategic)"
else
'random (should never happen)
do
col = int(rnd() * COLS)
until IsValidMove(col)
action = " (fallback)"
endif
' Set screen size (in a graphics environment) SET SCREEN 800, 536
' Initialize score
score = 0
' Main game loop
LABEL mainLoop
' Move enemy sprites using WHILE loop
i = 2
WHILE i < 6
spriteX[i] = spriteX[i] + spriteSpeedX[i]
spriteY[i] = spriteY[i] + spriteSpeedY[i]
' Bounce on edges (assuming screen size 800x536)
IF spriteX[i] <= 0 OR spriteX[i] + spriteWidth[i] >= 800 THEN
spriteSpeedX[i] = -spriteSpeedX[i]
ENDIF
IF spriteY[i] <= 0 OR spriteY[i] + spriteHeight[i] >= 536 THEN
spriteSpeedY[i] = -spriteSpeedY[i]
ENDIF
i = i + 1
WEND
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