#!/usr/local/bin/yabasic
rem programmed by Hermang Mansilla,1998 released under GNU Public License
rem version 0.5, graphic version in development :-)
difficulty=775
dim board(7,7)
input "Size of the Board [3,4,5]" size
blank =size*size
gosub InitBoard : rem this put the board in order
print "Press q to quit, arrows to move a letter to the empty space"
print "The goal of the game is to arrange the board this way :"
gosub PrintBoard
input "Press Enter key to continue" dummy$
print "Wait, mixing the puzzle ..."
gosub MixBoard
Label Playit
  clear screen
  gosub PrintBoard
  gosub KeyEvent
  if board(blankrow+dy ,blankcol+dx)<> -1 then gosub Slide fi
goto Playit
end

label InitBoard
for row=1 to 7
for col=1 to 7
board(row,col)=-1
next col
next row
for i= 1 to blank
row=int((i-1)/size)+2
col=mod(i-1,size)+2
board(row,col)=i
if i=blank then
blankrow=row
blankcol=col
fi
next i
return

Label PrintBoard
print "\n"
for row=1 to size+2
for col=1 to size+2
if board(row,col)=-1 then
print " *   ";
else
    if row=blankrow and col=blankcol then
    print "     ";
    else
       print " ",chr$(64+board(row,col)),"   ";
rem    print str$(board(row,col),"%2.0f"),"   ";
    fi
fi
next col
print "\n"
next row
print "\n"
return

Label KeyEvent
label eventloop
dx=0:dy=0
k$=inkey$
if k$="q" then end fi
opt=instr("udlr",mid$(k$,1,1))
if k$="up" then dy=1 fi
if k$="down" then dy=-1 fi
if k$="left" then dx=1 fi
if k$="right" then dx=-1 fi
if opt<1 then goto eventloop fi
return

Label Slide
tmp = board(blankrow+dy ,blankcol+dx)
board(blankrow+dy ,blankcol+dx)=blank
board(blankrow ,blankcol)=tmp
blankrow=blankrow+dy
blankcol=blankcol+dx
return

Label MixBoard
for k=1 to difficulty*size
dx=0:dy=0
opt=ran(2)
if opt>0.4 then 
 if ran(2)>0.5 then dx=-1
 else dx=1
 fi
else
 if ran(2)>0.5 then dy=-1
 else dy=1
 fi
fi
rem  for diagnostics :-) print dx,dy;
  if board(blankrow+dy ,blankcol+dx)<> -1 then gosub Slide 
  fi

next k
return

    Source: geocities.com/sunsetstrip/palms/1624/yabasic/puzzles

               ( geocities.com/sunsetstrip/palms/1624/yabasic)                   ( geocities.com/sunsetstrip/palms/1624)                   ( geocities.com/sunsetstrip/palms)                   ( geocities.com/sunsetstrip)