';}}
s+='';}
s+='';return s;}
function ontouchstart(evt){var touch=evt.targetTouches[0];evt.clientX=touch.clientX;evt.clientY=touch.clientY;evt.touchQ=true;mouseDownListener(evt)}
function ontouchmove(evt){var touch=evt.targetTouches[0];evt.clientX=touch.clientX;evt.clientY=touch.clientY;evt.touchQ=true;evt.preventDefault();mouseMoveListener(evt);}
function ontouchend(){el.addEventListener('touchstart',ontouchstart,false);window.removeEventListener("touchend",ontouchend,false);if(my.drag.on){my.drag.on=false;pcDrop();window.removeEventListener("touchmove",ontouchmove,false);}}
function dopointer(e){var div=document.getElementById('sq_0_0')
var bRect=div.getBoundingClientRect();var mouseX=(e.clientX-bRect.left);var mouseY=(e.clientY-bRect.top);var overQ=false;for(var i=0;i(shape.x+shape.wd))return false;if(my>(shape.y+shape.ht))return false;return true;}
function mouseDownListener(evt){var i;var highestIndex=-1;var div=document.getElementById('sq_0_0')
var bRect=div.getBoundingClientRect();var mouseX=(evt.clientX-bRect.left);var mouseY=(evt.clientY-bRect.top);for(i=0;ihighestIndex){my.drag.hold.x=mouseX-pc.x;my.drag.hold.y=mouseY-pc.y;highestIndex=i;my.drag.index=i;}}}
if(my.drag.on){my.pcs[my.drag.index].shadowQ=true;if(evt.touchQ){window.addEventListener('touchmove',ontouchmove,false);}else{window.addEventListener("mousemove",mouseMoveListener,false);}}
if(evt.touchQ){el.removeEventListener("touchstart",ontouchstart,false);window.addEventListener("touchend",ontouchend,false);}else{el.removeEventListener("mousedown",mouseDownListener,false);window.addEventListener("mouseup",mouseUpListener,false);}
evt.preventDefault();return false;}
function mouseUpListener(){el.addEventListener("mousedown",mouseDownListener,false);window.removeEventListener("mouseup",mouseUpListener,false);if(my.drag.on){my.drag.on=false;pcDrop();window.removeEventListener("mousemove",mouseMoveListener,false);}}
function mouseMoveListener(evt){if(my.drag.index<0)return;var div=document.getElementById('sq_0_0')
var bRect=div.getBoundingClientRect();var mouseX=(evt.clientX-bRect.left);var mouseY=(evt.clientY-bRect.top);var pcDrag=my.pcs[my.drag.index]
var minX=-pcDrag.wd/2;var maxX=my.bdWd-pcDrag.wd/2;var posX=mouseX-my.drag.hold.x;posX=(posXmaxX)?maxX:posX);var minY=-pcDrag.ht*0.7;var maxY=my.bdHt-pcDrag.ht*0.3;var posY=mouseY-my.drag.hold.y;posY=(posYmaxY)?maxY:posY);pcDrag.x=posX;pcDrag.y=posY;var div=document.getElementById('pc'+pcDrag.id);div.style.left=posX+'px';div.style.top=posY+'px';if(pcDrag.shadowQ){div.style.filter=my.players[pcDrag.clr].glow;div.style.webkitFilter=my.players[pcDrag.clr].glow;}else{div.style.filter='none';div.style.webkitFilter='none';}}
function pcDrop(){var me=my.pcs[my.drag.index];var nx=(me.x/my.wd+0.5)<<0;var ny=(me.y/my.wd+0.5)<<0;me.dnx=nx;me.dny=ny;playerMove(me);}
function playerMove(pc){if(pc.clr!=turn){pc.showMeAt(pc.nx,pc.ny);return;}
var jumps=getJumps(turn);if(isLegalMove(pc)){if(jumps.length){console.log("playerMove","Should Jump");setMsg(my.players[turn].name+' Must Jump!');pc.showMeAt(pc.nx,pc.ny);}else{addHist(pc,null);tryKingMe(pc);pc.showMeAt(pc.dnx,pc.dny);nextTurn();}}else{var jumpedPc=isLegalJump(pc);if(jumpedPc){removePc(jumpedPc);addHist(pc,jumpedPc);tryKingMe(pc);pc.showMeAt(pc.dnx,pc.dny);if(my.multiJumpQ){jumps=getJumps(turn);if(jumps.length){var moreJumpsQ=false;for(var i=0;i');soundPlay('sndmove')}else{s=s.replace('to','('+jumpedPc.nx+','+jumpedPc.ny+')');soundPlay('sndtake')}
my.hist+=s;my.hist+='\n';}
function getDiags(pc){var diags;if(pc.typ=='KING'){diags=[[-1,-1],[1,-1],[-1,1],[1,1]];}else{if(pc.clr==0){diags=[[-1,-1],[1,-1]];}else{diags=[[-1,1],[1,1]];}}
return diags;}
function getJumps(clr){var jumps=[];for(var i=0;i=my.bdSize)return-1;if(ny>=my.bdSize)return-1;for(var i=0;ibestWt){bestWt=wt;bestMove=move;}}
return bestMove;}
function isLegalMove(pc){var destinationEmpty=isEmpty(pc.dnx,pc.dny);var dCol=pc.dnx;var dRow=pc.dny;var oCol=pc.nx;var oRow=pc.ny;var color=pc.clr;var type=pc.typ;var blackMove=color===0&&dRow+1===oRow;var redMove=color===1&&dRow-1===oRow;var kingMove=type==='KING'&&(dRow+1===oRow||dRow-1===oRow);var legalMove=(dCol+1===oCol||dCol-1===oCol)&&(blackMove||redMove||kingMove);return destinationEmpty&&legalMove;}
function isEmpty(nx,ny){for(var i=0;i';s+='';s+='
';s+='';s+='
';s+='';return s;}
function histPop(){document.getElementById('hist').value=my.hist;var pop=document.getElementById('histpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left=(w-320)/2+'px';}
function histYes(){var pop=document.getElementById('histpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';}
function optPopHTML(){var s='';s+='
';s+='
';s+='
';s+='
';s+='';s+='';s+='
';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=(Math.min(window.innerWidth,760)-340)/2+'px';}
function optYes(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';newGame();}
function optNo(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';}
function optChoose(n){console.log("optChoose",n);optYes();}
function getDropdownHTML(opts,funcName,id,chkNo){var s='';s+='';return s;}
function getRandomInt(min,max){return Math.floor(Math.random()*(max-min+1))+min;}
function AI(){}
AI.prototype.fmtBd=function(b){var s='';for(var i=0;ibest){best=worst;besti=i;}}
return moves[besti];};AI.prototype.copyBd=function(b){var newb=[];for(var i=0;i1)wantClr-=2;var diags=this.getDiags(clr,wantClr);for(var k=0;k=my.bdSize)return-1;if(c>=my.bdSize)return-1;return b[r][c];};AI.prototype.getScore=function(b){var v=0;for(var i=0;i';s+=prompt+':';for(var i=0;i';s+='';}
s+='';return s;}
function soundBtnHTML(){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()
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")}}