This is the
highly-annotated decompressed version of the game:
DBPro:
sync rate 100
sync on
REM The basic idea for this game
REM is a AI vs. player board game.
REM The game has a 20*20 grid of
REM tiles that can be 3 states(-1,0,1).
dim grid(21,21) as integer
REM Refrence
global sx as integer
global sy as integer
global tiles as integer
global turn as integer
global white as integer
global black as integer
global stop as integer
REM This game can be played as many times
REM as you want before you close the application,
REM so there needs to be a loop
do
set text size 20
REM All tiles start at a
REM neutral state(0)
for x=1 to 20
for y=1 to 20
grid(x,y)=0
next y
next x
REM To make the game better,
REM it needs flexible victory conditions.
REM At the start of a game you would need 210
REM tiles of 1 state to win.
tiles=210
REM You get the first turn.
turn=0
sx=1
sy=1
stop=0
REM Main game loop
do
REM Paint a grid.
ink rgb(0,0,255),0
for t=0 to 21
line 159+(t*24),0,159+(t*24),479
next t
for t=1 to 21
line 159,t*24-1,639,t*24-1
next t
REM Paint tiles to grid.
REM Color by states.
REM -1=black,0=gray,1=white
REM Also take count of states
white=0
black=0
for x=1 to 20
for y=1 to 20
if grid(x,y)=1 then ink rgb(255,255,255),0:white=white+1
if grid(x,y)=0 then ink rgb(128,128,128),0
if grid(x,y)=-1 then ink 0,0:black=black+1
box (x-1)*24+160,(y-1)*24,x*24-1+160,y*24-1
next y
next x
REM Print stats.
ink rgb(0,255,0),0
center text 80,0,"Tiles To Win:"+str$(tiles)
center text 80,20,"White Tiles:"+str$(white)
center text 80,40,"Black Tiles:"+str$(black)
center text 80,60,"W+W=B"
center text 80,80,"W+G=W"
center text 80,100,"W+B=B"
REM VICTORY!!!
if (white=>tiles or black=>tiles) and turn=0 then exit
REM show selection
ink rgb(0,255,0),0
if turn=0
line (sx-1)*24+172,(sy-1)*24+12,(sx+3)*24+172,(sy-1)*24+12
else
line (sx-1)*24+172,(sy-1)*24+12,(sx-1)*24+172,(sy+3)*24+12
endif
REM Check if game paused
if stop=0
REM Decide on who's turn it is.
if turn=0
REM It's your turn. Use
REM your mouse to select a group of tiles.
if mousex()>159
REM Do calculations to find out which tile you selected
sx=mousex()-160
sy=mousey()
sx=sx/24
sy=sy/24
sx=sx+1
sy=sy+1
if sx>16 then sx=16
if sy>20 then sy=20
endif
if mouseclick()=1
REM Change states in a line pattern
state(sx,sy,1)
state(sx+1,sy,1)
state(sx+2,sy,1)
state(sx+3,sy,1)
state(sx+4,sy,1)
REM Pause.
stop=50
REM Change turns.
turn=1
endif
else
REM Use a complex process to
REM calculate the AIs move.
t=51
do
t=t-1
for sx=1 to 20
for sy=1 to 16
b=0
for g=0 to 4
a=grid(sx,sy+g)
if a=0 then b=b+8
if a=-1 then b=b-8
if sx<20 and grid(sx+1,sy+g)=0 then b=b+1
if sx>1 and grid(sx-1,sy+g)=0 then b=b+1
next g
if b=>t then exit
next sy
if b=>t then exit
next sx
if b=>t then exit
loop
REM Change states in a line pattern
state(sx,sy,-1)
state(sx,sy+1,-1)
state(sx,sy+2,-1)
state(sx,sy+3,-1)
state(sx,sy+4,-1)
REM Pause.
stop=50
REM Change turns.
turn=0
endif
else
stop=stop-1
endif
REM At the end of each loop use a "sync" command
REM to switch the backbuffer and screen.
REM Then use the "cls" command to setup
REM the backbuffer.
sync
cls
loop
set text size 40
ink rgb(255,0,0),0
if white>black then center text 400,240,"YOU WIN" else center text 400,240,"YOU LOSE"
sync
sleep 5000
loop
REM This function changes the state of a tile.
function state(x,y,a)
if grid(x,y)=a
grid(x,y)=0-a
else
if grid(x,y)=0
grid(x,y)=a
else
tiles=tiles-1
endif
endif
endfunction
DBC:
sync rate 60
sync on
REM The basic idea for this game
REM is a AI vs. player board game.
REM The game has a 20*20 grid of
REM tiles(0) that can be 3 states(-1,0,1).
dim grid(21,21)
REM This game can be played as many times
REM as you want before you close the application,
REM so there needs to be a loop
do
set text size 20
REM All tiles start at a neutral state(0)
for x=1 to 20
for y=1 to 20
grid(x,y)=0
next y
next x
REM To make the game better,
REM it needs flexible victory conditions.
REM At the start of a game you would need 210
REM tiles of 1 state to win.
DIM tiles(0)
tiles(0)=20
REM You get the first turn.
turn=0
sx=1
sy=1
stop=0
REM Main game loop
do
REM Paint a grid.
ink rgb(0,0,255),0
for t=0 to 21
line 159+(t*24),0,159+(t*24),479
next t
for t=1 to 21
line 159,t*24-1,639,t*24-1
next t
REM Paint tiles to grid.
REM Color by states.
REM -1=black,0=gray,1=white
REM Also take count of states
white=0
black=0
for x=1 to 20
for y=1 to 20
if grid(x,y)=1 then ink rgb(255,255,255),0:white=white+1
if grid(x,y)=0 then ink rgb(128,128,128),0
if grid(x,y)=-1 then ink 0,0:black=black+1
box (x-1)*24+160,(y-1)*24,x*24-1+160,y*24-1
next y
next x
REM Print stats.
ink rgb(0,255,0),0
center text 80,0,"tiles To Win:"+str$(tiles(0))
center text 80,20,"White tiles:"+str$(white)
center text 80,40,"Black tiles:"+str$(black)
center text 80,60,"W+W=B"
center text 80,80,"W+G=W"
center text 80,100,"W+B=B"
REM VICTORY!!!
if (white=>tiles(0) or black=>tiles(0)) and turn=0 then exit
REM show selection
ink rgb(0,255,0),0
if turn=0
line (sx-1)*24+172,(sy-1)*24+12,(sx+3)*24+172,(sy-1)*24+12
else
line (sx-1)*24+172,(sy-1)*24+12,(sx-1)*24+172,(sy+3)*24+12
endif
REM Check if game paused
if stop=0
REM Decide on who's turn it is.
if turn=0
REM It's your turn. Use
REM your mouse to select a group of tiles(0).
if mousex()>159
REM Do calculations to find out which tile you selected
sx=mousex()-160
sy=mousey()
sx=sx/24
sy=sy/24
sx=sx+1
sy=sy+1
if sx>16 then sx=16
if sy>20 then sy=20
endif
if mouseclick()=1
REM Change states in a line pattern
state(sx,sy,1)
state(sx+1,sy,1)
state(sx+2,sy,1)
state(sx+3,sy,1)
state(sx+4,sy,1)
REM Pause.
stop=50
REM Change turns.
turn=1
endif
else
REM Use a complex process to
REM calculate the AIs move.
t=51
do
t=t-1
for sx=1 to 20
for sy=1 to 16
b=0
for g=0 to 4
a=grid(sx,sy+g)
if a=0 then b=b+8
if a=-1 then b=b-8
if sx<20 and grid(sx+1,sy+g)=0 then b=b+1
if sx>1 and grid(sx-1,sy+g)=0 then b=b+1
next g
if b=>t then exit
next sy
if b=>t then exit
next sx
if b=>t then exit
loop
REM Change states in a line pattern
state(sx,sy,-1)
state(sx,sy+1,-1)
state(sx,sy+2,-1)
state(sx,sy+3,-1)
state(sx,sy+4,-1)
REM Pause.
stop=50
REM Change turns.
turn=0
endif
else
stop=stop-1
endif
REM At the end of each loop use a "sync" command
REM to switch the backbuffer and screen.
REM Then use the "cls" command to setup
REM the backbuffer.
sync
cls
loop
set text size 40
ink rgb(255,0,0),0
if white>black then center text 400,240,"YOU WIN" else center text 400,240,"YOU LOSE"
sync
loop
REM This function changes the state of a tile.
function state(x,y,a)
if grid(x,y)=a
grid(x,y)=0-a
else
if grid(x,y)=0
grid(x,y)=a
else
tiles(0)=tiles(0)-1
endif
endif
endfunction
If everything was back to normal, it would happen again.