Here’s my submission. I’m taking “one line” as what will fit on one line in portrait orientation (smallest width) without wrapping to another line. To play this game, tap the number you want to move to the blank square. Object is to get the numbers in order, left to right, top to bottom, with the blank square in the lower right corner.
displayMode(FULLSCREEN) supportedOrientations(PORTRAIT_ANY)
function setup()
count,size,done,ntab,otab=0,150,false,{},{}
tab = { {2,5,},{1,3,6,},{2,4,7,},{3,8,},{1,6,9,},{2,5,7,10,},
{3,6,8,11,},{4,7,12,},{5,10,13,},{6,9,11,14,},{7,10,12,15,},
{8,11,16,},{9,14,},{10,13,15,},{11,14,16,},{12,15,} }
create16() end
function create16() -- create starting puzzle
for z = 1,16 do ntab[z]=0 rnd = randomNbr() ntab[z]=rnd otab[z]=rnd
if rnd == 16 then n=z end end ntab[n]="" otab[n]="" end
function randomNbr()
while 1 do a = math.random(1,16)
for z = 1,16 do if ntab[z] == 0 then return(a) end if ntab[z] == a then break
end end end end
function draw()
background(40,40,50) offset=0 rectMode(CENTER) text("REPLAY",190,800)
text("NEW",600,800)
for y=4,1,-1 do for x=1,4 do offset = offset + 1
fill(200,0,0) rect(x*size,y*size,size,size)
fill(255) fontSize(60) text(ntab[offset],x*size,y*size) end end
if done then str=string.format("Complete %3d",count)
text(str,WIDTH/2,HEIGHT-100) else
str=string.format("Number of moves %3d",count)
text(str,WIDTH/2,HEIGHT-50) end end
function touched(t)
if t.state==BEGAN then
if t.x>100 and t.x<300 and t.y>750 and t.y<850 then
for z=1,16 do ntab[z]=otab[z] end count=0 done=false end
if t.x>500 and t.x<700 and t.y>750 and t.y<850 then setup() end
if not done then z=0 for y=4,1,-1 do for x=1,4 do z = z + 1
if t.x > x*size-35 and t.x < x*size+35 then
if t.y > y*size-35 and t.y < y*size+35 then checkblank(z)
end end end end end end end
function complete() -- check for a completed game
count = count + 1 for z = 1,15 do if ntab[z] ~= z then return
end end done=true end
function checkblank(pos) -- check for the blank space
for z = 1,#tab[pos] do val = tab[pos][z]if ntab[val] == "" then
ntab[val] = ntab[pos]
ntab[pos] = "" complete() return end end end