Prove me wrong (DBC, possibly pro, no media required)...
Old Code
sync on
ink rgb(255,255,255),0
dim box(9)
do
for x=1 to 3
for y=1 to 3
if turn=0 and mousex()>x*100 and mousex()<x*100+100 and mousey()>y*100 and mousey()<y*100+100 and mouseclick()=1 and box((x-1)*3+y)=0 then box((x-1)*3+y)=1:turn=1:inc players_go
if box((x-1)*3+y)=1
line x*100,y*100,x*100+100,y*100+100
line x*100,y*100+100,x*100+100,y*100
endif
if box((x-1)*3+y)=2
circle x*100+50,y*100+50,45
endif
next y
next x
if turn=1
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="022" then box(1+(x-1)*3)=2:goto win
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="202" then box(2+(x-1)*3)=2:goto win
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="220" then box(3+(x-1)*3)=2:goto win
next x
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="022" then box(y)=2:goto win
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="202" then box(y+3)=2:goto win
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="220" then box(y+6)=2:goto win
next y
if str$(box(1))+str$(box(5))+str$(box(9))="022" then box(1)=2:goto win
if str$(box(1))+str$(box(5))+str$(box(9))="202" then box(5)=2:goto win
if str$(box(1))+str$(box(5))+str$(box(9))="220" then box(9)=2:goto win
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="011" then box(1+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="101" then box(2+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="110" then box(3+(x-1)*3)=2:goto moved
next x
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="011" then box(y)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="101" then box(y+3)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="110" then box(y+6)=2:goto moved
next y
if str$(box(1))+str$(box(5))+str$(box(9))="011" then box(1)=2:goto moved
if str$(box(1))+str$(box(5))+str$(box(9))="101" then box(5)=2:goto moved
if str$(box(1))+str$(box(5))+str$(box(9))="110" then box(9)=2:goto moved
if players_go=1
if box(5)=1 then box(3)=2:goto moved:else:box(5)=2:goto moved
endif
if players_go=2
if box(8)=1 and box(3)=1 then box(9)=2:goto moved
if box(8)=1 and box(1)=1 then box(7)=2:goto moved
if box(6)=1 and box(1)=1 then box(3)=2:goto moved
if box(6)=1 and box(7)=1 then box(9)=2:goto moved
if box(4)=1 and box(3)=1 then box(1)=2:goto moved
if box(4)=1 and box(9)=1 then box(7)=2:goto moved
if box(2)=1 and box(7)=1 then box(1)=2:goto moved
if box(2)=1 and box(9)=1 then box(3)=2:goto moved
endif
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="002" then box(1+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="020" then box(3+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="200" then box(1+(x-1)*3)=2:goto moved
next x
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="002" then box(y)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="020" then box(y+6)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="200" then box(y+6)=2:goto moved
next y
for x=1 to 9
if box(x)=0 then box(x)=2:goto moved
next x
moved:
turn=0
endif
full=1
for x=1 to 9
if box(x)=0 then full=0
next x
if full=1 then goto draw
line 100,100,100,400
line 200,100,200,400
line 300,100,300,400
line 400,100,400,400
line 100,100,400,100
line 100,200,400,200
line 100,300,400,300
line 100,400,400,400
sync
cls
loop
win:
do
for x=1 to 3
for y=1 to 3
if box((x-1)*3+y)=1
line x*100,y*100,x*100+100,y*100+100
line x*100,y*100+100,x*100+100,y*100
endif
if box((x-1)*3+y)=2
circle x*100+50,y*100+50,45
endif
next y
next x
line 100,100,100,400
line 200,100,200,400
line 300,100,300,400
line 400,100,400,400
line 100,100,400,100
line 100,200,400,200
line 100,300,400,300
line 100,400,400,400
text 20,20,"The Computer Wins!"
sync
loop
draw:
do
for x=1 to 3
for y=1 to 3
if box((x-1)*3+y)=1
line x*100,y*100,x*100+100,y*100+100
line x*100,y*100+100,x*100+100,y*100
endif
if box((x-1)*3+y)=2
circle x*100+50,y*100+50,45
endif
next y
next x
line 100,100,100,400
line 200,100,200,400
line 300,100,300,400
line 400,100,400,400
line 100,100,400,100
line 100,200,400,200
line 100,300,400,300
line 100,400,400,400
text 20,20,"It's a Draw"
sync
loop
This one is updated and has the bugs fixed and is set out neater and is remarked.
New Code
rem ***********************
rem * NOUGHTS AND CROSSES *
rem ***********************
rem * By Hamish McHaggis *
rem ***********************
rem *** This is a demo that is unbeatable hopefully and shows how to do simple AI in a game ***
rem Setup Stuff
sync on
ink rgb(255,255,255),0
dim box(9)
rem Restart label
start:
rem Reset variables and arrays
turn=0
players_go=0
for x=1 to 9
box(x)=0
next x
rem Main loop
do
rem Loop though all squares and fill appropriately
for x=1 to 3
for y=1 to 3
rem If the mouse is clicked on a square, if it isn't filled then fill it
if turn=0 and mousex()>x*100+60 and mousex()<x*100+160 and mousey()>y*100 and mousey()<y*100+100 and mouseclick()=1 and box((x-1)*3+y)=0 then box((x-1)*3+y)=1:turn=1:inc players_go
rem Draw crosses
if box((x-1)*3+y)=1
line x*100+60,y*100,x*100+160,y*100+100
line x*100+60,y*100+100,x*100+160,y*100
endif
rem Draw noughts
if box((x-1)*3+y)=2
circle x*100+110,y*100+50,45
endif
next y
next x
center text 320,20,"NOUGHTS AND CROSSES"
center text 320,40,"By Hamish McHaggis"
rem If it is the computers turn
if turn=1
rem Loop though columns testing for winning combinations
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="022" then box(1+(x-1)*3)=2:goto win
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="202" then box(2+(x-1)*3)=2:goto win
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="220" then box(3+(x-1)*3)=2:goto win
next x
rem Loop though rows testing for winning combinations
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="022" then box(y)=2:goto win
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="202" then box(y+3)=2:goto win
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="220" then box(y+6)=2:goto win
next y
rem Test for winning combinations diagonally
if str$(box(1))+str$(box(5))+str$(box(9))="022" then box(1)=2:goto win
if str$(box(1))+str$(box(5))+str$(box(9))="202" then box(5)=2:goto win
if str$(box(1))+str$(box(5))+str$(box(9))="220" then box(9)=2:goto win
if str$(box(3))+str$(box(5))+str$(box(7))="022" then box(3)=2:goto win
if str$(box(3))+str$(box(5))+str$(box(7))="202" then box(5)=2:goto win
if str$(box(3))+str$(box(5))+str$(box(7))="220" then box(7)=2:goto win
rem Loop though columns testing for blocking combinations
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="011" then box(1+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="101" then box(2+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="110" then box(3+(x-1)*3)=2:goto moved
next x
rem Loop though rows testing for blocking combinations
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="011" then box(y)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="101" then box(y+3)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="110" then box(y+6)=2:goto moved
next y
rem Test for blocking combinations diagonally
if str$(box(1))+str$(box(5))+str$(box(9))="011" then box(1)=2:goto moved
if str$(box(1))+str$(box(5))+str$(box(9))="101" then box(5)=2:goto moved
if str$(box(1))+str$(box(5))+str$(box(9))="110" then box(9)=2:goto moved
if str$(box(3))+str$(box(5))+str$(box(7))="011" then box(3)=2:goto moved
if str$(box(3))+str$(box(5))+str$(box(7))="101" then box(5)=2:goto moved
if str$(box(3))+str$(box(5))+str$(box(7))="110" then box(7)=2:goto moved
rem If there are no winning or blocking combinations then test other options
rem If player has had 1 go and hasn't placed in the middle then place in the middle otherwise place in a corner
if players_go=1
if box(5)=1 then box(3)=2:goto moved:else:box(5)=2:goto moved
endif
rem If player has had 2 gos then test other combinations
if players_go=2
rem Test the middle side, left other side possibility (see bottom for details)
if box(8)=1 and box(3)=1 then box(9)=2:goto moved
if box(8)=1 and box(1)=1 then box(7)=2:goto moved
if box(6)=1 and box(1)=1 then box(3)=2:goto moved
if box(6)=1 and box(7)=1 then box(9)=2:goto moved
if box(4)=1 and box(3)=1 then box(1)=2:goto moved
if box(4)=1 and box(9)=1 then box(7)=2:goto moved
if box(2)=1 and box(7)=1 then box(1)=2:goto moved
if box(2)=1 and box(9)=1 then box(3)=2:goto moved
rem Test middle, perpendicular sides possibility (see bottom for details)
if box(2)=1 and box(6)=1 then box(3)=2:goto moved
if box(2)=1 and box(4)=1 then box(1)=2:goto moved
if box(6)=1 and box(8)=1 then box(9)=2:goto moved
if box(4)=1 and box(8)=1 then box(7)=2:goto moved
endif
rem If there aren't any defensive or offensive moves available then test for other moves
rem Loop through columns for open columns to place in
for x=1 to 3
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="002" then box(1+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="020" then box(3+(x-1)*3)=2:goto moved
if str$(box(1+(x-1)*3))+str$(box(2+(x-1)*3))+str$(box(3+(x-1)*3))="200" then box(1+(x-1)*3)=2:goto moved
next x
rem Loop through rows for open rows to place in
for y=1 to 3
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="002" then box(y)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="020" then box(y+6)=2:goto moved
if str$(box(y))+str$(box(y+3))+str$(box(y+6))="200" then box(y+6)=2:goto moved
next y
rem If there are none of the above options then loop through all squares and place in the first one available
for x=1 to 9
if box(x)=0 then box(x)=2:goto moved
next x
rem Label for computer to go to when it's made it's move
moved:
rem Turn computer's go off
turn=0
endif
rem Test to see if the grid is full
full=1
for x=1 to 9
if box(x)=0 then full=0
next x
rem If the grid is full then declare a draw (winning is impossible, hopefully)
if full=1 then goto draw
rem Draw grid
line 160,100,160,400
line 260,100,260,400
line 360,100,360,400
line 460,100,460,400
line 160,100,460,100
line 160,200,460,200
line 160,300,460,300
line 160,400,460,400
rem Refresh and loop
sync
cls
loop
rem Display stuff for winning
win:
do
rem Draw crosses and noughts
for x=1 to 3
for y=1 to 3
rem Draw crosses
if box((x-1)*3+y)=1
line x*100+60,y*100,x*100+160,y*100+100
line x*100+60,y*100+100,x*100+160,y*100
endif
rem Draw noughts
if box((x-1)*3+y)=2
circle x*100+110,y*100+50,45
endif
next y
next x
rem Draw grid
line 160,100,160,400
line 260,100,260,400
line 360,100,360,400
line 460,100,460,400
line 160,100,460,100
line 160,200,460,200
line 160,300,460,300
line 160,400,460,400
center text 320,20,"NOUGHTS AND CROSSES"
center text 320,40,"By Hamish McHaggis"
center text 320,220,"The Computer Wins!"
center text 320,240,"Press Return to Restart"
if returnkey()=1 then goto start
sync
cls
loop
rem Display stuff for drawing
draw:
do
rem Draw crosses and noughts
for x=1 to 3
for y=1 to 3
rem Draw crosses
if box((x-1)*3+y)=1
line x*100+60,y*100,x*100+160,y*100+100
line x*100+60,y*100+100,x*100+160,y*100
endif
rem Draw noughts
if box((x-1)*3+y)=2
circle x*100+110,y*100+50,45
endif
next y
next x
rem Draw grid
line 160,100,160,400
line 260,100,260,400
line 360,100,360,400
line 460,100,460,400
line 160,100,460,100
line 160,200,460,200
line 160,300,460,300
line 160,400,460,400
center text 320,20,"NOUGHTS AND CROSSES"
center text 320,40,"By Hamish McHaggis"
center text 320,220,"It's a Draw"
center text 320,240,"Press Return to Restart"
if returnkey()=1 then goto start
sync
cls
loop
Why the hell'd you ask me for crying out loud!?!