Hello,
this is my second attempt at creating AI in 20 lines.
Here is the code:
`&&&&&&&&&&&&&&&&&&&&&&&&&&&
`&&&&&&& CONNECT 4 &&&&&&&&&
`&&&&& By: Michael K. &&&&&&
`&&& 20 Lines Challange &&&&
`&&&&&&&&&&&&&&&&&&&&&&&&&&&
sync on:load image "board.jpg",1:load image "2.jpg",2:load image "1.jpg",3:dim board(7,6)
turn=2:ink rgb(0,0,0),0:do:for p=2 to 30:for x=1 to 7
for y=1 to 6:if x>=3 :If board(x,y)=p and board(x-1,y)=p and board(x-2,y)=p and board(x-3,y)=p then end:endif
if y>=3 :If board(x,y)=p and board(x,y-1)=p and board(x,y-2)=p and board(x,y-3)=p then end:endif
if x>=3 and y>=3:if board(x,y)=p and board(x-1,y-1)=p and board(x-2,y-2)=p and board(x-3,y-3)=p then end:endif
if x>=3 and y>=3:if board(x,y)=p and board(x+1,y-1)=p and board(x+2,y-2)=p and board(x+3,y-3)=p then end:endif
next y:next x:next p:if turn=2:if mouseclick()=1
for i=1 to 6:if board(area,7-i)=0 then board(area,7-i)=turn:gosub drop:turn=1:exit
next i:endif:endif:if turn=1:area=rnd(6)+1
for x=1 to 7:for y=1 to 6:if x>=3:If board(x,y)=2 and board(x-1,y)=2 and board(x-2,y)=2 and board(x-3,y)=0 then area=x-3:exit:exit:endif
if y>=3:if board(x,y)=2 and board(x,y-1)=2 and board(x,y-2)=2 and board(x,y-3)=0 then area=x:endif:if x>=3 and y>=3:if board(x,y)=2 and board(x-1,y-1)=2 and board(x-2,y-2)=2 and board(x-3,y-3)=0 and board(x-3,y-2)>0 then area=x-3
endif:if x>=3 and y>=3:if board(x,y)=2 and board(x+1,y-1)=2 and board(x+2,y-2)=2 and board(x+3,y-3)=0 and board(x+3,y-2)>0 then area=x+3:endif
next y:next x:for i=1 to 6:if board(area,7-i)=0 then board(area,7-i)=turn:gosub drop:turn=turn+1:exit
next i:turn=2:endif:for i=0 to 6:if mouseX()=>i*91 and mouseX()<i*91+91:area=i+1
endif:next i:sprite 2,0,0,1:box (area-1)*91,0,(area-1)*91+91,479
for i=0 to 6:for x=0 to 7:if board(x,i)>0 then paste image board(x,i)+1,X*91+10-91,I*80+7-80
next x:next i:return:sync:loop
drop:
for n=0 to 6-i:paste image turn+1,(area-1)*91+10,n*80+7:sync:box (area-1)*91,n*80,(area-1)*91+91,n*80+80:next n
return
Here you can download source/Media:
http://piratss.freewebspace.com
Here is a
compiled version of Connect 4.
http://www24.brinkster.com/piratss/Compiled.html
Note: My Board has funny colors for some reason.
Here is a screenshot of Connect 4:
http://www24.brinkster.com/piratss/Screenshot.html
This works for DBC, I am not sure about DBPro,
so if anyone want to give it a try.
Computer AI is not bad, and it was very hard to fit in 20 lines.
1PH J00 C4|\| U|\|dER$T@|\||) +|-|I$, j00 |-|@\/3 4lR3Ady w0|\|! - p1r@T$$