var w,h,my={};function alloutMain(){let version='0.52';w=360;h=450;my.activeQ=true
my.bdSz=5
var s='';s+=''
my.sndHome=(document.domain=='localhost')?'/mathsisfun/images/sounds/':'/images/sounds/'
s+=''
s+='';s+='';my.snds=[];s+='
';return s;}
function optPop(){var pop=document.getElementById('optpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left=(w-400)/2+'px';}
function optYes(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';var div=document.getElementById("puz");my.puzN=div.selectedIndex;console.log('puzzle num',my.puzN)
gameNew()}
function optNo(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';}
function getDropdownHTML(opts,funcName,id,chkNo){var s='';s+='';return s;}
function soundBtnHTML(){var onClr='blue'
var offClr='#bbb'
var s=''
s+=''
s+='
'
return s}
function soundPlay(id,simulQ){if(!my.soundQ)return
simulQ=typeof simulQ!=='undefined'?simulQ:false
if(simulQ){if(id.length>0)document.getElementById(id).play()}else{my.snds.push(id)
soundPlayQueue(id)}}
function soundPlayQueue(id){var div=document.getElementById(my.snds[0])
div.play().then(_=>{}).catch(error=>{my.snds.shift();});div.onended=function(){my.snds.shift();if(my.snds.length>0)soundPlayQueue(my.snds[0]);};}
function soundToggle(){var btn='sound'
if(my.soundQ){my.soundQ=false
document.getElementById(btn).classList.add("mute")}else{my.soundQ=true
document.getElementById(btn).classList.remove("mute")}}
function Timer(g,rad,secs,clr,funcEnd){this.g=g;this.rad=rad;this.secs=secs;this.clr=clr;this.funcEnd=funcEnd;this.x=rad;this.y=rad;this.stt=performance.now();this.stopQ=false;}
Timer.prototype.update=function(){};Timer.prototype.restart=function(secs){this.secs=secs;this.stt=performance.now();this.stopQ=false;requestAnimationFrame(this.draw.bind(this));};Timer.prototype.more=function(secs){this.stt+=secs*1000;};Timer.prototype.stop=function(){this.stopQ=true;};Timer.prototype.draw=function(){if(this.stopQ)return;var now=performance.now();var elapsed=now-this.stt;var ratio=Math.min(1,elapsed/this.secs/1000);var g=this.g;g.beginPath();g.fillStyle="#def";g.arc(this.x,this.y,this.rad,0,2*Math.PI);g.fill();g.beginPath();g.moveTo(this.x,this.y);g.fillStyle=this.clr;g.arc(this.x,this.y,this.rad,-Math.PI/2,ratio*2*Math.PI-Math.PI/2);g.fill();if(ratio<1){requestAnimationFrame(this.draw.bind(this));}else{this.funcEnd();}};class Tile{constructor(wd,ht,lt,tp){this.wd=wd;this.ht=ht;this.bgClr='#ffe';this.bdrClr='grey';this.overClr='#dc8'
this.offClr='#fff';this.onClr='#dd0';this.onQ=false
this.hiliteQ=false
var div=document.createElement("div");div.style.width=wd+'px';div.style.height=ht+'px';div.style.position='absolute';div.style.top=tp+'px';div.style.left=lt+'px';this.div=div;var me=this;div.addEventListener('mouseover',function(){if(!my.activeQ)return;me.overQ=true
me.draw();});div.addEventListener('mouseleave',function(){if(!my.activeQ)return;me.overQ=false
me.draw();});div.addEventListener('click',function(){if(!my.activeQ)return;me.overQ=false
me.flip();my.moveN++
soundPlay('sndClick')
bdFlip(me.xn,me.yn)});var can=document.createElement('canvas');can.style.position="absolute";can.style.top='0px';can.style.left='0px';can.style.width='100%';can.style.height='100%';can.width=wd;can.height=ht;this.g=can.getContext("2d");div.appendChild(can);document.getElementById('board').appendChild(div);this.draw();}
draw(){var g=this.g;g.clearRect(0,0,this.wd,this.ht);let style=this.onQ?2:4
g.pieceDraw(this.wd/2,this.ht/2,this.wd*0.44,style,this.overQ)
if(this.hiliteQ){g.strokeStyle='#0cc'
g.lineWidth=5
g.beginPath();g.arc(this.wd*0.508,this.ht*0.508,this.wd*0.44,0,2*Math.PI)
g.stroke();}
return
if(this.onQ){if(this.overQ){g.strokeStyle=this.overClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}else{g.strokeStyle=this.onClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}}else{if(this.overQ){g.strokeStyle=this.overClr
g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}else{g.strokeStyle=this.offClr;g.lineWidth=2;g.beginPath();g.arc(this.wd/2,this.ht/2,this.wd/3,0,2*Math.PI);g.stroke();}}}
flip(){this.onQ=!this.onQ
this.draw()}
hilite(){this.hiliteQ=true
this.draw();this.hiliteQ=false}
win(){this.bgClr='#ffe';this.draw();}
setxy(lt,tp){this.div.style.left=lt+'px';this.div.style.top=tp+'px';}}
CanvasRenderingContext2D.prototype.pieceDraw=function(x,y,size,type,hoverq){if(hoverq){this.beginPath()
this.fillStyle='hsla(60,90%,10%,0.2)'
this.arc(x+size*0.1,y+size*0.1,size*1.03,0,Math.PI*2,true)
this.fill()
this.beginPath()
this.lineWidth=6
this.strokeStyle='hsla(120,100%,45%,1)'
this.arc(x,y,size,0,Math.PI*2,true)
this.stroke()}else{this.beginPath()
this.fillStyle='hsla(120,100%,10%,0.3)'
this.arc(x+size*0.1,y+size*0.1,size*1.03,0,Math.PI*2,true)
this.fill()}
var gradient
switch(type){case 0:this.beginPath()
gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(240,10%,50%,1)');gradient.addColorStop(1,'black');this.fillStyle=gradient
this.arc(x,y,size,0,Math.PI*2,true)
this.fill()
this.beginPath()
gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient
this.arc(x,y,size*1,0,Math.PI*2,true)
this.fill()
break
case 1:this.beginPath()
gradient=this.createRadialGradient(x-size*0.4,y-size*0.6,0,x,y,size*1.4);gradient.addColorStop(0,'white');gradient.addColorStop(0.4,'hsla(240,100%,93%,1)');this.fillStyle=gradient
this.arc(x,y,size,0,Math.PI*2,true)
this.fill()
break
case 2:this.beginPath()
gradient=this.createRadialGradient(x-size*0.4,y-size*0.6,0,x,y,size*1.4);gradient.addColorStop(0,'white');gradient.addColorStop(0.4,'hsla(120,70%,70%,1)');this.fillStyle=gradient
this.arc(x,y,size,0,Math.PI*2,true)
this.fill()
this.beginPath()
gradient=this.createRadialGradient(x+size*0.2,y+size*0.2,0,x,y,size);gradient.addColorStop(0,'hsla(0,0%,100%,0.7)');gradient.addColorStop(1,'hsla(0,0%,100%,0)');this.fillStyle=gradient
this.arc(x,y,size*1,0,Math.PI*2,true)
this.fill()
break
case 3:this.beginPath()
gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(240,10%,50%,1)');gradient.addColorStop(1,'hsla(240,10%,20%,1)');this.fillStyle=gradient
this.arc(x,y,size,0,Math.PI*2,true)
this.fill()
this.beginPath()
gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient
this.arc(x,y,size*1,0,Math.PI*2,true)
this.fill()
break
case 4:this.beginPath()
gradient=this.createRadialGradient(x+size*0.3,y+size*0.2,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(120,20%,50%,1)');gradient.addColorStop(1,'hsla(120,20%,10%,1)');this.fillStyle=gradient
this.arc(x,y,size,0,Math.PI*2,true)
this.fill()
this.beginPath()
gradient=this.createRadialGradient(x-size*0.5,y-size*0.5,0,x,y,size*1.6);gradient.addColorStop(0,'hsla(0,0%,70%,1)');gradient.addColorStop(0.3,'hsla(0,100%,100%,0)');this.fillStyle=gradient
this.arc(x,y,size*1,0,Math.PI*2,true)
this.fill()
break
default:}}
my.puzzles=[[2,7,10,28,8],[0,0,0,28,42,28],[0,0,21,0,0],[21,21,0,21,21],[10,27,27,27,10],[0,27,0,17,27],[15,23,23,24,27],[0,0,21,21,14],[15,17,17,17,15],[0,4,10,21,10],[10,31,14,26,7],[14,14,14,0,0],[21,21,21,21,14],[31,10,27,14,10],[8,20,10,5,2],[0,0,2,2,2],[0,2,0,2,0],[1,1,1,1,31],[0,0,4,14,31],[4,10,21,10,4],[21,0,21,0,21],[0,0,17,0,0],[30,2,14,2,2],[14,17,17,17,14],[0,0,28,12,4],[0,0,17,31,18],[1,3,7,15,30],[17,17,31,17,17],[4,14,4,4,4],[0,0,28,28,28],[0,2,0,0,0],[0,0,4,0,0],[17,19,21,25,17],[31,8,4,2,31],[8,8,21,17,25],[20,17,17,22,30],[24,10,17,21,0],[4,10,17,31,17],[0,14,14,14,0],[21,10,21,10,21],[10,1,3,12,10],[0,0,10,0,0],[17,10,4,4,4],[7,9,7,9,7],[17,11,7,2,14],[0,27,31,4,14],[14,5,28,15,21],[4,14,31,14,4],[4,31,5,18,16],[0,17,4,17,0],[17,10,4,10,17],[31,31,31,31,31],[27,0,27,0,27],[31,4,0,4,31],[31,10,4,10,31],[10,17,0,27,17],[4,6,27,12,4],[10,31,21,31,10],[21,17,27,17,21],[0,0,14,2,0],[16,8,4,6,5],[0,21,17,21,17],[31,14,14,14,31],[17,10,0,10,17],[14,10,14,8,14],[15,9,15,7,9],[21,21,21,21,14],[14,2,14,8,14],[31,17,21,17,31],[21,0,21,0,21],[10,21,14,21,10],[21,0,0,0,21],[31,29,27,23,31],[31,4,31,17,17],[27,10,27,10,27],[4,10,31,17,31],[17,27,21,17,17],[31,21,31,21,31],[14,4,4,4,14],[14,10,31,14,27],[0,0,4,0,0],[17,0,4,0,17],[27,27,0,27,27],[10,0,17,14,4],[21,14,27,14,21],[17,19,21,25,17],[21,21,27,21,21],[4,4,14,21,21],[21,21,21,21,31],[0,14,14,14,0],[4,10,17,31,17],[21,10,21,10,21],[17,14,10,14,17],[4,10,17,10,4],[21,0,10,0,21],[10,31,10,31,10],[31,21,31,29,31],[17,10,4,10,17],[31,4,31,4,31],[31,14,4,14,31],[4,21,31,21,4],[31,31,31,31,31]];function gameHint(){console.log('gameHint')
let mat=bd2mat(my.bd)
console.log('mat',mat)
let puz=[]
puz[0]=0
for(let i=0;i0){let pnt=pnts[Math.floor(pnts.length/2)];my.bd[pnt[1]][pnt[0]].hilite()}}
var qbit=[1,2,4,8,16,32,64,128]
let msk=qbit[6]-2;function puzGet(n){let puz=[];for(let i=0;i<=5;i++){puz[i]=(i==0)?0:2*my.puzzles[n][i-1];}
console.log('puzGet',puz)
return puz}
function solveAlmost(puz,hnt){for(let i=2;i<=5;i++){var c=puz[i-1]&msk;puz[i]^=c^(c+c)^(c>>1);puz[i+1]^=c;puz[i-1]=0;hnt[i]^=c;}}
function solveFull(puz){let backup=[];for(let i=0;i<=5;i++)backup[i]=puz[i];let hnt=[]
for(let i=0;i<=5;i++)hnt[i]=0;solveAlmost(puz,hnt);let aim=puz[5];puz[5]=0;let bot=[34,20,56,0,0];let inv=[6,14,12,54,42];let m=0;for(let k=1;k<=5;k++){let c=qbit[k];if(bot[m]&c){if(aim&c){aim^=bot[m];let d=inv[m];hnt[1]^=d;puz[1]=(puz[1]^d^(d+d)^(d>>1))&msk;puz[2]^=d;}
m++;}}
if(aim&msk){for(let i=0;i<=5;i++)puz[i]=backup[i];return(false);}
solveAlmost(puz,hnt);aim=countHnt(hnt);var backhnt=[];for(var i=1;i<=5;i++)backhnt[i]=hnt[i];console.log('A',hnt)
let invar=[];invar[0]=[54,0,54,0,54];invar[1]=[42,42,0,42,42];invar[2]=[28,42,54,42,28];for(let c=0;c<=2;c++){for(let i=1;i<=5;i++)hnt[i]=backhnt[i]^invar[c][i-1];let j=countHnt(hnt);if(j>1]+qcnt[hnt[i]>>6];}
return c}
function puz2Mat(puz){let mat=[];for(let i=0;i