Polychrome is a game where you try to beat your computer in thinking. I posted the first Polychrome in the 20 line challenge and the I did alot of work on it:
Smarter A.I.
Title screen
Adjustable difficulty
Better color scheme
sync rate 0
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
global blacksize as integer
global whitesize as integer
global lum as integer
global ai as integer
set text font "Courier New"
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
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
blacksize=5
whitesize=5
ai=10
set text size 40
cls
lum=0
stop=0
do
if stop=0 then lum=lum+1 else lum=lum-1
if lum>255 then lum=255:stop=1
if lum<0 then lum=0:stop=0
box 0,0,639,479,rgb(lum,lum,lum),rgb(255-lum,255-lum,255-lum),rgb(lum,lum,lum),rgb(255-lum,255-lum,255-lum)
ink rgb(0,255,255),0
center text 320,20,"Polychrome"
center text 320,400,"Start"
if mousex()>260 and mousex()<380 and mousey()>400 and mousey()<440 and mouseclick()=1 then exit
ink rgb(0,255,0),0
text 140,100,"AI |----------|"
text 140,140," "+space(ai)+"^"+str$(ai)
text 140,180,"WHITE |----------|"
text 140,220," "+space(whitesize)+"^"+str$(whitesize)
text 140,260,"BLACK |----------|"
text 140,300," "+space(blacksize)+"^"+str$(blacksize)
if mousex()>335 and mousex()<550 and mouseclick()=1
if mousey()>100 and mousey()<180 then ai=(mousex()-300)/23.5
if mousey()>180 and mousey()<260 then whitesize=(mousex()-300)/23.5
if mousey()>260 and mousey()<340 then blacksize=(mousex()-300)/23.5
endif
sync
cls
loop
stop=50
set text size 20
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)=-1 then ink 0,0:black=black+1
box (x-1)*24+160,(y-1)*24,x*24-1+160,y*24-1
if grid(x,y)=0 then box (x-1)*24+160,(y-1)*24,x*24-1+160,y*24-1,rgb(146,146,146),rgb(114,114,114),rgb(114,114,114),rgb(146,146,146)
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+(whitesize-2))*24+172,(sy-1)*24+12
else
line (sx-1)*24+172,(sy-1)*24+12,(sx-1)*24+172,(sy+(blacksize-2))*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>21-whitesize then sx=21-whitesize
if sy>20 then sy=20
endif
if mouseclick()=1
REM Change states in a line pattern
for g=0 to whitesize-1
state(sx+g,sy,1)
next g
REM Pause.
stop=50
REM Change turns.
turn=1
endif
else
REM Use a complex process to
REM calculate the AIs move.
t=-100
dx=0
dy=0
for sx=1 to 20
for sy=1 to 21-blacksize
if ai<>10 then b=rnd(10-ai)*3 else b=0
for g=0 to blacksize-1
a=grid(sx,sy+g)
if a=0 then b=b+8
if a=-1 then b=b-8
for bx=1 to whitesize-1
if sx+bx<=20 and grid(sx+bx,sy+g)=0 then b=b+1
if sx-bx=>1 and grid(sx-bx,sy+g)=0 then b=b+1
next bx
next g
if b>t then t=b:dx=sx:dy=sy
next sy
next sx
sx=dx
sy=dy
REM Change states in a line pattern
for g=0 to blacksize-1
state(sx,sy+g,-1)
next g
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
function space(num)
line$=""
for t=1 to num
line$=line$+" "
next t
endfunction line$
If you haven't seen the first, Polychrome is a game where you try to fill up a 20*20 grid with white as fast as you can. The first player to reach the "tiles to win" mark wins. You fill up the grid by placing a 1*5 stencil on the grid. Your computer places a 5*1 stencil too. In the stencil all gray block will turn white and every other color will turn black(bad color), while your computer tries to color the board black. You take the first turn.
CAN YOU WIN?
.exe attached
edited to include sync on
From the office of... Dr. Schnitzengruber