--!name Tents
--!icon puzzle
--!category Puzzles
local aF="!$%&()+,-0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnpqrstuvwxyz|~"local function aD(b)return aF:sub(b+1,b+1)end local aH,aG,aJ,aL=5,10,18,26 local O={6,8,11}local aM={0,34,0}local I={"Easy","Medium","Hard"}local aj={"022HW6M000aO0WaG20b0G9c0bW06a00OcG06098H4YW0G498a020169a0261G0W804W2GbO05Y81088444cO06a00864X8I4086412c1G2c12P418cG0W060ab02I0X02G0006W4G8c0G0a601O200Oc4K88aOM0W2G1Y010YPK08OG0c006aaG4W801428aY6H46800GbW209804O900XOIcM00OG0W408aa0029X40O0062112910Y0G6609I0X10c8040YGG89400a02PW0I6b00a9G0WOW0I0X8GK4c8c6G08Y4H042OaO00G9Y0HOc0G9c04089G1c2O2GbW6408O009Y0H1WW0I2111824002M1026824X9G408W0MXOI0WGGW002M2814cOK08O00c9H02900900OW0IO10aO0009O61Wa0468000cPG0WO0088441X8240a00caGO10ca02I01a00c8G40bOI1W28O4000O80LOYa241800OG0cOa201XXG28G4W9O000aa20HaW1WO0GaW01Xa2M0W2211804Pc029X46HXW26020b01WW6G0O6b02804O00aO0cG0600a020bO8c4G0a90HOY0c814O900W0GO9102bWG0W162W8M4H1Y2001WGcW108449c00a028146OW0IG0c0H82LWW02P2I01a6418200Y9H0804a01PY60b029H0YO000GOc0498042OaO61W2IG1122bWGMWW020X0M804Oc0108940W0G2016O042OW0IOW4M102a01c0000089K0c9814c002M1W6805W0018c40OW9G09102G0c694G8Y01G4c802H02aG0WG1YI824X1GIOW00610c2010011c2c058845W8M0W901Wa00XOI00O019I0W6I1X2aaG0Wc0G0GacW6G0I0X9002M06W0G92G00cPa00O90062H0202c1G9009b021OY0H0c4086000aOM0W9G1Wc0428b006c0G9aG4X820G4W80021Xa00WaI012610b6204281O00Oc0G0H4Y8O8042018O50cIMW00825529WcM00W9G0G2W1aa12c1G0XY01009WGMYGH2Y16804W0GaX1I2PW0GGcW0GcWG0OcG06a0G4c8aH0YO00H0YO0aO2G09W0G099","W012OG0IY814IM00G92O004MOY0G12084W0X2G041Wc081WIH60800022P40004cGWaaG02990G0Q8aGH218082G000c41GYY0542PY00K0c600908I0I5008c804M006GaWc0101W5WWW900HXY005XW021YK002H2G84W9X040WW101W1W2004XW900IGO001c2GG420c0440WX009c040ac000aYG102Oa402GG1Yc00490bWW0104W9X808O0GGG1Y60040ac00162O0089cGH429WcK00c200400089OM06400W6Oa006010H8282005WGa20b698GO28G0I26040001c9000PO9O020O000a01c1808G10P8WO121Y044WW1G0cPW004O8W0G28b4G9XW002K90W0aA09KW0X112O00089OG0000Hc20008bWK04W2W049bW9a0G1288GH22OWG121AG8GaWO500c0002004W018QPG00W019Y9G42P04801M1A080PW408W0GcI00400OW059aW9c8G0G2HG0A0002II0641W260K1Y0W0bO00HXY400XW00O0W2H848GWG0669002HXWc2G4002P10181e0b0080O00PW000YH10AG0022YK51YGI025WW012GO404W2W94O1WXO18010W81820G5c8W4H9W06800MO9000G9I02G2M60W0W111eOG02O800M0H0281W20Q4W410Y4PKW2040GYI00840GXW00WcP10IG20Y4b4W09P108804M8Y0G4IaY401W0a904O9cG1289WG0O0W2H0G2M24W4Wa106801089WG0088WGH40GXY800Pa0GOYO100b209a01G0A6844HWW8000G9Y91060c0X0100O0G1Y1WO0W0H9Y6G0IM2000OI024099O008W2H04aaW01I1Q480M1Q080069001WY0149490W0a001a1XYG8000aa408YPG2085WH0681408fa0008bWG0226440Oa0G229442OYGG0a9490W6080GG2600HO28600GYI100cGW614WWXX0900G00O9W818I0H4G8c000OOO0W8P0G0a6a0109PW2022G5WO480WPWOG00a00622G6Hc0a0W0109090W1X6081WK09WY0P5W009O80GKY8X0GO0a0YGP00696022G4041OW809042OX408WG1Q0408WaH898G08G0I21048900PY80KIIPWb4H8Y800400W2G00W9X9G006PX1088G069OX009W00900WY1140cc11G02890G09000G022904M9I02000c044OW82OM400a8a1G08W0160a000G0c000a20ALWK01Wb80801X808GW6b6090000W9b90006PW0GO2021W5a2GW14O8W0W0X210K02QIG04WGX202G00AGOG00O9O4G0Y9005W0W9O040WW1GO290WG1I2205W9aX019X808GO4G0Ya00990WM125fGW200061Y0W411W0XW504W8W9K00W6020b4080a6O2G44WWXP408W2006G1W602014c8a40PW90666400WWY114f8bGG296011988000W25O4W009Y4GKe20G04aaW6OO0002024O4080cHX1W00O000PW04PWW00IG2004cPWcG800GOW010090O090O6O09Oa00M120800M220K0Y9b0aa000080XM181W2G00899GGcQ1408c011W6004OaW000cKa0W0W2X050W0H92000O0W910Gfc100080GG2OW011W0bWW010OX818Ga1XWW410Wa2P80OGa00O080aG4O0W1WGOc9000YcH500ec1100090a2O20I4840I0aa11O8400WOaW414W9XO081W01O480W008PWG0O1808M800HY99400cG809O00G6201a8WOH00902G800P1W2005X4W8X4G0Y0Wc504YLX4W8W000a00092GI8Y5H0810088W0H2W2L2HW0cK00YG01YI005c2404YG009c804G66010We11M6600WYO10G02K60W0W616062M0006O409W2004aY414Y9W410cLW0WIG20824GaX1081W2G1W9W9G061c0000W6106M0W","08O1WG64H00Y8880GGM2Oa1001801e22G24045W9W0901W0XW8X0WHG1628100M80O04a20W95HOMA82000O0PW1W4006W9W10GOebX1009Y6O040690000992G2GH2029a200041W2HW0H09c80000YM9b00H01Y8900YGWbGb0I08Y0WH011YOa00GO1090e901006PYM002OOA0G0KGW1c1O80O18018GG80cO0W02H090Ga620690141YOX00G8Gc8200G40OWcO10092I02G4QG0a0cOa0402GM00c0XO0181WW4a14WO8W10G09W9W0OG002GHW0Y09108024Hc4W01WWaW9110O809G042P9YGc2GP10008Y091480aaP000GaWc0100I162482GO1W80MOM208012GM84201Y0W0K1PY8O00G104180c81WIG0A0a9G002a2M420094cM1X0009XW4G09Y0001c0W8XXOH0902G0I0X24b8008G80IOGY0414aYGO00O0400OY8OH4H28W805908WH9G28G00262I0G04Q6Oa08010Gc821425OX6O180086O0006062G90G01Y9aa09WW01120PYKa4000W9fWO1590OW2O1O448G0W2600I69c4000O0091cO4GG4Y24W00W0PW8O04G0aWbW00224444Wc2K1G0YQ0W00101PXYO10009X1GG8A2000908020Hf42H0b0AG9W0a08409GW00W0ab2K080W9Ga0208849GG94cO0W42G02G04GO8YO8K00GW9IG920IGc210408YOW141909W08GG0M6020WYL010880a0G0692IG0GGcI2402GXW1006860020Y255K48YOO000c9a5000XW00W889GGKI2Gc00a00aPYG005Y9WW4G0a1WW20H04c9W00H8420GY0Oa4806OM0004OcOW040c8154G8Wc90GG62290G00Y9OX4010X0Wa8104060W8XWWH011XWMW0I5620X01W9WGG0221O0H80c8600014YQOX0G0001XXYG001X910869W6006084GGGY2905W00W0c060480YOG140PWYa014906029GYK211W1W9O2G00Ge221H412OW801O6OW0G10I1c20W00b1c00YO2H42Ge901G66P8108G8a001O0O89a0000009a2G0aGIG22064Gc0Y0401W2GX9GX92108448GWWM009W0028c84H0Gc00049a4G00Y60a6HWOWa110288cK00bY000429Xc4G01060880O6G0429WXaG00IM4Q00W000G2I29X4019WO04O1WW01a2IO2H0608X00189a90O2G42GWW0X0O1001W9f1O1M81Y01W060091O82O0G0W04b20W14aO8010669W00060190a8IG62462Gc1WOPY4004eO0WG610600Y4O14W18a98GG14I08Y0900600O08OG0G2cO0040cM9W10K08OWW101O808G1WI0XY1X04020M94Y0HX024840WGWa00009WOOHO02O00O0185c8KW06W090Ga0I09Y01G2O9WGG4280W0M02G08X0aH818008HWa00049YOWK0H9c6800008M4aI0WW0a1204K4WYW1406OW2H4208c410G28Y4514W9WW0a00WIM1200000PW2P42G0Y04W4aXO40O6WGH4228WO1Y80a4O021HX4808O4102Y80KKG222600049c9WGc42L0YGY00W4812KI20c44a5W0GW220G4G20I91Y09W04H6Oe801G28904G8O9b000AIO900G080aGIG208WOOHO08900GGb0209Y0W0410WOOb10009YOW00H0c404KW0Y00aGb0208X1W1842O0X4H08c8GH4228W001WGaa20090I06Q414GYOYb0000WcG100W801OHc08cH0G08190G80Y85X1OW68GO00a0a05W68W60G600aWG05I64Y0HW0c8GWG2120001O618O082HW02G2M06992100a8a1O08008HXWH012PY801400809X5W18WOO2O02GK002Y064490Pa0Y0910WHWL242W0W09a600HYGc00444cWWW40004aWbW10819W08G6968G2GI062OG0GI0200W4cPOW0G02GWIG120cIGa00a06G1WWY02HKO1Y00a0bWHW020000Y8014HYPXW05108YO0G88XXGH08W091O90W00X291a4HW4Y00X0O01X0609Wc0O10W2210449c2OG4aG9Xc000002GWW0110a1c0082G0G0YI2L040Y1YGLW02100GA9Y0K14208c09G1Wbc4800WP8060IH194880WGG02202H0O08W0a1OaO01W08W60H64004W1WWG10209W0O0G0II8cG0G2OOcG60900X29X84196QP200046Xc2H001WGI0224a0000O620004YO010G9108HfXI00800022864KGGY0c11W1Wb9W08G0062OcMK00bXYGW008609PG01292O0000OOaO4088W0IG626O04a00X02HOcG810OG8G0a22G0b9W4818W0aG1W60G00292G02GWM0b2000G0aA9a9G0ac4004XWOWaO1094200W4W02H8YGOH02KO10W2O02P4A00WK80OOGaG0029W001OOaG002020G24QO5W0Y8914H1a280Y40041Y42G4W02O2O40408a09G6O1WOH1W29X0108IO0I0620011a089O0080Oa04G0OY60620a04a0Oa08000G1Xe8a0GGOXYP1001cM2K200YGa2000KPf29060020064060O81WGGG2OY0111AO98G9M9W201G0O20O60W201658G48I9W4K00YWab0009WO00462OY00G4W0b12G81002OOX4G18Y2OG40M0YPW800aI00246842GIO08K0OI90000I0eY5XH119W88GGac2004000OYOW1419G402OY914408W8OH8G28IG0Y4194YOIG0M00I6OY0WH00a0aW9W1116O800G1W209M0820OM0a600005XW9X0909W1W00002209L4O29WY01P4a80004cHOW080G00cac101G9W280O0G06PXWO68b2GG81XW0W0010aOG42I0W4040fWY0G0441YPWa619008OW1412OW910818WG8H8W20H9068040HWc0a0G8G29I24M04Y00008a90H0228W4411O0G8HY92006224044YO600I208K4aI04248c4WG1W6600G0620I69Y401400aXWW0012GW00X091192P8004194YO0WW8aP0G099WO1G4IO0Y02K1W0Y92G4909O0b0009W0c40X4Wb80060a00008G19I2O2I000KW8cb8G09G1W094080W9I19048I28244I0a2K884WGGX01462Oc1W2G9OG00I68cG0G2O04010ccO004104W82WG2422K0224A44WKa000948a0WK600YGcP010PW62060091XW000c9IG420cWG112O0O44YGWX0W04119Y8844G0c0O0cG2G0010a99W4000f8a00KO10W2PW8001Kbc8W0X8218G5e660G000O2M8G00I16QK800W64040XWYG0602P0O0O00601O0I8224244O4aW1WH9W28G602P0006PW9G0OI02I1YG000920O64G6GYOW140HWW200PW9WYOG10GOW60100cGb00a88000I262L41G86AO600HWa20460OYG0009WWOG1800bGQG9W00091802OM2GO99100688600M0aW0a1906G0aIO0201W0012MM80Wc9W0KG621Y0004W001Oa4YG8X00G02K2OGW420PXW0aYOb1408W1012O98004G28W24G94G0022G12G2PWbW2O0O0G0668400GW9WGOGc010048O0W2Ga06G2PW"}local aE="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-"local ak={}for b=1,64 do ak[aE:byte(b)]=b-1 end local function aA(j)return(O[j]*O[j]+2)//3 end local function aP(j)return#aj[j]//aA(j)end local function aU(h)local j=os.date("*t",h)return os.time({year=j.year,month=j.month,day=j.day,hour=12})//86400 end local function V()local h=os.time()if not h or h<1700000000 then return nil end return aU(h)end local aN={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}local aK={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}local aI={3,1,1,2,2,2,3}local function aq(P)return os.date("*t",P*86400+43200)end local function ar(P)local j=aq(P)return aN[j.wday].." "..aK[j.month].." "..j.day end local function ap(P)return aI[aq(P).wday]end local c=6 local H,G,n={},{},{}local M,K={},{}local a local C={}local e={}for b=1,13 do e[b]=0 end local R={1,1,1}local x={}local o,Q=1,false local m,r,am="menu",1,"menu"local u,X,Z=nil,nil,nil local function J(f)f=math.floor(f or 0)if f>=3600 then return string.format("%d:%02d:%02d",f//3600,f//60%60,f%60)end return string.format("%d:%02d",f//60,f%60)end local function Y(v)if v.kind=="d"then return"Daily, "..ar(v.num)end return I[v.diff].." #"..v.num end local function a3(L,p,w)local i=aP(p)if L=="d"then return(w*37+11)%i,w%8 end return(w-1)%i,(w*5+(w-1)//i)%8 end local function _(L,p,w)local an,h=a3(L,p,w)local W=aA(p)local a6=aj[p]:sub(an*W+1,an*W+W)local ab={}for d=1,W do local s=ak[a6:byte(d)]or 0 ab[3*d-2],ab[3*d-1],ab[3*d]=s>>4,s>>2&3,s&3 end c=O[p]H,G,n,M,K={},{},{},{},{}for d=1,c do M[d],K[d]=0,0 end for k=0,c-1 do for g=0,c-1 do local U,T=k,g if h&4~=0 then U,T=T,U end if h&1~=0 then U=c-1-U end if h&2~=0 then T=c-1-T end local s,b=ab[U*c+T+1],k*c+g+1 H[b],G[b],n[b]=s==1,s==2,0 if s==2 then M[k+1],K[g+1]=M[k+1]+1,K[g+1]+1 end end end o=1 a={kind=L,diff=p,num=w,el=0,hints=0,done=false}x,Q,u={},false,nil end local function a8()local s={}for b=1,c*c do s[b]=n[b]end return table.concat({a.kind,a.diff,a.num,a.el,a.hints,a.done and 1 or 0,o,table.concat(s)},",")end local function aB(f)local l={}for y in(f..","):gmatch("([^,]*),")do l[#l+1]=y end local p,w=tonumber(l[2]),tonumber(l[3])if(l[1]~="d"and l[1]~="b")or not p or p<1 or p>3 or not w then return end _(l[1],p,w)a.el,a.hints,a.done=tonumber(l[4])or 0,tonumber(l[5])or 0,l[6]=="1"local g=tonumber(l[7])or 0 if g>=1 and g<=c*c then o=g end local s=l[8]or""for b=1,c*c do local y=(s:byte(b)or 48)-48 if not H[b]and y>=0 and y<=2 then n[b]=y end end return true end local function z()if a then C[a.kind]=a8()end snail.save(table.concat({"TN1",table.concat(e,","),table.concat(R,","),a and a.kind or"",C.d or"",C.b or""},";"))end local function a0()local f=snail.load()if type(f)~="string"or f:sub(1,4)~="TN1;"then return end local l={}for y in(f..";"):gmatch("([^;]*);")do l[#l+1]=y end local d=0 for y in(l[2]or""):gmatch("[^,]+")do d=d+1 if d<=13 then e[d]=tonumber(y)or 0 end end d=0 for y in(l[3]or""):gmatch("[^,]+")do d=d+1 if d<=3 then R[d]=math.max(1,tonumber(y)or 1)end end if l[5]and l[5]~=""then C.d=l[5]end if l[6]and l[6]~=""then C.b=l[6]end local ad=l[4]if ad and C[ad]then local af,ag=pcall(aB,C[ad])if not(af and ag)then a=nil end end end local function aT(b)local k,g=(b-1)//c,(b-1)%c for at=-1,1 do for as=-1,1 do local ah,ae=k+at,g+as if(at~=0 or as~=0)and ah>=0 and ah<c and ae>=0 and ae<c and n[ah*c+ae+1]==1 then return true end end end return false end local function aa(k,d)local i,f=0,d==1 and(k-1)*c+1 or k for a_=0,c-1 do if n[f+a_*d]==1 then i=i+1 end end return i end local function ai(b)return(n[b]==1 and not G[b])or(n[b]==2 and G[b])end local function a1()local i=0 for b=1,c*c do if ai(b)then i=i+1 end end return i end local function ba()local E,D=0,0 for b=1,c*c do if n[b]==1 then E=E+1 end if H[b]then D=D+1 end end return E,D end local function az(b)x[#x+1]=b*4+n[b]if#x>150 then table.remove(x,1)end end local function av()for b=1,c*c do if(n[b]==1)~=G[b]then return end end a.done,Q=true,false local q=(a.diff-1)*3 e[q+1]=e[q+1]+1 if e[q+2]==0 or a.el<e[q+2]then e[q+2]=math.max(1,a.el)end e[q+3]=e[q+3]+a.el if a.kind=="d"and e[13]~=a.num then e[10]=e[10]+1 e[11]=e[13]==a.num-1 and e[11]+1 or 1 if e[11]>e[12]then e[12]=e[11]end e[13]=a.num end end local function aY()for d=0,c*c-1 do local b=(o-1+d)%(c*c)+1 if ai(b)or(G[b]and n[b]~=1)then az(b)n[b]=G[b]and 1 or 0 o=b a.hints=a.hints+1 u=G[b]and"Hint: a tent goes here"or"Hint: no tent here"av()return end end end local function ac()local j=V()if j and e[13]<j-1 then return 0 end return e[11]end local function B()m,Z,r="play",os.time(),1 end local function aC(p)if a then z()end local i=R[p]R[p]=i+1 _("b",p,i)B()z()end local function a9(j)if a then z()end a=nil if C.d then local af,ag=pcall(aB,C.d)if not(af and ag)or a.num~=j then a=nil end end if not a then _("d",ap(j),j)end B()z()end local function aS()local ax=os.time()if a and m=="play"and Z and not a.done then local au=ax-Z if au>0 then a.el=a.el+math.min(au,600)end end Z=ax end local function a7(j)return O[j].."x"..O[j]end local function aw()local h={}if a and not a.done then h[#h+1]={"Continue: "..Y(a).." ("..J(a.el)..")","cont"}end local j=V()if j then local f="Daily puzzle: "..ar(j)..", "..I[ap(j)]if e[13]==j then f=f.." (solved)"end h[#h+1]={f,"daily"}else h[#h+1]={"Daily puzzle: needs the clock","noclock"}end for d=1,3 do h[#h+1]={"New "..I[d].." "..a7(d).." puzzle (#"..R[d]..")",d}end h[#h+1]={"Statistics","stats"}h[#h+1]={"How to play","help"}return h end local function ay()return{{"Back to the puzzle","cont"},{#x>0 and("Undo ("..#x..(#x==1 and" move)"or" moves)"))or"Undo (nothing to undo)","undo"},{"Check for mistakes","check"},{"Hint: fix a square","hint"},{"Grass on all empty squares of full rows","grass"},{"Restart this puzzle","restart"},{"Main menu","menu"},{"How to play","help"},}end local function aX()local v={}for b=1,c*c do local k,g=(b-1)//c+1,(b-1)%c+1 if n[b]==0 and not H[b]and(aa(k,1)==M[k]or aa(g,c)==K[g])then v[#v+1]=b*4 end end for aO,A in ipairs(v)do n[A//4]=2 end if#v>0 then x[#x+1]=v end return#v end local function aR(t)if t=="cont"then B()elseif t=="undo"then local A=table.remove(x)if A then if type(A)~="table"then A={A}end for d=#A,1,-1 do n[A[d]//4]=A[d]%4 end o=A[1]//4 B()z()else u="Nothing to undo"end elseif t=="check"then B()local i=a1()Q=i>0 u=i==0 and"No mistakes so far"or(i==1 and"1 mistake, marked"or i.." mistakes, marked")elseif t=="hint"then B()if not a.done then aY();z()end elseif t=="grass"then B()local i=aX()u=i==0 and"No open squares in full lines"or("Grass on "..i..(i==1 and" square"or" squares"))z()elseif t=="restart"then _(a.kind,a.diff,a.num)B()z()elseif t=="menu"then m,r="menu",1 elseif t=="daily"then a9(V())elseif type(t)=="number"then if a and a.kind=="b"and not a.done and X~=t then X,u=t,"Press OK again to leave "..Y(a)else X=nil aC(t)end else am,m=m,t end end local function a2(d)local k,g=(o-1)//c,(o-1)%c if d=="up"then k=(k+c-1)%c elseif d=="down"then k=(k+1)%c elseif d=="left"then g=(g+c-1)%c elseif d=="right"then g=(g+1)%c end o=k*c+g+1 end local function a4(d)if a.done then if d=="top"then m,r="menu",1 elseif d=="ok"then if a.kind=="b"then aC(a.diff)else m,r="menu",1 end end return end if d=="top"then m,r="opts",1 z()elseif d=="ok"then if H[o]then u="That's a tree"return end az(o)n[o]=(n[o]+1)%3 av()z()else a2(d)end end function key(d)aS()u,Q=nil,false if m=="play"and a then a4(d)return end if m=="menu"or m=="opts"then local F=m=="menu"and aw()or ay()if d~="ok"then X=nil end if d=="up"then r=(r-2)%#F+1 elseif d=="down"then r=r%#F+1 elseif d=="ok"then aR(F[math.min(r,#F)][2])elseif d=="top"and m=="opts"then m,r="menu",1 end return end if d=="top"or d=="ok"then m=am end end function touch(L,g,k)if L~="board"or m~="play"or not a or a.done or g<1 or g>c or k<1 or k>c then return end o=(k-1)*c+g key("ok")end local function ao(N,E,D)return aD(N+(E<D and aG or E==D and aJ or aL)+math.min(D,7))end local function aQ()local N=aM[a.diff]local a5=a.done local S={}for k=0,c-1 do local h={}for g=1,c do local b=k*c+g local f=n[b]local s=H[b]and 3 or(f==1 and(aT(b)and 4 or 1))or f if Q and ai(b)then h[g]="@"else h[g]=aD(N+s+((b==o and not a5)and aH or 0))end end h[c+1]=ao(N,aa(k+1,1),M[k+1])S[#S+1]=table.concat(h)end local h={}for g=1,c do h[g]=ao(N,aa(g,c),K[g])end S[#S+1]=table.concat(h).."."return table.concat(S,"/")end local function aV()snail.title("Tents - "..Y(a))local f if a.done then local q=(a.diff-1)*3 f="Solved! Best "..I[a.diff].." time "..J(e[q+2])if a.hints>0 then f=f..", "..a.hints..(a.hints==1 and" hint"or" hints")end elseif u then f=u else local E,D=ba()f=J(a.el).."  Tents "..E.." of "..D end snail.status(f:sub(1,47))snail.board(aQ(),nil,a.done and("Solved in "..J(a.el))or nil)if a.done then local q=(a.diff-1)*3 snail.text(I[a.diff].." puzzles solved: "..e[q+1])if a.kind=="d"then snail.text("Daily streak: "..ac()..(ac()==1 and" day"or" days"))end snail.hint(a.kind=="b"and"BACK puzzles OK next puzzle"or"BACK puzzles OK puzzles")else local bb=H[o]and"tree"or({"tent","grass","clear"})[n[o]+1]snail.hint("BACK options OK "..bb.." L/R move UP/DN move")end end local function aW()snail.title("Tents statistics")for d=1,3 do local q=(d-1)*3 local i=e[q+1]if i>0 then snail.text(I[d]..": "..i.." solved, best "..J(e[q+2])..", average "..J(e[q+3]/i))else snail.text(I[d]..": none solved yet")end end snail.gap()snail.text("Daily puzzles solved: "..e[10])snail.text("Daily streak "..ac()..", best "..e[12])snail.hint("BACK back OK back")end local al={"Every tree needs its own tent right next to it: above, below, left or right.","Tents never touch each other, not even corner to corner.","Numbers say how many tents go in each row and column: hollow once met, boxed if over.","Arrows move. OK cycles a square: tent, grass (no tent here), empty.","Tents that touch another tent are marked. BACK opens options: undo, check and a hint.","Options can also fill grass in every row and column that has all its tents.",}function draw()if m=="play"and a then aV()return end if m=="stats"then aW()return end if m=="help"then snail.title("How to play")if snail.touchscreen then al[4]="Tap a square to cycle it: tent, grass (no tent here), empty."end for aO,f in ipairs(al)do snail.text(f)end snail.hint("BACK back OK back")return end if m=="noclock"then snail.title("Daily puzzle")snail.text("The daily puzzle needs the date. Connect to Wi-Fi once so the clock gets set, then come back.")snail.text("The Easy, Medium and Hard puzzles work any time.")snail.hint("BACK back OK back")return end local F=m=="menu"and aw()or ay()if r>#F then r=#F end snail.title(m=="menu"and"Tents"or("Tents - "..Y(a)))if u then snail.status(u)end for b,aZ in ipairs(F)do snail.row(aZ[1],b==r)end snail.gap()if m=="menu"then local i=e[1]+e[4]+e[7]snail.small("Daily streak "..ac()..", "..i..(i==1 and" puzzle"or" puzzles").." solved.")snail.hint("BACK leave OK choose UP/DN move")else snail.small("Time "..J(a.el)..(a.hints>0 and(", hints "..a.hints)or""))snail.hint("BACK puzzles OK choose UP/DN move")end end function start()snail.ink("fast")a0()if a and not a.done and not(a.kind=="d"and V()and a.num~=V())then B()else m,r="menu",1 end end
