rem ********************** rem **** gridgame solver **** rem ********************** rem **setup** luc=3 currentinc=3 totaldepth=3 dim working(20,2) gosub clearworking gosub alternatestart dim start(5,4) dim grid (5,4) for y=1 to 4 for x=1 to 5 read start(x,y):grid(x,y)=start(x,y) next x next y data 0,1,1,0,1,1,0,1,1,0,0,1,0,1,1,1,0,0,1,1 print print "Starting..." rem **start** compsdone=1 label loopx:rem ***main x loop for bottom level*** rem ***this is where the flip all relevant levels and check comes in*** print compsdone;:print" "; for a=1 to totaldepth:print working(a,1);:print working(a,2);:print" ";:next a:print gosub setupboard gosub checkoutcome compsdone=compsdone+1 working(luc,1)=(working(luc,1)+1) if working (luc,1)=6 then goto loopy:rem **reached the end of a line of xs** else endif goto loopx label loopy: rem ***main y loop for bottom level*** working(luc,1)=1:rem **reset the x** working(luc,2)=(working(luc,2)+1) if working (luc,2)=5 then goto endofys else endif goto loopx label endofys:rem **xloop at endofys** currentinc=currentinc-1 working(currentinc,1)=(working(currentinc,1)+1) if working (currentinc,1)=6 then goto endofysyloop else currentinc=currentinc+1:gosub resetrest endif goto loopx label endofysyloop working (currentinc,1)=1 working(currentinc,2)=(working(currentinc,2)+1) if working (currentinc,2)=5 then goto endofoneabove else currentinc=currentinc+1:gosub resetrest endif goto loopx label endofoneabove: rem **now the level above is 5,4** if currentinc=1 then goto goingdown:endif working (currentinc,1)=1:working(currentinc,2)=1:rem **reset the present level** working (currentinc-1,1)=(working (currentinc-1,1))+1: rem ** increase the next x up** if working (currentinc-1,1)=6 then goto endofoneaboveys else currentinc=currentinc+1:currentinc=totaldepth:gosub resetrest endif goto loopx label endofoneaboveys: rem **increase the ys in the level above** working (currentinc,1)=1:working(currentinc,2)=1:rem **reset the present level** working (currentinc-1,2)=(working (currentinc-1,2))+1: rem ** increase the next y up** working (currentinc-1,1)=1:rem **and reset the x** if working (currentinc-1,2)=5 then currentinc=currentinc-1:goto endofoneabove else currentinc=currentinc+1:currentinc=totaldepth:gosub resetrest endif goto loopx rem ***I suspect we never call goingupx***** label goingupx: rem **level above is 5,4** print "currentinc=";:print currentinc if currentinc=2 then goto goingdown :rem **are we at top?** else currentinc=currentinc-1 working (currentinc-1,1)=(working (currentinc-1,1))+1 if working (currentinc-1,1)=6 then goto goingupy else gosub resetrest currentinc=totaldepth endif goto loopx label goingupy: rem **so the level above that is at end of xs** working (currentinc-1,1)=1:rem **reset the x above** working (currentinc-1,2)=(working (currentinc-1,2))+1 if working (currentinc-1,2)=5 then currentinc=currentinc-1:goto goingupx else gosub resetrest currentinc=totaldepth endif goto loopx label resetrest for a=currentinc to totaldepth working (a,1)=1:working(a,2)=1 next a return label goingdown totaldepth=totaldepth+1 for a=1 to totaldepth: working (a,1)=1:working(a,2)=1:next a luc=totaldepth currentinc=totaldepth goto loopx endif: rem **somehow I don't think this will assist!, it's a spurious endif** label clearworking for a=1 to 20 working(a,1)=1:working(a,2)=1 next a return label flip rem ****this will execute a flip for inputs flx,fly***** for xx=1 to 5 for yy=1 to 4 flipdone=0 if xx=flx then grid (xx,yy)=(grid (xx,yy)+1):flipdone=1endif if grid (xx,yy)=2 then grid(xx,yy)=0:endif if (flipdone=0 and yy=fly) then grid (xx,yy)=(grid (xx,yy)+1):endif if grid (xx,yy)=2 then grid(xx,yy)=0:endif next yy next xx return label printgrid for tt=1 to 4 for uu=1 to 5 print grid(uu,tt); next uu print next tt print return label resetgrid for y=1 to 4 for x=1 to 5 grid(x,y)=start(x,y) next x next y return label checkoutcome count=0 yesxo=0 yesxi=0 yesyo=0 yesyi=0 yescount=0 yrest=0 yrestt=0 xrest=0 xrestt=0 for t=1 to 4 xxx=0 for u=1 to 5 count=count+grid(u,t) xxx=xxx+grid(u,t) mmm=(grid(u,1)+grid(u,2)+grid(u,3)+grid(u,4)) if mmm=0 then yesyo=1:endif if mmm=4 then yesyi=1:endif if mmm>1 and mmm<4 then yrest=1:endif if mmm<3 and mmm>1 then yrestt=1:endif next u if xxx=0 then yesxo=1:endif if xxx=5 then yesxi=1:endif if xxx>1 and xxx<5 then xrest=1:endif if xxx<4 and xxx>1 then xrestt=1:endif next t if (count=8 or count=12) then yescount=1:endif if yesxi=1 and yesyi=1 and yescount=1 and yrest=0 and xrest=0 then print "Looks like a prewin...":goto win:endif if yesxo=1 and yesyo=1 and yescount=1 and yrestt=0 and xrestt=0 then print "Looks like a prewin...":goto win:endif if (count=20 or count=0) then goto win endif gosub resetgrid return label setupboard rem **this puts the board into the correct state given the flips which have occured** for n=1 to totaldepth flx=working(n,1):fly=working(n,2) gosub flip next n return label win for a=1 to totaldepth print working (a,1);:print working (a,2);:print " "; next a print gosub printgrid print print "win" label hang goto hang end label prewin for a=1 to totaldepth print working (a,1);:print working (a,2);:print " "; next a input a$ gosub resetgrid return label printvars print print "totaldepth=";:print totaldepth print "levelunderconsid=";:print luc print "currentinc=";:print currentinc print input a$ return label alternatestart totaldepth=4 luc=4 currentinc=4 for a=2 to 4 working (a,1)=5:working (a,2)=4 next a working (1,1)=5:working (1,2)=4 print "alternatestart" input a$ return label testit for y=1 to 4 for x=1 to 5 grid(x,y)=1 next x next y grid (3,1)=0:grid(3,2)=0:grid(3,3)=0:grid(3,4)=0 grid (1,2)=0:grid (2,2)=0:grid(4,2)=0:grid(5,2)=0 gosub printgrid gosub checkoutcome print "oh it didn't find it" label stopper goto stopper