<html>
<head>
<title>Experimental Drag and Drop - RJM Programming - July, 2023 ... thanks to https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setData</title>
<style>
th.source {
border: 1px solid transparent;
}
</style>
<script type=text/javascript>
var playerb='Black';
var playerw='White';
var clonedata='', clonedatatwo='', pos3=0, pos4=0, secs=0, score=0, tdid='', tdcheck=true;
var tdnum=location.search.split('tdnum=')[1] ? eval(location.search.split('tdnum=')[1].split('&')[0]) : 9;
var across=location.search.split('across=')[1] ? eval(location.search.split('across=')[1].split('&')[0]) : 3;
var trad='';
var amove='';
if (document.URL.indexOf('traditional=') != -1) {
trad=decodeURIComponent(document.URL.split('traditional=')[1].split('&')[0]);
}
if (document.URL.indexOf('move=') != -1) {
amove=decodeURIComponent(document.URL.split('move=')[1].split('&')[0]);
}
var movefrom=-1, moveto=-1, nextmove=-1, mirroring=false;
var dragh=false;
var sdone=false;
var sourceid='sou' + 'rce';
var shuffle=('' + location.hash + ' ' + location.search + ' ').split('shuffle=')[1] ? true : false;
var yourblurb=location.search.split('yourblurb=')[1] ? decodeURIComponent('' + location.hash + ' ' + location.search.split('yourblurb=')[1].split('&')[0]).replace(/\+/g,' ').replace(/\ \ \ /g,' + ') : '';
var sourcenum=location.search.split('sourcenum=')[1] ? Math.floor(eval(('' + location.search.split('sourcenum=')[1].split('&')[0]) + '.0')) : 1;
if ((document.URL.split('#')[0] + '&').indexOf('sourcenum=&') != -1 && sourcenum == 1) { sourcenum=0; }
var originalsn=sourcenum;
var originalsh=shuffle;
var origsnc='';
var bdone=false;
var lastbco=null;
var lastoh='', prevlastoh='', prevlastih='', prevtih='', lohfulloh='', newlohfulloh='';
var lastih='', loh='', lohoh='';
var lastevid='', bcklastid='';
var lastid='';
var prefx='th';
var itisthiscmove='', lastitisthiscmove=' ';
var cpa=['bK','wK','bQ','wQ','bR1','wR1','bR2','wR2','bB1','wB1','bB2','wB2','bK1','wK1','bK2','wK2','bP1','wP1','bP2','wP2','bP3','wP3','bP4','wP4','bP5','wP5','bP6','wP6','bP7','wP7','bP8','wP8'];
var staidmap=[4,60,3,59,0,56,7,63, 2,58,5,61, 1,57,6,62, 8,48,9,49,10,50,11,51,12,52,13,53,14,54,15,55];
var occupiedlist=',', qid='', qqid='';
var blackchecked=false, blackcheckmated=false;
var whitechecked=false, whitecheckmated=false;
var fouroh='', eightoh='', sixoh='', spanzero='', tdtte='';
var wwwtdtte='', wwtdtte='', wtdtte='', wsixoh='', spanfive='', ppt=false;
var domcmds=[];
var wastitle='';
var gev=null, hostid='', prelegal=true, cm='';

function consolelog(what) {
if (document.URL.indexOf('/chess') != -1) {
if (document.getElementById('pstatus')) {
if (document.getElementById('pstatus').innerHTML.indexOf(' ... Your next move ') != -1) {
document.getElementById('pstatus').innerHTML='Move just made by ' + document.getElementById('pstatus').innerHTML.split('Your next move ')[eval(-1 + document.getElementById('pstatus').innerHTML.split('Your next move ').length)] + ' ... ' + what;
} else {
document.getElementById('pstatus').innerHTML+=' ... ' + what.split(' ... ')[0] + ' ... ';
}
}
}
console.log(what);
}

function ouralert(what) {
if (document.URL.indexOf('/chess') != -1) {
if (document.getElementById('pstatus')) {
if (document.getElementById('pstatus').innerHTML.indexOf(' ... ') != -1) {
if (document.getElementById('pstatus').innerHTML.indexOf(' ... Your next move ') != -1) {
document.getElementById('pstatus').innerHTML='Move just made by ' + document.getElementById('pstatus').innerHTML.split('Your next move ')[eval(-1 + document.getElementById('pstatus').innerHTML.split('Your next move ').length)] + ' ... ' + what;
} else {
document.getElementById('pstatus').innerHTML+=' ... ' + what.split(' ... ')[0] + ' ... ';
}
}
}
}
return alert(what);
}

function rerefit() {
document.title=wastitle;
}

function delayedrefit() {
refit(gev);
}

function refit(ev) {
var waspl=prelegal;
prelegal=true;
if (wastitle == '') { wastitle=document.title; }
//document.title=itisthiscmove + ' ' + ev.target.id + ' at refit';

//if (ev.target.id == 'mytable') { document.title='mytable'; return true; }

if (lastitisthiscmove != itisthiscmove && ev.target.id != 'mytable') {
ppt=false;
//document.title=itisthiscmove + ' ' + ev.target.id + ' 1 at refit';
if (itisthiscmove != '' && itisthiscmove != (ev.target.outerHTML.split(' data-piece="')[1]).substring(0,1)) {
if (waspl) { ouralert('It is not your turn.'); }
} else {
lastitisthiscmove=(itisthiscmove + ev.target.outerHTML.split(' data-piece="')[1]).substring(0,1);
itisthiscmove=lastitisthiscmove;
if (itisthiscmove == 'b') {
consolelog('Your next move ' + playerb + ' ... ');
} else {
consolelog('Your next move ' + playerw + ' ... ');
}
//ouralert('no1 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
if (ev.target.outerHTML.indexOf(' data-piece="') != -1) {
if (ev.target.outerHTML.split(' data-piece="')[1].substring(0,1) == (itisthiscmove + ev.target.outerHTML.split(' data-piece="')[1].substring(0,1)).substring(0,1)) {
//document.title=itisthiscmove + ' ' + ev.target.id + ' 1.0 at refit';
lohfulloh=ev.target.outerHTML;
newlohfulloh=ev.target.outerHTML;
hostid=bigv(newlohfulloh).split(' id="')[1].split('"')[0];
lastid=ev.target.id;
}
}
}
} else if (newlohfulloh != ev.target.outerHTML && ev.target.id != 'mytable') {
//ouralert('yes0 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
lohfulloh=newlohfulloh;
//document.title=itisthiscmove + ' ' + ev.target.id + ' 2 at refit';
lastoh=newlohfulloh; //ev.target.outerHTML;
lastih='>' + newlohfulloh.split('</')[0].split('>')[eval(-1 + newlohfulloh.split('</')[0].split('>').length)] + '<'; //'>' + ev.target.innerHTML + '<';
console.log('yes ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
if (lohfulloh != '') {
console.log("lohfulloh=" + lohfulloh);
//ouralert('yes2 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
if (lohfulloh.indexOf(' data-piece="') != -1) {
//ouralert('yes3 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
if (ev.target.outerHTML.indexOf(' data-piece="') != -1 && ev.target.outerHTML != lohfulloh) {
//ouralert('yes4 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
if (ev.target.outerHTML.split(' data-piece="')[1].substring(0,1) != lohfulloh.split(' data-piece="')[1].substring(0,1)) {
//ouralert('yes5 ' + lastitisthiscmove + ' ' + itisthiscmove + ' ' + ev.target.id);
console.log('Potential piece take');
ppt=true;
}
}
}
}
lastid=ev.target.id;
bcklastid=lastid;
loh=ev.target.id;
lohoh=bigv(ev.target.outerHTML.split('>')[0] + '></' + ev.target.outerHTML.substring(1).split(' ')[0].split('>')[0] + '>');


console.log("Drop 3");
if (newlohfulloh.indexOf(' data-piece="' + itisthiscmove + 'R') != -1 && ev.target.outerHTML.indexOf(' data-piece="' + itisthiscmove + 'K') != -1) {
if (mightbecastling(ev.target.outerHTML.split(' data-piece="')[1].split('"')[0], newlohfulloh.split(' data-piece="')[1].split('"')[0], ev.target.outerHTML, newlohfulloh) == 1) {
prelegal=false;
}
} else if (newlohfulloh.indexOf(' data-piece="' + itisthiscmove + 'K') != -1 && ev.target.outerHTML.indexOf(' data-piece="' + itisthiscmove + 'R') != -1) {
if (mightbecastling(ev.target.outerHTML.split(' data-piece="')[1].split('"')[0], newlohfulloh.split(' data-piece="')[1].split('"')[0], ev.target.outerHTML, newlohfulloh) == 1) {
prelegal=false;
}
}

if (!prelegal) {
//ouralert('Illegal move ... please start again');
lastitisthiscmove = itisthiscmove + ' ';
//ouralert(lastitisthiscmove + '!');
hostid='';
} else if (islegal()) {
if (hostid != '') {
document.getElementById(hostid).innerHTML='';
} else {
document.getElementById('mytable').innerHTML=document.getElementById('mytable').innerHTML.replace(newlohfulloh, '');
}
gev=ev;
setTimeout(gevit,1500); //ev.target.innerHTML=newlohfulloh;
//itisthiscmove=itisthiscmove.replace('w','B').replace('b','W').toLowerCase();
lastitisthiscmove = itisthiscmove + ' ';
hostid='';
} else {
if (waspl) { ouralert('Illegal move ... please start again'); }
lastitisthiscmove = itisthiscmove + ' ';
hostid='';
}


// }
}
setTimeout(rerefit, 3000);
}

function gevit() {
gev.target.innerHTML=newlohfulloh;
if (document.getElementById(newlohfulloh.split(' id="')[1].split('"')[0])) {
adddrop(newlohfulloh.split(' id="')[1].split('"')[0]);
}
//ouralert('' + gev.target.id + '=' + newlohfulloh);
newlohfulloh='';
lastitisthiscmove = itisthiscmove + ' ';
}

function dodoms() {
var stopit=false;
if (document.getElementById('span4') && fouroh == '') { fouroh=document.getElementById('span4').outerHTML; }
if (document.getElementById('span5') && wsixoh == '') { wsixoh=document.getElementById('span5').outerHTML; }
if (document.getElementById('span6') && sixoh == '') { sixoh=document.getElementById('span6').outerHTML; }
if (document.getElementById('span0') && spanzero == '') { spanzero=document.getElementById('span0').outerHTML; }
if (document.getElementById('span1') && spanfive == '') { spanfive=document.getElementById('span1').outerHTML; }
if (document.getElementById('td22') && tdtte == '') { tdtte=document.getElementById('td22').outerHTML.split('>')[0] + '></td>'; }
if (document.getElementById('td211') && wtdtte == '') { wtdtte=document.getElementById('td211').outerHTML.split('>')[0] + '></td>'; }
if (document.getElementById('td193') && wwtdtte == '') { wwtdtte=document.getElementById('td193').outerHTML.split('>')[0] + '></td>'; }
if (document.getElementById('td11') && wwwtdtte == '') { wwwtdtte=document.getElementById('td11').outerHTML.split('>')[0] + '></td>'; }

if (nextmove != -1) {
var tds=document.getElementsByTagName('td');
for (var itds=0; itds<tds.length; itds++) {
if (tds[itds].outerHTML.indexOf(' data-square="' + nextmove + '"') != -1) {
if (tds[itds].innerHTML.indexOf('</span>') != -1) {
document.getElementById(tds[itds].innerHTML.split(' id="')[1].split('"')[0]).click();
} else {
tds[itds].click();
}
}
}
nextmove=-1;
}

if (document.getElementById('pstatus')) {
if (document.getElementById('pblack')) {
playerb=document.getElementById('pblack').innerText;
}
if (document.getElementById('pwhite')) {
playerw=document.getElementById('pwhite').innerText;
}
if (eval('' + ('' + document.getElementById('pstatus').getAttribute('data-decided')).replace(/^null$/g,'').replace(/^undefined$/g,'').length) == 2) {
if (document.getElementById('pblack')) {
document.getElementById('pblack').style.display='none';
}
if (document.getElementById('pwhite')) {
document.getElementById('pwhite').style.display='none';
}
if (document.getElementById('pvs')) {
document.getElementById('pvs').style.display='none';
}
if (playerb != 'Black') {
playerb+=' (black)';
}
if (playerw != 'White') {
playerw+=' (white)';
}
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
}

if (eval('' + ('' + document.getElementById('pstatus').getAttribute('data-decided')).replace(/^null$/g,'').replace(/^undefined$/g,'').length) == 3) {
if (document.getElementById('pstatus').innerText == '') {
document.getElementById('pstatus').innerHTML='Welcome to the Chess Game between ' + playerb + ' (black) and ' + playerw + ' (white).';
}
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
}

if (eval('' + ('' + document.getElementById('pstatus').getAttribute('data-decided')).replace(/^null$/g,'').replace(/^undefined$/g,'').length) == 4) {
if (itisthiscmove != '') {
if (itisthiscmove == 'b') {
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
document.getElementById('pstatus').innerHTML='Your first move ' + playerb + ' ... ';
} else {
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
document.getElementById('pstatus').innerHTML='Your first move ' + playerw + ' ... ';
}
} else if (lastoh.indexOf(' data-piece="') != -1) {
if (lastoh.indexOf(' data-piece="b') != -1) {
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
document.getElementById('pstatus').innerHTML='Your first move ' + playerb + ' ... ';
} else {
document.getElementById('pstatus').setAttribute('data-decided', document.getElementById('pstatus').getAttribute('data-decided') + ' ');
document.getElementById('pstatus').innerHTML='Your first move ' + playerw + ' ... ';
}
}
}

if (eval('' + ('' + document.getElementById('pstatus').getAttribute('data-decided')).replace(/^null$/g,'').replace(/^undefined$/g,'').length) == 5) {
}
}
for (var ikj=0; ikj<domcmds.length; ikj++) {
if (!stopit && domcmds[ikj] != '') {
stopit=true;
//if (prompt(domcmds[ikj], domcmds[ikj])) {
//if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
// var huh=prompt(domcmds[ikj], domcmds[ikj]);
//}
if (document.URL.indexOf('/chess') != -1) {
eval(domcmds[ikj]);
//rejig();
}
//}
domcmds[ikj]='';

}
}
//domcmds=[];
setTimeout(dodoms, 1000);
}

function innards(inele) {
var outele=inele;
if (inele.indexOf('<span') > 0) {
outele='<span' + inele.split('</span>')[0].split('<span')[eval(-1 + inele.split('</span>')[0].split('<span').length)] + '</span>';
}
//ouralert('innards:' + outele);
return outele;
}

function adddrop(inelid) {
document.getElementById(inelid).addEventListener("drop", (ev) => {
console.log("Drop 1");
if (lohfulloh != '') {
console.log("lohfulloh=" + lohfulloh);
if (lohfulloh.indexOf(' data-piece="') != -1) {
if (ev.target.outerHTML.indexOf(' data-piece="') != -1 && ev.target.outerHTML != lohfulloh) {
if (ev.target.outerHTML.split(' data-piece="')[1].substring(0,1) != lohfulloh.split(' data-piece="')[1].substring(0,1)) {
console.log('Potential piece take');
ppt=true;
}
}
}
}
loh=ev.target.id;
lohoh=bigv(ev.target.outerHTML.split('>')[0] + '></' + ev.target.outerHTML.substring(1).split(' ')[0].split('>')[0] + '>');
//if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
// document.title='ev.preventDefault(); //1';
//}
ev.preventDefault();
// Get the data, which is the id of the source element
const data = ev.dataTransfer.getData("text");
const source = document.getElementById(data);

console.log('' + ev.target.id);
if (!document.getElementById('callback')) {
lastevid=ev.target.id;
//ouralert(lastevid);
//ev.target.setAttribute('draggable', true);
if (lastoh == '') {
//ouralert('suspicious ' + document.getElementById(sourceid).outerHTML);
lastoh=ev.target.outerHTML;
lastih='>' + ev.target.innerHTML + '<';
lastid=ev.target.id;
} else if (prefx == 'span') {
if (lastid.indexOf(' ') != -1) {
lastid=lastid.trim();
} else {
lastid=ev.target.id;
}
}
if (document.URL.indexOf('/chess') != -1) {
setTimeout(lastohit, 1000);
if (('' + ev.target.style.backgroundColor).indexOf(',0.6') != -1 || ('' + ev.target.style.backgroundColor).indexOf(',0.5') != -1) {
//ouralert('564 ' + ev.target.getAttribute('data-square'));
ev.target.style.filter='invert(1)';
ev.target.style.backgroundColor='rgba(255,255,255,0.6)';
}
}
if (('' + ev.target.id).substring(0,2) == 'td' && secs > 0 && document.URL.indexOf('/planet_') == -1) {
score+=eval(ev.target.innerHTML.substring(0,1));
}
} else if (document.getElementById('callback')) {
secs++;
if (('' + ev.target.getAttribute('data-answer')) == ('' + document.getElementById('source').getAttribute('data-answer')) || ('' + ev.target.getAttribute('data-answer')) == ('' + document.getElementById(sourceid).getAttribute('data-answer'))) {
score++;
document.getElementById('score').innerHTML='Score: ' + score + '/' + secs + '';
} else {
document.getElementById('score').innerHTML='Score: ' + score + '/' + secs + '';
if (document.getElementById('source').outerHTML.indexOf('<ta' + 'ble') == 0) {
ouralert(('Correct answer was ' + document.getElementById(sourceid).getAttribute('data-answer')).replace('null',''));
} else {
ouralert(('Correct answer was ' + document.getElementById('source').getAttribute('data-answer')).replace('null',''));
}
}
location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs;
}
if (1 == 2) {
clonedatatwo=document.getElementById(sourceid).outerHTML;
document.getElementById('mytable').innerHTML=document.getElementById('mytable').innerHTML.replace(clonedatatwo, '');
ev.target.innerHTML=ev.target.innerHTML.substring(0,1) + clonedatatwo;
} else if (secs > 0 && (9 == 9 || ('' + ev.target.id).substring(0,2) == 'td')) {
if (source) { source.style.cursor='progress'; }
clonedatatwo=document.getElementById(sourceid).outerHTML;
andlater();
//document.getElementById('mytable').innerHTML=document.getElementById('mytable').innerHTML.replace(clonedatatwo, '');
//ev.target.innerHTML=ev.target.innerHTML.substring(0,1) + clonedatatwo;
//document.getElementById('target').appendChild(source);
if (('' + ev.target.id).substring(0,2) != 'td') {
document.getElementById('target').insertAdjacentHTML('beforeend', clonedatatwo);
} else {
if (source) { source.style.cursor='progress'; }
ev.target.insertAdjacentHTML('beforeend', clonedatatwo);
}
} else {
try {
ev.target.appendChild(source);
} catch(ers) { }
}

if (ev.touches) {
if (ev.touches[0].pageX) {
pos3 = ev.touches[0].pageX;
pos4 = ev.touches[0].pageY;
} else {
pos3 = ev.touches[0].clientX;
pos4 = ev.touches[0].clientY;
}
console.log('pos3 = ' + pos3 + ',pos4 = ' + pos4);
} else if (ev.clientX || ev.clientY) {
pos3 = ev.clientX;
pos4 = ev.clientY;
console.log('pos3 = ' + pos3 + ' ,pos4 = ' + pos4);
} else {
pos3 = ev.pageX;
pos4 = ev.pageY;
console.log('pos3 = ' + pos3 + ', pos4 = ' + pos4);
}

});
}

function bigv(inspan) {
var outspan=inspan;
if (inspan.trim().indexOf('<span') == 0 && document.getElementById('target').innerHTML.indexOf(inspan.split('>')[0]) != -1) {
outspan='<' + document.getElementById('target').innerHTML.split(inspan.split('>')[0])[0].split('<')[eval(-1 + document.getElementById('target').innerHTML.split(inspan.split('>')[0])[0].split('<').length)];
outspan+='</' + outspan.substring(1).split(' ')[0].split('>')[0] + '>';
//ouralert('Found ' + outspan);
} //else {
//ouralert('did not find ' + inspan);
//}
return outspan;
}

function bigabb(infind) {
var prefxz='';
var outfind=infind;
var lastchr=infind.slice(-1);
var firstlk=infind.split(lastchr)[0];
var vbits=document.getElementById('target').innerHTML.split(firstlk);
if (eval('' + vbits.length) > 1) {
prefxz='<' + document.getElementById('target').innerHTML.split(firstlk)[0].split('<')[eval(-1 + document.getElementById('target').innerHTML.split(firstlk)[0].split('<').length)];
outfind=prefxz + firstlk + vbits[1].split(lastchr)[0] + lastchr;
}
return outfind;
}

function abb(infind) {
var outfind=infind;
var lastchr=infind.slice(-1);
var firstlk=infind.split(lastchr)[0];
var vbits=document.getElementById('target').innerHTML.split(firstlk);
if (eval('' + vbits.length) > 1) {
outfind=firstlk + vbits[1].split(lastchr)[0] + lastchr;
}
return outfind;
}

function epy(thething, thelook) {
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
var theid=document.getElementById('mytable').innerHTML.split(thething)[0].split(' id="')[eval(-1 + document.getElementById('mytable').innerHTML.split(thething)[0].split(' id="').length)].split('"')[0];
var thenid='t' + document.getElementById('mytable').innerHTML.split(thelook.split('>')[0])[0].split(' id="t')[eval(-1 + document.getElementById('mytable').innerHTML.split(thelook.split('>')[0])[0].split(' id="t').length)].split('"')[0];
var ithing=innards(thething), thenum=-1, thetds=[], jnum=0, ijk=0;
if (thelook.indexOf(' data-square="') != -1) {
thenum=eval(thelook.split(' data-square="')[1].split('"')[0]);
thetds=document.getElementsByTagName('td');
for (ijk=0; ijk<thetds.length; ijk++) {
if (thetds[ijk].outerHTML.indexOf(' class="black"') != -1 || thetds[ijk].outerHTML.indexOf(' class="white"') != -1) { jnum++; }
if (jnum == thenum || thetds[ijk].outerHTML.indexOf(thelook.split('>')[0]) != -1) {
//ouralert(thenid + ' vs ' + thetds[ijk].id);
thenid=thetds[ijk].id;
if (thetds[ijk].outerHTML.indexOf(thelook.split('>')[0]) != -1) { jnum=-999; }
}
}
}
//ouralert("document.getElementById('" + theid + "').innerHTML=''; " + "document.getElementById('" + thenid + "').innerHTML='" + ithing + "'; ");
domcmds.push("document.getElementById('" + theid + "').innerHTML=''; ");
domcmds.push("document.getElementById('" + thenid + "').innerHTML='" + ithing + "'; ");
}
return thething;
}

function mightbecastling(pthispiece, potherpiece, pthisoh, potheroh) { // thanks to https://www.chessable.com/blog/how-to-castle-in-chess/
var pretval=0, delone='', deltwo='';
var bigih=document.getElementById('target').innerHTML;
var inpthisoh=pthisoh;
var inpotheroh=potheroh;
if (inpthisoh.indexOf(' data-square="') == -1) {
inpthisoh='<td' + bigih.split(pthisoh)[0].split('<td')[eval(-1 + bigih.split(pthisoh)[0].split('<td').length)];
}
if (inpotheroh.indexOf(' data-square="') == -1) {
inpotheroh='<td' + bigih.split(potheroh)[0].split('<td')[eval(-1 + bigih.split(potheroh)[0].split('<td').length)];
}
if (pthispiece.substring(0,1) != potherpiece.substring(0,1)) { return -5; }
if ((pthispiece.substring(1).substring(0,1) == 'K' && eval('' + pthispiece.length) == 2) && (potherpiece.substring(1).substring(0,1) == 'R' && eval('' + potherpiece.length) == 3)) {
if (pthispiece.substring(0,1) == 'w' && inpthisoh.indexOf(' data-square="61"') != -1 && (inpotheroh.indexOf(' data-square="64"') != -1 || inpotheroh.indexOf(' data-square="57"') != -1)) {
pretval=1;
if (inpotheroh.indexOf(' data-square="57"') != -1 && (bigih.indexOf(abb(' data-square="58">') + '</') == -1 || bigih.indexOf(abb(' data-square="59">') + '</') == -1 || bigih.indexOf(abb(' data-square="60">') + '</') == -1)) {
pretval=-1;
} else if (inpotheroh.indexOf(' data-square="57"') != -1) { //newish
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="60">') + '</', abb(' data-square="60">') + potheroh + '</').replace(abb(' data-square="59">') + '</', abb(' data-square="59">') + pthisoh + '</');




if (wwtdtte != '') { lohoh=wwtdtte; } //rmtwowk
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));
bigih=bigih.replace(epy(pthisoh,' data-square="60">'),'').replace(epy(potheroh,' data-square="59">'),'');
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//bigih=bigih.replace(abb(' data-square="59">') + '</span>', abb(' data-square="59">') + innards(potheroh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="59">') + '</', abb(' data-square="59">') + innards(potheroh) + '</');
// + lohoh);
//ouralert('About to Castle1 the rook ' + abb(' data-square="60">') + innards(potheroh) + '</');
bigih=bigih.replace(bigabb(' data-square="60">') + '</', bigabb(' data-square="60">') + innards(pthisoh) + '</'); // + lohoh.split('</td>')[0]);
//ouralert('About to Castle2 ' + innards(potheroh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22 ' + innards(potheroh));
//ouralert('About to Castle223');
if (wwtdtte != '') {
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
domcmds.push("document.getElementById('td202').innerHTML='" + wsixoh + "'; ");
domcmds.push("document.getElementById('td203').innerHTML='" + spanfive + "'; ");
domcmds.push("document.getElementById('tr8').innerHTML='" + wwtdtte + "' + document.getElementById('tr8').innerHTML; itisthiscmove='b'; consolelog('Your next move ' + playerb + ' ... '); adddrop('" + lohoh.split(' id="')[1].split('"')[0] + "'); ");
}
}
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
if (inpotheroh.indexOf(' data-square="64"') != -1 && (bigih.indexOf(abb(' data-square="62">') + '</') == -1 || bigih.indexOf(abb(' data-square="63">') + '</') == -1)) {
//ouralert(bigih.split(' data-square="62"')[1].substring(0,40) + '*62');
//ouralert(bigih.split(' data-square="63"')[1].substring(0,40) + '*63');
pretval=-1;
} else if (inpotheroh.indexOf(' data-square="64"') != -1) { //new
//ouralert('About to Castle ' + lastoh);
bigih=bigih.replace(epy(pthisoh,' data-square="63">'),'').replace(epy(potheroh,' data-square="62">'),'');
//ouralert('About to Castle1 the rook ' + abb(' data-square="62">') + innards(potheroh) + '</');
bigih=bigih.replace(abb(' data-square="62">') + '</', abb(' data-square="62">') + innards(potheroh) + '</');
//ouralert('About to Castle12 the king ' + abb(' data-square="63">') + innards(pthisoh) + '</ ... ' + bigih.split(' data-square="63"')[1] + ' +++ ' + lohoh);
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; }
bigih=bigih.replace(abb(' data-square="63">') + '</td>', abb(' data-square="63">') + innards(pthisoh) + '</td>' + lohoh);
//ouralert('About to Castle2');
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22');
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}
}
}
if (pthispiece.substring(0,1) == 'b' && inpthisoh.indexOf(' data-square="5"') != -1 && (inpotheroh.indexOf(' data-square="8"') != -1 || inpotheroh.indexOf(' data-square="1"') != -1)) {
pretval=1;
if (inpotheroh.indexOf(' data-square="8"') != -1 && (bigih.indexOf(abb(' data-square="6">') + '</') == -1 || bigih.indexOf(abb(' data-square="7">') + '</') == -1)) {
pretval=-1;
} else if (inpotheroh.indexOf(' data-square="8"') != -1) { // new
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="6">') + '</', abb(' data-square="6">') + pthisoh + '</').replace(abb(' data-square="7">') + '</', abb(' data-square="7">') + potheroh + '</');

//if (eightoh != '') { lohoh=eightoh; }
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));

bigih=bigih.replace(epy(pthisoh, ' data-square="7">'),'').replace(epy(potheroh, ' data-square="6">'),'');
//ouralert('About to Castle1 the rook ' + abb(' data-square="6">') + innards(potheroh) + '</');
bigih=bigih.replace(abb(' data-square="6">') + '</', abb(' data-square="6">') + innards(potheroh) + '</');
//ouralert('About to Castle12 the king ' + abb(' data-square="7">') + innards(pthisoh) + '</ ... ' + bigih.split(' data-square="7"')[1] + ' +++ ' + lohoh);
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//if (bigih.indexOf(abb(' data-square="7">') + '</') == -1) {
// ouralert('Not found ' + bigabb(' data-square="7">') + '</');
//} else {
// ouralert(' ... ' + bigv(lohoh));
//}
//bigih=bigih.replace(abb(' data-square="7">') + '</span>', abb(' data-square="7">') + innards(pthisoh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="7">') + '</', abb(' data-square="7">') + innards(pthisoh) + '</');
// + lohoh);
//ouralert('About to Castle2 ' + innards(pthisoh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
if (eightoh != '') {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
//domcmds.push("document.getElementById('td23').innerHTML='" + innards(potheroh) + "'; ");
//domcmds.push("document.getElementById('td31').innerHTML='" + innards(pthisoh) + "'; ");
//domcmds.push("document.getElementById('td32').innerHTML=''; ");
eightoh=eightoh;
} else {
document.getElementById('tr1').innerHTML+=eightoh;
document.getElementById('td31').innerHTML=innards(pthisoh);
domcmds.push("document.getElementById('td31').innerHTML='" + innards(pthisoh) + "'; ");
}
}
//ouralert('About to Castle22 ' + innards(pthisoh));
//document.getElementById('td31').innerHTML=innards(pthisoh);
//ouralert('About to Castle223');
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
if (inpotheroh.indexOf(' data-square="1"') != -1 && (bigih.indexOf(abb(' data-square="4">') + '</') == -1 || bigih.indexOf(abb(' data-square="2">') + '</') == -1 || bigih.indexOf(abb(' data-square="3">') + '</') == -1)) {
pretval=-1;
} else if (inpotheroh.indexOf(' data-square="1"') != -1) { //newer
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="3">') + '</', abb(' data-square="3">') + pthisoh + '</').replace(abb(' data-square="4">') + '</', abb(' data-square="4">') + potheroh + '</');


if (wwwtdtte != '') { lohoh=wwwtdtte; } //rmtwowk4
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));
bigih=bigih.replace(epy(pthisoh,' data-square="4">'),'').replace(epy(potheroh,' data-square="3">'),'');
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//bigih=bigih.replace(abb(' data-square="3">') + '</span>', abb(' data-square="3">') + innards(potheroh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="3">') + '</', abb(' data-square="3">') + innards(potheroh) + '</');
// + lohoh);
//ouralert('About to Castle1 the rook ' + abb(' data-square="4">') + innards(potheroh) + '</');
bigih=bigih.replace(bigabb(' data-square="4">') + '</', bigabb(' data-square="4">') + innards(pthisoh) + '</'); // + lohoh.split('</td>')[0]);
//ouralert('About to Castle2 ' + innards(potheroh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22 ' + innards(potheroh));
//ouralert('About to Castle223');
if (wwwtdtte != '') {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
domcmds.push("document.getElementById('td13').innerHTML='" + fouroh + "'; ");
domcmds.push("document.getElementById('td21').innerHTML='" + spanzero + "'; ");
domcmds.push("document.getElementById('tr1').innerHTML='" + wwwtdtte + "' + document.getElementById('tr1').innerHTML; itisthiscmove='w'; consolelog('Your next move ' + playerw + ' ... '); adddrop('" + lohoh.split(' id="')[1].split('"')[0] + "'); ");
}
}
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
}
} else if ((potherpiece.substring(1).substring(0,1) == 'K' && eval('' + potherpiece.length) == 2) && (pthispiece.substring(1).substring(0,1) == 'R' && eval('' + pthispiece.length) == 3)) {

if (potherpiece.substring(0,1) == 'w' && inpotheroh.indexOf(' data-square="61"') != -1 && (inpthisoh.indexOf(' data-square="64"') != -1 || inpthisoh.indexOf(' data-square="57"') != -1)) {
pretval=1;
if (inpthisoh.indexOf(' data-square="57"') != -1 && (bigih.indexOf(abb(' data-square="58">') + '</') == -1 || bigih.indexOf(abb(' data-square="59">') + '</') == -1 || bigih.indexOf(abb(' data-square="60">') + '</') == -1)) {
pretval=-1;
} else if (inpthisoh.indexOf(' data-square="57"') != -1) { // new
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="60">') + '</', abb(' data-square="60">') + pthisoh + '</').replace(abb(' data-square="59">') + '</', abb(' data-square="59">') + potheroh + '</');



if (wtdtte != '') { lohoh=wtdtte; } //rmtwow
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));
bigih=bigih.replace(epy(pthisoh,' data-square="60">'),'').replace(epy(potheroh,' data-square="59">'),'');
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//bigih=bigih.replace(abb(' data-square="59">') + '</span>', abb(' data-square="59">') + innards(potheroh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="59">') + '</', abb(' data-square="59">') + innards(potheroh) + '</');
// + lohoh);
//ouralert('About to Castle1 the rook ' + abb(' data-square="60">') + innards(potheroh) + '</');
bigih=bigih.replace(bigabb(' data-square="60">') + '</', bigabb(' data-square="60">') + innards(pthisoh) + '</'); // + lohoh.split('</td>')[0]);
//ouralert('About to Castle2 ' + innards(potheroh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22 ' + innards(potheroh));
//ouralert('About to Castle223');
if (wtdtte != '') {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {

//document.getElementById('td202').innerHTML=sixoh;
domcmds.push("document.getElementById('td202').innerHTML='" + wsixoh + "'; ");
//document.getElementById('td203').innerHTML=spanzero;
domcmds.push("document.getElementById('td203').innerHTML='" + spanfive + "'; ");
//document.getElementById('td22').innerHTML='';
//domcmds.push("document.getElementById('td22').innerHTML=''; ");
domcmds.push("document.getElementById('tr8').innerHTML=document.getElementById('tr8').innerHTML.replace('" + spanfive + "', '" + spanfive + "</td>' + '" + wtdtte.split('</td>')[0] + "'); itisthiscmove='b'; consolelog('Your next move ' + playerb + ' ... '); adddrop('" + lohoh.split(' id="')[1].split('"')[0] + "'); ");
}
}
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
if (inpthisoh.indexOf(' data-square="64"') != -1 && (bigih.indexOf(abb(' data-square="62">') + '</') == -1 || bigih.indexOf(abb(' data-square="63">') + '</') == -1)) {
ouralert(bigih.split(' data-square="62"')[1].substring(0,40) + '!62');
ouralert(bigih.split(' data-square="63"')[1].substring(0,40) + '!63');
pretval=-1;
} else if (inpthisoh.indexOf(' data-square="64"') != -1) { // new
//ouralert('About to castle');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//ouralert('About to castle1');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="63">') + '</', abb(' data-square="63">') + pthisoh + '</').replace(abb(' data-square="62">') + '</', abb(' data-square="62">') + potheroh + '</');
//ouralert('About to castle2');

//ouralert('About to Castle ' + lastoh);
bigih=bigih.replace(epy(pthisoh,' data-square="62">'),'').replace(epy(potheroh,' data-square="63">'),'');
if (bigih .indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; }
//ouralert('About to Castle12 the king ' + abb(' data-square="63">') + innards(pthisoh) + '</ ... ' + bigih.split(' data-square="63"')[1] + ' +++ ' + lohoh);
bigih=bigih.replace(abb(' data-square="63">') + '</td>', abb(' data-square="63">') + innards(potheroh) + '</td>');
//ouralert('About to Castle2');
//ouralert('About to Castle1 the rook ' + abb(' data-square="62">') + innards(potheroh) + '</');
if (lohoh == '') {
bigih=bigih.replace(abb(' data-square="62">') + '</', abb(' data-square="62">') + innards(pthisoh) + '</');
} else {
bigih=bigih.replace(bigabb(' data-square="62">') + '</', lohoh + bigabb(' data-square="62">') + innards(pthisoh) + '</');
}
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22');
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}

}
}
if (potherpiece.substring(0,1) == 'b' && inpotheroh.indexOf(' data-square="5"') != -1 && (inpthisoh.indexOf(' data-square="8"') != -1 || inpthisoh.indexOf(' data-square="1"') != -1)) {
pretval=1;
if (inpthisoh.indexOf(' data-square="8"') != -1 && (bigih.indexOf(abb(' data-square="6">') + '</') == -1 || bigih.indexOf(abb(' data-square="7">') + '</') == -1)) {
pretval=-1;
} else if (inpthisoh.indexOf(' data-square="8"') != -1) { // new if
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="6">') + '</', abb(' data-square="6">') + potheroh + '</').replace(abb(' data-square="7">') + '</', abb(' data-square="7">') + pthisoh + '</');


//if (eightoh != '') { lohoh=eightoh; } //rm
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));
bigih=bigih.replace(epy(pthisoh,' data-square="6">'),'').replace(epy(potheroh,' data-square="7">'),'');
//ouralert('About to Castle12 the king ' + abb(' data-square="7">') + innards(potheroh) + '</ ... ' + bigih.split(' data-square="7"')[1] + ' +++ ' + lohoh);
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//if (bigih.indexOf(abb(' data-square="7">') + '</') == -1) {
// ouralert('Not found ' + bigabb(' data-square="7">') + '</');
//} else {
// ouralert(' ... ' + bigv(lohoh));
//}
//bigih=bigih.replace(abb(' data-square="7">') + '</span>', abb(' data-square="7">') + innards(potheroh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="7">') + '</', abb(' data-square="7">') + innards(potheroh) + '</');
// + lohoh);
//ouralert('About to Castle1 the rook ' + abb(' data-square="6">') + innards(potheroh) + '</');
bigih=bigih.replace(bigabb(' data-square="6">') + '</', lohoh + bigabb(' data-square="6">') + innards(pthisoh) + '</');
//ouralert('About to Castle2 ' + innards(potheroh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22 ' + innards(potheroh));
//document.getElementById('td31').innerHTML=innards(potheroh);
//ouralert('About to Castle223');
if (sixoh != '') {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
//document.getElementById('tr1').innerHTML+=eightoh;
document.getElementById('td23').innerHTML=sixoh;
domcmds.push("document.getElementById('td23').innerHTML='" + sixoh + "'; ");
}
}
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
if (inpthisoh.indexOf(' data-square="1"') != -1 && (bigih.indexOf(abb(' data-square="4">') + '</') == -1 || bigih.indexOf(abb(' data-square="2">') + '</') == -1 || bigih.indexOf(abb(' data-square="3">') + '</') == -1)) {
pretval=-1;
} else if (inpthisoh.indexOf(' data-square="1"') != -1) { // new if
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(pthisoh,'').replace(potheroh,'');
//document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(abb(' data-square="3">') + '</', abb(' data-square="3">') + potheroh + '</').replace(abb(' data-square="4">') + '</', abb(' data-square="4">') + pthisoh + '</');


if (tdtte != '') { lohoh=tdtte; } //rmtwo
//ouralert('About to Castle ' + lastoh + ' +++ ' + pthisoh + ' --- ' + innards(pthisoh));
bigih=bigih.replace(epy(pthisoh,' data-square="4">'),'').replace(epy(potheroh,' data-square="3">'),'');
//ouralert('About to Castle12 the king ' + abb(' data-square="7">') + innards(potheroh) + '</ ... ' + bigih.split(' data-square="7"')[1] + ' +++ ' + lohoh);
if (bigih.indexOf(lohoh.split('</')[0]) != -1) { lohoh=''; } //else { ouralert('found'); }
//if (bigih.indexOf(abb(' data-square="7">') + '</') == -1) {
// ouralert('Not found ' + bigabb(' data-square="7">') + '</');
//} else {
// ouralert(' ... ' + bigv(lohoh));
//}
//bigih=bigih.replace(abb(' data-square="3">') + '</span>', abb(' data-square="3">') + innards(potheroh) + '</span></td>' + bigv(lohoh).split('</td>')[0]);
bigih=bigih.replace(abb(' data-square="3">') + '</', abb(' data-square="3">') + innards(potheroh) + '</');
// + lohoh);
//ouralert('About to Castle1 the rook ' + abb(' data-square="4">') + innards(potheroh) + '</');
bigih=bigih.replace(bigabb(' data-square="4">') + '</', bigabb(' data-square="4">') + innards(pthisoh) + '</'); // + lohoh.split('</td>')[0]);
//ouralert('About to Castle2 ' + innards(potheroh));
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('target').innerHTML=bigih;
}
//ouralert('About to Castle22 ' + innards(potheroh));
//document.getElementById('td31').innerHTML=innards(potheroh);
//ouralert('About to Castle223');
if (tdtte != '') {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {

//document.getElementById('td13').innerHTML=sixoh;
domcmds.push("document.getElementById('td13').innerHTML='" + sixoh + "'; ");
//document.getElementById('td21').innerHTML=spanzero;
domcmds.push("document.getElementById('td21').innerHTML='" + spanzero + "'; ");
//document.getElementById('td22').innerHTML='';
//domcmds.push("document.getElementById('td22').innerHTML=''; ");
domcmds.push("document.getElementById('tr1').innerHTML=document.getElementById('tr1').innerHTML.replace('" + spanzero + "', '" + spanzero + "</td>' + '" + tdtte.split('</td>')[0] + "'); itisthiscmove='w'; consolelog('Your next move ' + playerw + ' ... '); adddrop('" + lohoh.split(' id="')[1].split('"')[0] + "'); ");
}
}
if (lohoh != '') {
adddrop(lohoh.split(' id="')[1].split('"')[0]);
lohoh='';
}



}
}
} else {
//ouralert('pthisoh=' + pthisoh + ' and potheroh=' + potheroh);
pretval=-2;
}
if (pretval == 1) {
itisthiscmove=pthispiece.substring(0,1).replace('w','B').replace('b','W').toLowerCase();
if (itisthiscmove == 'b') {
consolelog('Your next move ' + playerb + ' ... ');
} else {
consolelog('Your next move ' + playerw + ' ... ');
}

}
return pretval;
}

function islegal() {
var mbcrval=0;
var sat=0, ihthere=false, thispiece='', otherpiece='';
var sfor=1
var retval=true, adjective='', directionally='';
cm='';
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log(34);
}
if (document.URL.indexOf('/chess') != -1 && !document.getElementById('fdz') && lastoh.indexOf(' id="') != -1 && lastoh.indexOf('<span') == 0) {

if (newlohfulloh != '' && loh != '' && lastid == '') { lastid=loh; } else if (newlohfulloh != '' && bcklastid != '' && lastid == '') { lastid=bcklastid; }

bcklastid='';

if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log(35);
}
console.log('1');
if (document.getElementById('fnodz')) {
console.log('11');
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log(36);
}
if (document.getElementById('mytable').innerHTML.indexOf(lastoh) == -1) {
retval=false;
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log('illegal');
}
} else {
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log('debatable');
}
var ioff=0;
//if (thispiece.substring(0,1) == 'w') { ioff=1; }
console.log('111');
// document.getElementById('target').innerHTML=document.getElementById('target').innerHTML.replace(lastoh, '');
// document.getElementById(lastid).innerHTML=lastoh;
// lastoh='';
// lastih='';
var thisid=lastoh.split(' id="')[1].split('"')[0];
thispiece=('' + document.getElementById(thisid).getAttribute('data-piece')).replace(/^null$/g,'').replace(/^undefined$/g,'');
if ((itisthiscmove + thispiece).substring(0,1) != thispiece.substring(0,1)) {
console.log('It is not your turn for a move.' + lohfulloh + ' ' + thisid + ' ' + lastoh);
ouralert('It is not your turn for a move.');
return false;
}
//ouralert('*' + lastid + '!');
if (loh != '') { lastid=loh; }

var goodthis='';
var thissq=-1;
if (document.getElementById(lastid).outerHTML.indexOf('<span') == 0) {
thissq=('' + bigv(document.getElementById(lastid).outerHTML).split(' data-square="')[eval(-1 + bigv(document.getElementById(lastid).outerHTML).split(' data-square="').length)].split('"')[0]).replace(String.fromCharCode(10),'');
lastid=bigv(document.getElementById(lastid).outerHTML).split(' id="')[1].split('"')[0];
if (thissq.substring(0,1) >= '0' && thissq.substring(0,1) <= '9') { goodthis='' + thissq; }
} else {
thissq=('' + document.getElementById(lastid).outerHTML.split(' data-square="')[eval(-1 + document.getElementById(lastid).outerHTML.split(' data-square="').length)].split('"')[0]).replace(String.fromCharCode(10),'');
}
//if (newlohfulloh != '') { ouralert('7:' + thissq + ' ' + document.getElementById(lastid).outerHTML); }
var interim='';
if (thissq.indexOf('<span') == 0) {
interim='<span' + thissq.split('</span>')[0].split('<span')[eval(-1 + thissq.split('</span>')[0].split('<span').length)] + '</span>';
//if (newlohfulloh != '') { ouralert('lastoh=' + lastoh + ' and interim=' + interim + ' and thissq=' + thissq + ' and loh=' + loh); }
if (interim.length < 20 && loh != '') { lastid=loh; interim=document.getElementById(loh).innerHTML; lastih=interim.split('</')[0].split('>')[eval(-1 + interim.split('</')[0].split('>').length)]; }
//lastoh=interim;
//if (newlohfulloh != '') { ouralert(lohfulloh + ' +++ ' + bigv(lastoh) + ' Lastoh=' + lastoh + ' and interim=' + interim + ' and thissq=' + thissq + ' and loh=' + loh); }
if (interim.indexOf('<t') != -1) {
thissq=interim.split(' data-square="')[1].split('"')[0];
//} else {
} else if (bigv(document.getElementById(loh).outerHTML).indexOf(' data-square="') != -1) {
thissq=bigv(document.getElementById(loh).outerHTML).split(' data-square="')[eval(-1 + bigv(lastoh).split(' data-square="').length)].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('8253:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
thissq=document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="')[eval(-1 + document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="').length)].split('"')[0];
}
} else if (loh != '') {
//if (newlohfulloh != '') { ouralert('77:' + thissq + ' ' + document.getElementById(lastid).outerHTML); }
lastid=loh;
interim=document.getElementById(loh).outerHTML;
lastih=interim.split('</')[0].split('>')[eval(-1 + interim.split('</')[0].split('>').length)];
if (interim.indexOf('<t') != -1) {
thissq=interim.split(' data-square="')[1].split('"')[0];
} else if (bigv(lastoh).indexOf(' data-square="') != -1) {
thissq=bigv(lastoh).split(' data-square="')[eval(-1 + bigv(lastoh).split(' data-square="').length)].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('823:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
} else {
thissq=document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="')[eval(-1 + document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="').length)].split('"')[0];
}
}
if ((thissq + ' ').substring(0,1) < '0' && loh != '') {
//ouralert('yes');
lastid=loh;
interim=document.getElementById(loh).outerHTML;
//ouralert(interim + ' ... ' + document.getElementById('target').innerHTML.split(interim)[0].slice(-60));
lastih=interim.split('</')[0].split('>')[eval(-1 + interim.split('</')[0].split('>').length)];
if (interim.indexOf('<t') != -1) {
thissq=interim.split(' data-square="')[1].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('81:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
//ouralert(lastoh + ' +++ ' + interim);
} else if (bigv(lastoh).indexOf(' data-square="') != -1) {
thissq=bigv(lastoh).split(' data-square="')[eval(-1 + bigv(lastoh).split(' data-square="').length)].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('82:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
} else {
thissq=document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="')[eval(-1 + document.getElementById('target').innerHTML.split(interim)[0].split(' data-square="').length)].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('83:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
}
}
//thissq=document.getElementById('target').innerHTML.split(lastoh)[0].split(' data-square="')[eval(-1 + document.getElementById('target').innerHTML.split(lastoh)[0].split(' data-square="').length)].split('"')[0];
//if (document.URL.indexOf('debug') != -1) { ouralert('8:' + thissq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }
var lastsq=('' + prevtih.split(lastoh)[0].split(' data-square="')[eval(-1 + prevtih.split(lastoh)[0].split(' data-square="').length)].split('"')[0]);
//if (document.URL.indexOf('debug') != -1) { ouralert('9:' + lastsq + ' ' + lastid + ' ' + thisid + ' ' + lastoh); }

if (thissq.substring(0,1) >= '0' && thissq.substring(0,1) <= '9') { if (goodthis != '') { thissq=eval('' + goodthis); } else { thissq=eval('' + thissq); } }
if (lastsq.substring(0,1) >= '0' && lastsq.substring(0,1) <= '9') { lastsq=eval('' + lastsq); }
//if (newlohfulloh != '') { ouralert('777:' + thissq + ' ' + document.getElementById(lastid).outerHTML); }

// 4.2;20,2
//ouralert('lastsq=' + lastsq + ' and thissq=' + thissq + ' and loh=' + loh + ' and lastid=' + lastid);
loh='';
var hshift=Math.floor(Math.abs(eval(eval(-1 + thissq) % 8) - eval(eval(-1 + lastsq) % 8)));
var vshift=Math.floor(eval(ioff + Math.abs(eval(eval(thissq - eval(eval(-1 + thissq) % 8)) / 8) - eval(eval(lastsq - eval(eval(-1 + lastsq) % 8) )) / 8)));

if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
console.log('hshift=' + hshift + ' and vshift=' + vshift);
}

if (document.getElementById(lastid).outerHTML.indexOf(' data-piece="') != -1) {
otherpiece=document.getElementById(lastid).outerHTML.split(' data-piece="')[1].split('"')[0];
adjective=' occupied';
adjective+=' by ' + otherpiece;
if ((otherpiece + ' ').substring(1).substring(0,1) == 'K' && eval('' + otherpiece.length) == 2) {
if ((thispiece + ' ').substring(1).substring(0,1) == 'K' && eval('' + otherpiece.length) == 2) {
ouralert('Kings can not take kings.');
return false;
} else if ((otherpiece + ' ').substring(0,1) != (thispiece + ' ').substring(0,1) && (otherpiece + ' ').substring(0,1) == 'w') {
cm='Checkmate! Congratulations, ' + playerb; //setTimeout(function(){ ouralert('Checkmate! Congratulations, ' + playerb); }, 2000);
//return false;
} else if ((otherpiece + ' ').substring(0,1) != (thispiece + ' ').substring(0,1) && (otherpiece + ' ').substring(0,1) == 'b') {
cm='Checkmate! Congratulations, ' + playerw; //setTimeout(function(){ ouralert('Checkmate! Congratulations, ' + playerw); }, 2000);
//return false;
}
}
}

if (document.getElementById(lastid).innerHTML.indexOf('<') != -1 || adjective != '') {
adjective=' occupied';
if (document.getElementById(lastid).outerHTML.indexOf(' data-piece="') != -1) {
otherpiece=document.getElementById(lastid).outerHTML.split(' data-piece="')[1].split('"')[0];
adjective+=' by ' + otherpiece;
if (otherpiece.substring(0,1) == thispiece.substring(0,1)) {
consolelog('Chess Piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq);
//ouralert('check castling ' + thispiece + ' ' + otherpiece + ' ' + lastoh + ' ' + document.getElementById(lastid).outerHTML);
mbcrval=mightbecastling(thispiece, otherpiece, lastoh, document.getElementById(lastid).outerHTML);
if (mbcrval <= 0) { //thispiece.substring(1).substring(0,1) == 'K' && eval('' + thispiece.length) == 2) {
if (mbcrval == 0) {
} else if (mbcrval == -1) {
ouralert('Existing pieces between King and Rook prevent castling.');
return false;
} else if (mbcrval == -2) {
if (prelegal) {
ouralert('Only Kings and Rooks can castle.');
return false;
}
} else if (mbcrval == -3) {
} else if (mbcrval == -4) {
} else if (mbcrval == -5) {
ouralert('Only Kings and Rooks of the same colour can castle.');
return false;
} else if (mbcrval == -6) {
} else if (mbcrval == -7) {
} else if (hshift == 3 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
} else if (hshift == 4 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
} else if (eval(hshift + vshift) >= 3) {
ouralert('Kings do not move this way .');
return false;
} else if ((hshift == 0 || vshift == 0) && eval(hshift + vshift) > 1) {
ouralert('Kings do not move this way .');
return false;
} else if (hshift != 1 || vshift != 1) {
ouralert('Kings do not move this way .');
return false;
} else if (hshift == 3 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
} else if (hshift == 4 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
}
} else if (mbcrval != 1) {
ouralert('Except for castling (we will code for later) this is an illegal move.');
return false;
}
} //else { //if (thispiece.substring(1).substring(0,1) == 'P') {
//adjective=' occupied by ' + otherpiece;
//if (hshift == 0) {
//ouralert('Pawns can not move this way .');
// return false;
// } else {
// alert('P ' + hshift + '.' + vshift + ' ' + otherpiece + ' ' + lastoh + ' ... ' + document.getElementById(lastid).outerHTML);
// }
//}

}
} else if (adjective == '') {
adjective=' unoccupied';
//if (thispiece.substring(1).substring(0,1) == 'P') {
// alert('p ' + hshift + '.' + vshift + ' ' + otherpiece + ' ' + lastoh + ' ... ' + document.getElementById(lastid).outerHTML);
//}
}

if (thissq == lastsq) { return false; }

//ouralert('' + hshift + '.' + vshift);
if ('Chess piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq == 'Chess piece bR1 just moved from square 1 to unoccupied square 5') {
console.log('Normally bad where lastid=' + lastid + ' ... ' + document.getElementById(lastid).outerHTML);
}
if ('Chess piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq == 'Chess piece wR1 just moved from square 57 to unoccupied square 61') {
console.log('Normally is bad where lastid=' + lastid + ' ... ' + document.getElementById(lastid).outerHTML);

}
if (Math.floor(eval(ioff + Math.abs(eval(thissq) - eval(lastsq)) % 8)) == 0) { // && eval(eval(-1 + thissq) / 8) != eval(eval(-1 + lastsq) / 8)) { // 57 vs 41 ... no
directionally=' vertically by ' + vshift;
if (thispiece.substring(1).substring(0,1) == 'B') {
consolelog('Chess Piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq);
ouralert('Bishops do not move this way.');
return false;
}
} else if (Math.floor(eval(eval(-1 + thissq) % 8) == eval(eval(-1 + lastsq) % 8))) {
directionally=' horizontally by ' + hshift;
if (thispiece.substring(1).substring(0,1) == 'B') {
consolelog('Chess Piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq);
ouralert('Bishops do not move this way.');
return false;
}
} else if (thispiece.substring(1).substring(0,1) == 'R' && hshift != 0 && vshift != 0) {
consolelog('Chess Piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq);
ouralert('Rooks do not move this way.');
return false;
}
if (thispiece.substring(1).substring(0,1) == 'K' && eval('' + thispiece.length) > 2) {
if (eval(hshift + vshift) != 3 || hshift < 1 || vshift < 1) {
//ouralert('8:' + thissq + ' ' + thisid + ' ' + lastoh);
//ouralert('9:' + lastsq + ' ' + thisid + ' ' + lastoh);
ouralert('Knights can not move this way.' + hshift + '.' + vshift + '+');
return false;
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'K' && eval('' + thispiece.length) == 2) {
if ((otherpiece + ' ').substring(1).substring(0,1) == 'K' && eval('' + otherpiece.length) == 2) {
ouralert('Kings can not take kings.');
return false;
} else if (eval(hshift + vshift) >= 3) {
ouralert('Kings do not move this way .');
return false;
} else if ((hshift == 0 || vshift == 0) && eval(hshift + vshift) > 1) {
ouralert('Kings do not move this way.' + hshift + '.' + vshift + '+');
return false;
} else if (hshift != 1 || vshift != 1) {
if (eval(hshift + vshift) > 1) {
ouralert('Kings do not move this way.' + hshift + '.' + vshift + '-');
return false;
}
} else if (hshift == 3 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
} else if (hshift == 4 && vshift == 0 && adjective.indexOf(' occupied by ' + thispiece.substring(0,1) + 'R') == 0) {
ouralert('Check regarding castling');
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'B') {
// ouralert('' + hshift + ',' + vshift);
if (hshift != vshift) {
ouralert('Bishops do not move this way.');
return false;
} else {
//ouralert('' + eval(Math.abs(thissq - lastsq) / hshift));
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / hshift);
sat+=sfor;
while (sat != thissq) {
//ouralert('' + sat + ' vs ' + lastsq + ' sfor=' + sfor + ' thissq=' + thissq + ' lastsq=' + lastsq);
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Bishops can not jump over other pieces.');
return false;
}
sat+=sfor;
}
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'Q' && hshift != vshift && hshift != 0 && vshift != 0) {
if (hshift != 0 && vshift != 0) {
ouralert('Queens do not move this way.');
return false;
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'Q' && (hshift == vshift || hshift == 0 || vshift == 0)) {
//alert('Here');
if (hshift != 0) {
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / hshift);
sat+=sfor;
while (sat != thissq) {
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Queens can not jump over other pieces.');
return false;
}
sat+=sfor;
}
} else {
//alert('here');
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / vshift);
sat+=sfor;
while (sat != thissq) {
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Queens can not jump over other pieces.');
return false;
}
sat+=sfor;
}
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'R' && hshift != 0) {
mbcrval=mightbecastling(thispiece, otherpiece, lastoh, document.getElementById(lastid).outerHTML);
if (mbcrval != 1) {
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / hshift);
sat+=sfor;
while (sat != thissq) {
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Rooks can not jump over other pieces.');
return false;
}
sat+=sfor;
}
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'R' && vshift != 0) {
mbcrval=mightbecastling(thispiece, otherpiece, lastoh, document.getElementById(lastid).outerHTML);
if (mbcrval != 1) {
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / vshift);
sat+=sfor;
while (sat != thissq) {
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Rooks can not jump over other pieces.');
return false;
}
sat+=sfor;
}
}
} else if (mbcrval != 1 && thispiece.substring(1).substring(0,1) == 'P') {
if (adjective == ' unoccupied') {
if (hshift != 0) {
if (eval(hshift + vshift) > 2) {
ouralert('Pawns can not move this way .');
return false;
} else if (ppt && hshift == 1 && vshift == 1) {
ouralert('Pawns can not move this way .');
return false;
//consolelog('huh pawn');
ppt=ppt;
} else if (!ppt && hshift > 0) {
ouralert('Pawns can not move this way .');
return false;
}
} else if (Math.floor(eval(eval(-1 + eval('' + lastsq)) / 8)) == 6 || Math.floor(eval(eval(-1 + eval('' + lastsq)) / 8)) == 1) {
if (vshift > 2) {
ouralert('Pawns can not move this way .');
return false;
} else if (vshift == 2) {
//ouralert('vshift=' + vshift);
sat=lastsq;
ihthere=false;
sfor=eval((eval('' + thissq) - eval('' + lastsq)) / vshift);
sat+=sfor;
//while (sat != thissq) {
if (document.getElementById('target').innerHTML.split(' data-square="' + sat + '"')[1].split('>')[1].split('</')[0].trim() != '') {
ouralert('Pawns can not jump over other pieces.');
return false;
}
//sat+=sfor;
//}
}
} else if (vshift != 1) {
ouralert('Pawns can not move this way.');
return false;
} else if (thispiece.substring(0,1) == 'w' && eval('' + lastsq) < eval('' + thissq)) {
if (ppt && hshift == 1 && vshift == 1) {
ppt=ppt;
} else {
ouralert('Pawns can not move this way .');
return false;
}
} else if (thispiece.substring(0,1) == 'b' && eval('' + lastsq) > eval('' + thissq)) {
if (ppt && hshift == 1 && vshift == 1) {
ppt=ppt;
} else {
ouralert('Pawns can not move this way .');
return false;
}
}
} else if (hshift != 1 || vshift != 1) {
if (ppt && hshift == 1 && vshift == 1) {
ppt=ppt;
} else {
ouralert('Pawns can not move this way .');
return false;
}
}
}
consolelog('Chess piece ' + thispiece + ' just moved' + directionally + ' from square ' + lastsq + ' to' + adjective + ' square ' + thissq);
prevlastoh=lastoh;
prevlastih=lastih;
setTimeout(prevl, 500);
}
}
}
//ouralert('' + retval + ' ' + thispiece);
if (retval) {
itisthiscmove=thispiece.substring(0,1).replace('w','B').replace('b','W').toLowerCase();
if (itisthiscmove == 'b') {
consolelog('Your next move ' + playerb + ' ... ');
} else {
consolelog('Your next move ' + playerw + ' ... ');
}
occupiedlist=occupiedlist.replace(',' + lastsq + ',', ',');
occupiedlist+='' + thissq + ',';

if (thispiece.substring(0,2) == 'wP' && thissq <= 8) {
qid=thisid;
qqid='♕⁠';
setTimeout(bbbthen, 4000);
//ouralert(98);
//document.getElementById(thisid).setAttribute('data-piece', document.getElementById(thisid).getAttribute('data-piece').replace('wP','wQ'));
//document.getElementById(thisid).innerHTML='♕⁠';
} else if (thispiece.substring(0,2) == 'bP' && thissq >= 57) {
qid=thisid;
qqid='♛⁠';
setTimeout(bbbthen, 4000);
//document.getElementById(thisid).setAttribute('data-piece', document.getElementById(thisid).getAttribute('data-piece').replace('bP','bQ'));
//document.getElementById(thisid).innerHTML='♛⁠';
}
}
if (mbcrval == 1) { retval=false; }
if (cm != '' && retval) {
setTimeout(function(){ ouralert(cm); }, 2000);
}
return retval;
}

function bbbthen() {
var thatid=qid;
//ouralert(thatid);
document.getElementById(thatid).innerHTML=qqid;
document.getElementById(thatid).setAttribute('data-piece', document.getElementById(thatid).getAttribute('data-piece').replace('wP','wQ').replace('bP','bQ'));
}

function prevl() {
prevtih=document.getElementById('target').innerHTML;
}

function mirrorperhaps(inn) {
if (!mirroring) { return inn; }
var onnd=Math.floor(eval(inn / 8));
var onnr=eval(inn % 8);
// (7 - 1/8) x 8 + (1 % 8)
//if (inn == 14) { alert(eval(eval(eval(7 - onnd) * 8) + onnr)); }
return eval(eval(eval(7 - onnd) * 8) + onnr);
}

function butwhatifchessgame(inspanstuff) {
var outspanstuff=inspanstuff, ii=0, thisth='', tnum=0;
if (document.URL.indexOf('/chess') != -1 && document.URL.indexOf('traditional=') != -1) {
var ths=[];
var ourmap=[];
var thas=inspanstuff.split('</th>');
for (ii=0; ii<thas.length; ii++) {
if (thas[ii].trim() != '') {
thisth='<th' + thas[ii].split('<th')[-1 + eval('' + thas[ii].split('<th').length)] + '</th>';
ths.push(thisth);
} // outspanstuff=outspanstuff.replace(thisth, '');
}
var outtg=document.getElementById('mytable').innerHTML;
thas=outtg.split('</td>');
//ouralert(65);
if (trad.indexOf('_') != -1 && trad.indexOf('P') != -1) {
if (trad.indexOf('wP') != -1) {
if (eval(trad.split('wP')[1].split('_')[1].split('w')[0].split('b')[0].split('_')[0]) <= 16) {
mirroring=true;
}
}
if (trad.indexOf('bP') != -1) {
if (eval(trad.split('bP')[1].split('_')[1].split('w')[0].split('b')[0].split('_')[0]) >= 49) {
mirroring=true;
}
}

if (9 == 6) {

for (ii=0; ii<staidmap.length; ii++) { staidmap[ii]=-1; }

for (ii=0; ii<thas.length; ii++) {
if (trad.indexOf('_') != -1) {
//alert('' + ths.length + ' ' + trad + ' cpa[' + ii + ']=' + cpa[ii] + ' ... ' + occupiedlist);
//if (1 == 1 || cpa[ii] == 'wP1') { alert('Ready ' + cpa[ii]); }
if (trad.indexOf(cpa[ii] + '_') != -1) {
//if (cpa[ii] == 'wP1') { alert(eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0])))); }
// ourmap.push(eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0]))));
// occupiedlist+='' + eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0]))) + ',';
//alert(occupiedlist);
staidmap[ii]=eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0])));
alert('' + ths.length + ' ' + trad + ' staidmap[' + ii + ']=' + staidmap[ii] + ' ... ' + occupiedlist);
}
}
}

trad='';
}

}
//alert(thas.length);
for (ii=0; ii<thas.length; ii++) {
if (trad.indexOf('_') != -1) {
//alert('' + ths.length + ' ' + trad + ' cpa[' + ii + ']=' + cpa[ii] + ' ... ' + occupiedlist);
//if (1 == 1 || cpa[ii] == 'wP1') { alert('Ready ' + cpa[ii]); }
if ((trad + amove).indexOf(cpa[ii] + '_') != -1) {
//if (cpa[ii] == 'wP1') { alert(eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0])))); }
ourmap.push(eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0].split('_')[0]))));
occupiedlist+='' + eval(-1 + mirrorperhaps(eval(trad.split(cpa[ii] + '_')[1].split('w')[0].split('b')[0].split('_')[0]))) + ',';
//alert(occupiedlist);
} else {
ourmap.push(-1);
occupiedlist+='' + eval(1 + eval('' + staidmap[ii])) + ',';
}
} else if (staidmap[ii] >= 0 && document.URL.indexOf('traditional=mayhem') == -1 && trad.indexOf('_') == -1) {
ourmap.push(staidmap[ii]);
occupiedlist+='' + eval(1 + eval('' + staidmap[ii])) + ',';
} else {
tnum=Math.floor(Math.random() * 64);
occupiedlist+='' + eval(1 + tnum) + ',';
ourmap.push(tnum);
}
}
if (amove.trim() != '') {
//alert(amove);
//if (trad.trim().indexOf(amove.split('_')[0] + '_') == -1) {
//ourmap.push(eval(-1 + mirrorperhaps(eval(trad.trim().split(cpa[ii] + '_')[1].split('w')[0].split('b')[0].split('_')[0]))));
//occupiedlist+='' + eval(-1 + mirrorperhaps(eval(trad.trim().split(cpa[ii] + '_')[1].split('w')[0].split('b')[0].split('_')[0]))) + ',';
//}
var amvs=amove.split('_');
if (eval('' + amvs.length) > 2) {
moveto=mirrorperhaps(eval('' + amvs[2]));
if (movefrom == -1) { movefrom=mirrorperhaps(eval('' + amvs[1])); }
//alert('' + movefrom + ' to ' + moveto);
}
}
//ouralert(165);
var preclick='';
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
preclick='data-';
}
//alert(ths.length);
for (ii=(-1 + eval('' + ths.length)); ii>=0; ii--) {
if (ourmap[ii] >= 0) {
//ouralert(thas[ii] + ' ... ' + ths[ii]);
outtg=outtg.replace(thas[ourmap[ii]], thas[ourmap[ii]] + ths[ii].replace(/th/g,'span').replace('<span ', '<span style=font-size:60px; data-ontouchstart=fit(this); onmouseover=fit(this); ' + preclick + 'onclick=fit(this); ')); // .replace(/th/g,'SPAN')
}
}
document.getElementById('mytable').innerHTML=outtg;
setTimeout(prevl, 500);
return '<td></td>';
}
return outspanstuff;
}

function askmore() {
var yb=prompt('Optionally enter your own new sentence to set for the user to unscramble. The assumption is there that an absolute URL as a word represents an image URL where hashtag #leftoff#topoff#width#height could optionally be appended.', '');
if (yb != null) {
if (yb.trim() != '') {
location.href=(document.URL.replace(('#' + location.hash).replace('##','#').replace(/^\#$/g,''),'') + ('#' + location.hash).replace('##','#').replace(/^\#$/g,'')).replace('sourcenum=', 'sourceXnum=').replace('yourblurb=', 'yourXblurb=').replace('?', '?yourblurb=' + encodeURIComponent(yb) + '&sourcenum=&').replace('#','&');
}
}
}

function cloneize() {
var irws=1;
var firsttogo='td33', ifirst=9;
var ielems=0, elems=[];
var wastdcheck=tdcheck;

if (tdcheck) {
setTimeout(dodoms, 1000); //setInterval(dodoms, 1000);
tdcheck=false;

if (document.getElementById('td32')) { eightoh=document.getElementById('td32').outerHTML.split('>')[0] + '></td>'; }

if (document.URL.indexOf('/chess') != -1) {
document.getElementById('clone').style.display='none';
}

if (shuffle) {
document.getElementById('spmore').innerHTML='<a title="Set your own sentence for the user to unscramble." style=text-decoration:none;cursor:pointer; onclick=askmore();>+</a>';
}

if (yourblurb != '') {
document.getElementById('source').innerHTML=yourblurb;
yourblurb='';
}

if (sourcenum <= 0 && !sdone) {
var sncx=document.getElementById('source').innerText;
var swordsx=sncx.split(' ');
if (tdnum == 9 && document.URL.indexOf('tdnum=') == -1) {
tdnum=eval('' + swordsx.length);
}
} else if (sourcenum != 1 && !sdone && tdnum == 9) {
tdnum=eval('' + sourcenum);
}

if (tdnum == 3) {
if (document.getElementById('tr3')) {
document.getElementById('tr3').style.display='none';
document.getElementById('tr2').style.display='none';
}
document.getElementById('td11').rowspan='3';
document.getElementById('td12').rowspan='3';
document.getElementById('td13').rowspan='3';
} else if (tdnum == 6) {
if (document.getElementById('tr3')) {
document.getElementById('tr3').style.display='none';
}
document.getElementById('td21').rowspan='2';
document.getElementById('td22').rowspan='2';
document.getElementById('td23').rowspan='2';
} else if (tdnum < 9) {
if (document.getElementById('td33')) {
for (ifirst=9; ifirst>tdnum; ifirst--) {
document.getElementById(firsttogo).style.display='none';
firsttogo=firsttogo.replace('td12','tdx11').replace('td21','tdx12').replace('td21','tdx13').replace('td22','tdx21').replace('td23','tdx22').replace('td31','tdx23').replace('td32','tdx31').replace('td33','tdx32').replace('tdx','td');
}
}
} else if (tdnum > 9) {
var arow='', rownum=4;
if (document.getElementById('target').innerHTML.indexOf('td221') != -1 && document.URL.indexOf('/chess') != -1) {
var wastheih=document.getElementById('target').innerHTML;
//ouralert(wastheih);
for (var ijkx=1; ijkx<=tdnum; ijkx++) {
wastheih=wastheih.replace('>' + ijkx + '<', '><');
}
document.getElementById('target').innerHTML=wastheih;
} else {
for (var ijk=10; ijk<=tdnum; ijk++) {
if (eval(ijk % 3) == 1) {
rownum=eval(1 + eval(eval(-1 + ijk) / 3));
arow='<t' + 'r id=tr' + rownum + '><t' + 'd id=td' + rownum + '1>' + ijk + '</t' + 'd></t' + 'r>';
//ouralert('1:' + ijk + ' ' + arow);
} else if (eval(ijk % 3) == 0) {
arow=arow.replace('</t' + 'r>', '<t' + 'd id=td' + rownum + '3>' + ijk + '</t' + 'd></t' + 'r>');
//ouralert('2:' + ijk + ' ' + arow);
document.getElementById('mytable').innerHTML+=arow;
arow='';
} else {
arow=arow.replace('</t' + 'r>', '<t' + 'd id=td' + rownum + '2>' + ijk + '</t' + 'd></t' + 'r>');
//ouralert('3:' + ijk + ' ' + arow);
}
}
}
document.getElementById('mytable').innerHTML+=arow;
}
}

if (across != 3) {
var sofartd='', two=2;
var wasih=document.getElementById('mytable').innerHTML;
var rowas=wasih.split('</' + 'tr>');
for (irws=1; irws<rowas.length; irws++) {
if (rowas[irws].length > 3 && rowas[irws].replace(String.fromCharCode(10),'').indexOf('</') != 0) {
wasih=wasih.replace(rowas[eval(-1 + irws)] + '</' + 'tr>', rowas[eval(-1 + irws)] + '<!-' + '-/' + 'tr>');
}
}
rowas=wasih.split('<t' + 'r');
for (irws=2; irws<rowas.length; irws++) {
if (rowas[irws].length > 3) {
wasih=wasih.replace('<t' + 'r' + rowas[irws], '<t' + 'r' + rowas[irws].replace(rowas[irws].split('>')[0] + '>', '-' + '->'));
}
}
rowas=wasih.split('</t' + 'd>');
for (irws=0; irws<rowas.length; irws++) {
if (eval(eval(1 + irws) % across) == 0) {
sofartd+=rowas[irws] + '</t' + 'd>';
wasih=wasih.replace(sofartd, sofartd + '</t' + 'r><t' + 'r id=tr' + two + '>');
sofartd='';
two++;
} else {
sofartd+=rowas[irws] + '</t' + 'd>';
}
}
document.getElementById('mytable').innerHTML=wasih;
}

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
document.getElementById(sourceid).setAttribute('contenteditable',false);
document.getElementById('strongs').innerHTML='';
}
if (clonedata != document.getElementById(sourceid).innerHTML) {
clonedata=document.getElementById(sourceid).outerHTML.replace(' id=', ' data-id=');
if (!document.getElementById('callback') && document.URL.indexOf('/chess') == -1) { document.getElementById('clone').style.display='inline-block'; }
}
if (sourcenum != 1 && !sdone) {
sdone=true;
var snc=document.getElementById('source').innerText;
origsnc=snc;
var swords=snc.split(' ');
var ourone=1, onepos=0;
var sarr=[], sarrsofar=',';
var ccbit=' cellpadding=0 cellspacing=0 ', onerand='';
var spanstuff='', kspan=0;
if (eval('' + sourcenum) == eval('' + swords.length) || eval('' + sourcenum) <= 0 || shuffle) {
if (eval('' + sourcenum) <= 0) { sourcenum=eval('' + swords.length); }
for (var inb=0; inb<sourcenum; inb++) {

if (!shuffle) {
//ouralert('*' + swords[inb] + '*');
sarr.push(inb);
} else {
if (sarrsofar == ',') {
onerand='' + Math.floor(Math.random() * sourcenum);
sarrsofar+='' + onerand + ',';
sarr.push(eval(onerand));
} else {
while (sarrsofar.indexOf(',' + onerand + ',') != -1) {
onerand='' + Math.floor(Math.random() * sourcenum);
}
sarrsofar+='' + onerand + ',';
sarr.push(eval(onerand));
}
}

}
ourone=-1;
ccbit=' cellpadding=2 cellspacing=0 ';
setInterval(shufflegamecheck, 3000);
} else if (eval('' + snc.length) > eval('' + sourcenum)) {
ourone=Math.floor(eval(eval('' + snc.length) / eval('' + sourcenum)));
}
for (kspan=0; kspan<eval('' + sourcenum); kspan++) {
if (ourone < 0) {
spanstuff+='<span data-piece="' + cpa[kspan] + '" class=source draggable="true" id=span' + kspan + cbi('>' + ('' + swords[sarr[kspan]]).replace(/undefined$/g, '')) + '</span>';
} else if (eval(eval('' + onepos) + eval('' + ourone)) < eval('' + snc.length) && eval(1 + kspan) != eval('' + sourcenum)) {
spanstuff+='<span data-piece="' + cpa[kspan] + '" class=source draggable="true" id=span' + kspan + cbi('>' + snc.substring(onepos).substring(0,ourone)) + '</span>';
} else if (eval('' + onepos) < eval('' + snc.length)) {
//ouralert(snc.substring(onepos));
spanstuff+='<span data-piece="' + cpa[kspan] + '" class=source draggable="true" id=span' + kspan + cbi('>' + snc.substring(onepos)) + '</span>';
} else {
spanstuff+='<span data-piece="' + cpa[kspan] + '" class=source draggable="true" id=span' + kspan + '> </span>';
}
onepos+=ourone;
}
//ouralert(888);
document.getElementById('dsource').innerHTML='<ta' + 'ble' + ccbit + ' id=source style="background-color:#f0f0f0;"><t' + 'r>' + butwhatifchessgame(spanstuff.replace(/span/g, 'th')) + '</t' + 'r></ta' + 'ble><br>';
//document.getElementById('dsource').style.textAlign='left';
if (document.getElementById('mybut') && originalsn <= 0 && originalsh) {
document.getElementById('mybut').innerHTML='Piece Sentence Back Together Again Game';
document.getElementById('dsource').style.width='100%';
document.getElementById('dsource').style.display='inline-block';
document.getElementById('source').align='left';
} //else {
//ouralert(originalsn);
//ouralert(originalsh);
//}
setTimeout(aathen, 50);
setTimeout(cloneize, 100);

if (wastdcheck && document.URL.indexOf('/chess') != -1) {
document.title='Chess Game Practice';
if (document.URL.indexOf('traditional=') != -1) {
document.getElementsByTagName('h4')[0].style.marginTop='-22px';
document.getElementById('target').style.marginTop='-5px';
}
rejig();
}
}

function rejig() {
var eword="touchdown";
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) || (trad.trim().indexOf('_') != -1 && amove.trim() != '')) {
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { eword="click"; }
if (document.URL.indexOf('traditional=') != -1) {
var huhih=document.getElementsByTagName('h1')[0].innerHTML.substring(26);
if (huhih.indexOf('Discrete Touch') == -1 && eword == "touchdown") {
document.getElementsByTagName('h1')[0].innerHTML="Discrete Touch" + huhih;
}
}
//document.body.addEventListener("touchdown", (ev) => { gev=ev; refit(ev); });
document.getElementById('mytable').addEventListener("click", (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
if (1 == 1) {
elems=document.getElementsByTagName('td');
for (ielems=0; ielems<elems.length; ielems++) {
if (('' + elems[ielems].className) == 'black' || ('' + elems[ielems].className) == 'white') {
//document.title='set1';
elems[ielems].addEventListener(eword, (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
if (eword == "touchdown" && amove != "" && movefrom != -1 && moveto != -1) {
if (elems[ielems].outerHTML.indexOf(' data-square="' + movefrom + "'") != -1) {
if (tds[itds].innerHTML.indexOf('</span>') != -1) {
document.getElementById(tds[itds].innerHTML.split(' id="')[1].split('"')[0]).addEventListener("click", (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
} else {
elems[ielems].addEventListener("click", (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
}
}
if (elems[ielems].outerHTML.indexOf(' data-square="' + moveto + "'") != -1) {
if (tds[itds].innerHTML.indexOf('</span>') != -1) {
document.getElementById(tds[itds].innerHTML.split(' id="')[1].split('"')[0]).addEventListener("click", (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
} else {
elems[ielems].addEventListener("click", (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
}
}
}

}
}
elems=document.getElementsByTagName('span');
for (ielems=0; ielems<elems.length; ielems++) {
if (('' + elems[ielems].className) == 'source') {
//if (document.title.replace('set1','') == '') { document.title+='set2'; }
elems[ielems].addEventListener(eword, (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
}
}
elems=document.getElementsByTagName('th');
for (ielems=0; ielems<elems.length; ielems++) {
if (('' + elems[ielems].className) == 'source') {
//if (document.title.replace('set1set2','') == '') { document.title+='set3'; }
elems[ielems].addEventListener(eword, (ev) => { gev=ev; if (1 == 1) { setTimeout(delayedrefit, 500); } else { refit(ev); } });
}
}
}
}

if (movefrom != -1 && moveto != -1) {
var tds=document.getElementsByTagName('td');
for (var itds=0; itds<tds.length; itds++) {
if (tds[itds].outerHTML.indexOf(' data-square="' + movefrom + '"') != -1) {
//alert('here');
if (tds[itds].innerHTML.indexOf('</span>') != -1) {
document.getElementById(tds[itds].innerHTML.split(' id="')[1].split('"')[0]).click();
} else {
tds[itds].click();
}
}
}
nextmove=moveto;
movefrom=-1;
moveto=-1;
}

}


// https://www.puzzles-on-line-niche.com/images/Rebus1pictograph.jpg#0#0#150#120 https://www.puzzles-on-line-niche.com/images/Rebus1pictograph.jpg#150#0#150#120 https://www.puzzles-on-line-niche.com/images/Rebus1pictograph.jpg#0#120#150#120 https://www.puzzles-on-line-niche.com/images/Rebus1pictograph.jpg#150#120#150#120
function cbi(insw) { // #leftoff#topoff#width#height
var outsw=insw;
var ourbp='';
var ourbs='background-size:contain;width:80px;height:80px;';
if (insw.substring(1).toLowerCase().replace(/^\/\//g, 'http://').replace('https:','http:').indexOf('http:') == 0) {
if (eval('' + insw.substring(1).split('#').length) >= 2) {
if (eval('' + insw.substring(1).split('#').length) >= 3) {
if (eval('' + insw.substring(1).split('#').length) < 5) {
ourbp='background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;';
ourbs=' background-size:80px 80px;width:80px;height:80px;';
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
} else {
ourbp='background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;';
//ourbs=' 80px 80px;width:80px;height:80px;';
ourbs=' background-size:' + insw.substring(1).split('#')[3] + 'px ' + insw.substring(1).split('#')[4] + 'px;background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;width:' + insw.substring(1).split('#')[3] + 'px;height:' + insw.substring(1).split('#')[4] + 'px;';
ourbs=' width:' + insw.substring(1).split('#')[3] + 'px;height:' + insw.substring(1).split('#')[4] + 'px;';
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
} else {
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
} else {
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1) + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
} else if (insw.substring(1).toLowerCase().indexOf('data:image/') == 0) {
if (eval('' + insw.substring(1).split('#').length) >= 2) {
if (eval('' + insw.substring(1).split('#').length) >= 3) {
if (eval('' + insw.substring(1).split('#').length) < 5) {
ourbp='background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;';
ourbs=' background-size:80px 80px;width:80px;height:80px;';
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
} else {
ourbp='background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;';
//ourbs=' background-size:80px 80px;width:80px;height:80px;';
ourbs=' background-size:' + insw.substring(1).split('#')[3] + 'px ' + insw.substring(1).split('#')[4] + 'px;background-position: -' + insw.substring(1).split('#')[1] + 'px -' + insw.substring(1).split('#')[2] + 'px;width:' + insw.substring(1).split('#')[3] + 'px;height:' + insw.substring(1).split('#')[4] + 'px;';
ourbs=' width:' + insw.substring(1).split('#')[3] + 'px;height:' + insw.substring(1).split('#')[4] + 'px;';
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
} else {
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1).split('#')[0] + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
} else {
ourbs+=ourbp;
outsw=' style="background:URL(' + insw.substring(1) + ');background-repeat:no-repeat;' + ourbs + 'font-color:transparent;color:transparent;display:inline-block;overflow-x:hidden;">' + insw.substring(1);
}
}
return outsw;
}

function workouralert(insg) {
var outsg=insg;
//ouralert('' + sourcenum + ' 1:' + insg);
for (var ii=sourcenum; ii>=1; ii--) {
if (outsg.indexOf('' + ii + 'http') != -1) {
outsg=outsg.replace('' + ii + 'http', 'http');
//ouralert('0:' + outsg);
} else {
outsg=outsg.replace('' + ii, '');
}
}
// ouralert('2:' + outsg);
insg=outsg;
outsg='';
for (var iii=0; iii<insg.length; iii++) {
if (insg.charAt(iii) <= ' ') {
outsg+=' ';
} else {
outsg+=insg.substring(iii).substring(0,1);
}
}
//ouralert('3:' + outsg);
while (outsg.indexOf(' ') != -1) {
outsg=outsg.replace(' ', ' ');
}
//ouralert('4:' + outsg);
return outsg;
}

function shufflegamecheck() {
if (document.URL.indexOf('/chess') == -1) {
if (document.getElementBy== -1) {
documentbody=document.getElementById('mytable');
documentURL+=('' + location.hash);
} else if (('' + inurls) != '' && documentURL.indexOf('#') == -1) {
documentURL+=('#in' + 'url=' + encodeURIComponent(inurls));
}
if (documentURL.indexOf('in' + 'url=') != -1) {
if (documentURL.split('&tableohprefix=')[0].split('&table&cibih=')[0].indexOf('in' + 'url=') == -1) {
smore='#in' + 'url=' + documentURL.split('in' + 'url=')[1].split('&')[0].split('#')[0];
}
}
if (document.getElementById('mytable').outerHTML.indexOf(changeanyfrom) == -1 && document.getElementById('mytable').outerHTML.indexOf(changeanyfrom.replace(/\ /g,'')) != -1) {
changeanyfrom=changeanyfrom.replace(/\ /g,'');
}
if (document.getElementById('mytable').outerHTML.indexOf(changeanyfrom) != -1) {
var mtcb=document.getElementById('mytable').getBoundingClientRect();
changeanyto='width:' + mtcb.width + 'px;height:' + mtcb.height + 'px;';
tableohprefixbit=addop('?tableohprefix=') + hereencodeURIComponent(document.getElementById('mytable').outerHTML.split('<table')[1].split('>')[0].replace(changeanyfrom,changeanyto));
if (documentURL.indexOf('?') != -1) {
documentURL=documentURL.replace('?', tableohprefixbit + '&');
} else if (documentURL.indexOf('.php') != -1) {
documentURL=documentURL.replace('.php', '.php' + tableohprefixbit);
} else if (documentURL.indexOf('#') != -1) {
documentURL=documentURL.replace(documentURL.split('#')[0], documentURL.split('#')[0] + tableohprefixbit);
} else {
documentURL+=tableohprefixbit;
}
}
var bihbig='';
var fromone='youllneverfindthis';
var toone='youllneverfindthis';
if (('' + window.localStorage.getItem('colouringincollaboratoremailee')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {
defemail=window.localStorage.getItem('colouringincollaboratoremailee');
}
if (('' + window.localStorage.getItem('colouringincollaboratorsmsno')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {
defsms=window.localStorage.removeItem('colouringincollaboratorsmsno');
}
document.getElementById('result').innerHTML='';

var documentbody=document.body;
document.getElementById('inurl').value='';
var therest='';
if (document.URL.indexOf('#inurl=') != -1 || 1 == 1) {
documentbody=document.getElementById('mytable');
bihbig=documentbody.innerHTML;
} else {
bihbig=documentbody.innerHTML;
}
if (bihbig.indexOf('</tab' + 'le>') != -1 || documentbody.outerHTML.indexOf('<tab') == 0) {
if (documentbody.outerHTML.indexOf('<tab') != 0) {
therest=bihbig.split(bihbig.split('</tab' + 'le>')[0] + '</tab' + 'le>')[1];
bihbig=bihbig.split('</tab' + 'le>')[0] + '</tab' + 'le>';
}

while (bihbig.indexOf(suffixfor) != -1) {
bihbig=bihbig.replace(suffixfor, suffixnickchar); // .replace(/\-/g,'%2d').replace(/\./g,'%2e')
if (fromone == 'youllneverfindthis') {
fromone='imageurl=';
toone='urlimage=';
}
}
while (bihbig.indexOf(prefixfor + 'td') != -1) {
bihbig=bihbig.replace(prefixfor + 'td', prefixnickchar + 'td'); // .replace(/\-/g,'%2d').replace(/\./g,'%2e')
if (fromone == 'youllneverfindthis') {
fromone='imageurl=';
toone='urlimage=';
}
}
}

var spc=('sms:' + snum + '&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + (selem == 128506 ? '#WorldReveal=' + firsttentimestwo : (selem == 127754 ? '#RiverReveal=' + encodeURIComponent(firsttentimestwo) : (selem == 127956 ? '#MountainReveal=' + encodeURIComponent(firsttentimestwo) : ''))) + '#cibih=' + encodeURIComponent(encodeURIComponent(bihbig + therest))));
//alert(eval('' + ('sms:' + snum + '&body=' + encodeURIComponent(documentURL.split('?')[0].split('#')[0] + (selem == 128506 ? '#WorldReveal=' + firsttentimestwo : (selem == 127754 ? '#RiverReveal=' + encodeURIComponent(firsttentimestwo) : (selem == 127956 ? '#MountainReveal=' + encodeURIComponent(firsttentimestwo) : ''))) + '#cibih=' + encodeURIComponent(documentbody.innerHTML))).length));
if (eval('' + spc.length) >= 4450) {
snum=('' + prompt('Please enter SMS number to send to. We suspect message is too long for an SMS and if you enter an email address here instead, we will try to send an email instead. Append space(s) to remember, whatever you enter, for next time. ', snum)).replace(/^null/g, (defemail.indexOf('@') != -1 ? defemail : (defsms != '' ? defsms : '')) );
} else {
snum=('' + prompt('Please enter SMS number to send to. Append space(s) to remember for next time. ', snum)).replace(/^null/g, (defsms != '' ? defsms : (defemail.indexOf('@') != -1 ? defemail : '')));
}
if (snum == null) { snum=''; }

if (snum.indexOf('@') != -1) {
if (snum.trim() != snum) {
snum=snum.trim();
if (('' + window.localStorage.getItem('colouringincollaboratoremailee')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {
window.localStorage.removeItem('colouringincollaboratoremailee');
}
window.localStorage.setItem('colouringincollaboratoremailee', snum);
defemail=snum;
}
return doemail(snum);
} else if (snum.trim() != '' && snum.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'').trim() == '') {
//alert('Snum=' + snum + '?');
if (snum.trim() != snum) {
snum=snum.trim();
if (('' + window.localStorage.getItem('colouringincollaboratorsmsno')).replace(/^null/g,'').replace(/^undefined/g,'') != '') {
window.localStorage.removeItem('colouringincollaboratorsmsno');
}
window.localStorage.setItem('colouringincollaboratorsmsno', snum);
defsms=snum;
}

var azx=top.document.getElementById('xas' + 'ms');
if (azx == null) { azx=top.document.createElement("a"); }
//if (1 == 1) {
// document.getElementById('divas').appendChild(azx);
//} else {
top.document.body.appendChild(azx);
// }
azx.id = 'xas' + 'ms';
azx.target = "_top";
azx.style = "display: none";
azx.href = 'sms:' + snum + '&body=' + encodeURIComponent((documentURL.replace('php#', 'php?').replace('#', '&').replace('&inurl=','#inurl=').split('&tableohprefix=')[0].split('&table&cibih=')[0] + smore).replace(fromone,toone) + (selem == 128506 ? '#WorldReveal=' + firsttentimestwo : (selem == 127754 ? '#RiverReveal=' + encodeURIComponent(firsttentimestwo) : (selem == 127956 ? '#MountainReveal=' + encodeURIComponent(firsttentimestwo) : ''))) + '#cibih='.substring(0,6) + ('=') + encodeURIComponent(encodeURIComponent(bihbig + therest))); // .replace(/\_/g,'%5f')
azx.click();
}
return '';
}

function getdover() {
if (document.getElementById('dragoverdelay') && document.getElementById('dragovercountdown')) {
return doverc;
}
return 0;
}

function overdover() {
if (document.getElementById('dragoverdelay') && document.getElementById('dragovercountdown')) {
if (document.getElementById('numacross')) {
if (('' + document.getElementById('numacross').value) != '99') {
if (decodeURIComponent(decodeURIComponent(('' + location.hash))).indexOf('#inu' + 'rl=') != -1) {
document.getElementById('dstyle').innerHTML+='<st' + 'yle> .tdone { border:1px solid transparent; width: ' + eval(100 / eval('' + document.getElementById('numacross').value)) + '% !important; height: ' + eval(100 / eval('' + document.getElementById('numacross').value)) + '% !important; } </st' + 'yle>';
} else {
document.getElementById('dstyle').innerHTML+='<st' + 'yle> .tdone { border:1px solid transparent; width: ' + eval(100 / eval('' + document.getElementById('numacross').value)) + 'vw !important; height: ' + eval(100 / eval('' + document.getElementById('numacross').value)) + 'vh !important; } </st' + 'yle>';
}
}
}
if (Math.abs(doverd) != eval('' + document.getElementById('dragoverdelay').value)) { doverd=eval('' + document.getElementById('dragoverdelay').value); }
if (doverc == 0 && eval('' + document.getElementById('dragovercountdown').value) == 0) { doverc=doverd; document.getElementById('dragovercountdown').value='' + doverc; document.getElementById('dragovercountdown').style.display='inline-block'; }
}
}

function dover() {
if (document.getElementById('dragoverdelay') && document.getElementById('dragovercountdown')) {
//document.title='' + doverc;
if (Math.abs(doverd) != eval('' + document.getElementById('dragoverdelay').value)) { doverd=eval('' + document.getElementById('dragoverdelay').value); }
if (doverc > 0) { doverc--; document.getElementById('dragovercountdown').value='' + doverc; if (1 == 3) { doverd=-doverd; } }
setTimeout(dover, 1000);
}
}

function thefauxencodeURIComponent(inbit) {
return inbit.toLowerCase().replace(String.fromCharCode(35), "").replace(".", "").replace(".", "").replace(".", "").replace("+", "").replace("+", "").replace("'", "").replace('%27','').replace(/\//g, "").replace(/,/g, "").replace("---","-").replace("---","-").replace(/--/g,"-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-");
}

function lsit() {
var sofarls='';
if (window.localStorage) {
if (('' + window.localStorage.getItem('eightbyeightplayers')).replace(/^null$/g,'').replace(/^undefined$/g,'') != '') {
if (('|' + decodeURIComponent(('' + window.localStorage.getItem('eightbyeightplayers'))) + '|').indexOf('|' + playerb.replace('(white)','').replace('(black)','').trim() + playerw.replace('(black)','').replace('(white)','').trim() + '|') == -1) {
sofarls=(('' + window.localStorage.getItem('eightbyeightplayers')));
window.localStorage.removeItem('eightbyeightplayers');
window.localStorage.setItem('eightbyeightplayers', sofarls + encodeURIComponent('|') + encodeURIComponent(playerb.replace('(white)','').replace('(black)','').trim() + playerw.replace('(black)','').replace('(white)','').trim()));
}
} else {
window.localStorage.setItem('eightbyeightplayers', encodeURIComponent(playerb.replace('(white)','').replace('(black)','').trim() + playerw.replace('(black)','').replace('(white)','').trim()));
}
}
}

function dsumsel() {
var bwsets=[], seloh='', iseloh=0;
if (document.getElementById('dsum') && document.URL.indexOf('/chess') != -1) {
if (document.getElementById('dsum').innerHTML == '') {
if (window.localStorage) {
if (('' + window.localStorage.getItem('eightbyeightplayers')).replace(/^null$/g,'').replace(/^undefined$/g,'') != '') {
bwsets=decodeURIComponent(('' + window.localStorage.getItem('eightbyeightplayers'))).split('|');
if (bwsets.length >= 1) {
seloh='<select style="font-size:8px;opacity:0.5;" onchange="if (this.value.trim().length != 0) { location.href=this.value; } else if (this.value.length != 0) { window.localStorage.removeItem(' + "'eightbyeightplayers'" + '); this.style.display=' + "'none'" + '; }" id=selo title="Stored past player name sets"><option value=""></option></select>';
for (iseloh=0; iseloh<bwsets.length; iseloh++) {
if (eval('' + bwsets[iseloh].split(']').length) >= 3) {
seloh=seloh.replace('</select>', '<option value="' + document.URL.split('/chess')[0] + '/chess_game.php?traditional=chess&bname=' + encodeURIComponent(bwsets[iseloh].split(']')[0] + ']') + '&wname=' + encodeURIComponent(bwsets[iseloh].split(']')[1] + ']') + '">Chess Game ' + bwsets[iseloh].split(']')[0] + '] versus ' + bwsets[iseloh].split(']')[1] + ']</option></select>');
seloh=seloh.replace('</select>', '<option value="' + document.URL.split('/chess')[0] + '/chess_game.php?traditional=draughts&bname=' + encodeURIComponent(bwsets[iseloh].split(']')[0] + ']') + '&wname=' + encodeURIComponent(bwsets[iseloh].split(']')[1] + ']') + '">Draughts Game ' + bwsets[iseloh].split(']')[0] + '] versus ' + bwsets[iseloh].split(']')[1] + ']</option></select>');
seloh=seloh.replace('</select>', '<option value="' + document.URL.split('/chess')[0] + '/chess_game.php?traditional=makyek&bname=' + encodeURIComponent(bwsets[iseloh].split(']')[0] + ']') + '&wname=' + encodeURIComponent(bwsets[iseloh].split(']')[1] + ']') + '">Mak-yek Game ' + bwsets[iseloh].split(']')[0] + '] versus ' + bwsets[iseloh].split(']')[1] + ']</option></select>');
}
seloh=seloh.replace('</select>', '<option value="' + document.URL.split('/chess')[0] + '/chess_game.php' + '">Game Options</option></select>');
seloh=seloh.replace('</select>', '<option value=" ">Forget Saved Player Names Above</option></select>');
}
document.getElementById('dsum').innerHTML=seloh;
}
}
}
}
}
}

function deq(inideais) {
if (document.URL.indexOf(inideais + '=') != -1) {
return inideais + '=';
} else if (document.URL.indexOf('=' + inideais) != -1) {
return '=' + inideais;
}
return "you'l" + "lnever#findth" + "is";
}

function anybw(asq, thebrd, bwenemy, alertallowed) {
thebrd+='&';
isbad=false;
iswrong=false;
var bwfriend=bwenemy.replace('w','!').replace('b','W').replace('!', 'b').toLowerCase();
var okfornow=true, startat=eval('' + asq), twos=[];
var startrow=Math.floor(eval(-1 + asq) / 8);
var startcol=Math.floor(eval(-1 + asq) % 8);
var lastcol=-1, lastrow=-1;
var kposa=[18,-18,17,-17,15,-15,6,-6,10,10];
var pposa=[9,7];
var kgposa=[9,8,7,-1,1,-7,-8,-9];
var ikposa=0;
if (asq == thissquare) {
asq=asq;
}
if (bwfriend == 'w') {
pposa=[-9,-7];
}

//alert('Checking ' + bwfriend + ' King at ' + asq);

// Horizontal check
startat=eval(-1 + asq);
while (startat >= 1 && startat <= 64 && startrow == Math.floor(eval(-1 + startat) / 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(1);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(2);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(3);
return asq;
}
}
}
startat--;
}
startat=eval(1 + asq);
while (startat >= 1 && startat <= 64 && startrow == Math.floor(eval(-1 + startat) / 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(11);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(12);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(13);
return asq;
}
}
}
startat++;
}

// Vertical check
startat=eval(-8 + asq);
while (startat >= 1 && startat <= 64 && startcol == Math.floor(eval(-1 + startat) % 8)) {
//alert('startat=_' + startat);
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(21);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(22);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(23);
return asq;
}
}
}
startat-=8;
}
startat=eval(8 + asq);
while (startat >= 1 && startat <= 64 && startcol == Math.floor(eval(-1 + startat) % 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(24);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(25);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('R') != -1) {
isbad=true;
//alert(26);
return asq;
}
}
}
startat+=8;
}

// Diagonal check
lastcol=Math.floor(eval(-1 + asq) % 8);
lastrow=Math.floor(eval(-1 + asq) / 8);
startat=eval(-9 + asq);
while (startat >= 1 && startat <= 64 && Math.abs(lastcol - Math.floor(eval(-1 + startat) % 8)) == 1 && Math.abs(lastrow - Math.floor(eval(-1 + startat) / 8)) == 1) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert('31 ' + bwfriend + ' ' + twos[0].slice(-3) + ' ' + startat + ' ' + asq);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(32);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(33);
return asq;
}
}
}
lastcol=Math.floor(eval(-1 + startat) % 8);
lastrow=Math.floor(eval(-1 + startat) / 8);
startat-=9;
}
lastcol=Math.floor(eval(-1 + asq) % 8);
lastrow=Math.floor(eval(-1 + asq) / 8);
startat=eval(-7 + asq);
while (startat >= 1 && startat <= 64 && Math.abs(lastcol - Math.floor(eval(-1 + startat) % 8)) == 1 && Math.abs(lastrow - Math.floor(eval(-1 + startat) / 8)) == 1) { // && startcol == Math.floor(eval(-1 + startat) % 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(41);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(42);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(43);
return asq;
}
}
}
lastcol=Math.floor(eval(-1 + startat) % 8);
lastrow=Math.floor(eval(-1 + startat) / 8);
startat-=7;
}
lastcol=Math.floor(eval(-1 + asq) % 8);
lastrow=Math.floor(eval(-1 + asq) / 8);
startat=eval(9 + asq);
while (startat >= 1 && startat <= 64 && Math.abs(lastcol - Math.floor(eval(-1 + startat) % 8)) == 1 && Math.abs(lastrow - Math.floor(eval(-1 + startat) / 8)) == 1) { // && startcol == Math.floor(eval(-1 + startat) % 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(44);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(45);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(46);
return asq;
}
}
}
lastcol=Math.floor(eval(-1 + startat) % 8);
lastrow=Math.floor(eval(-1 + startat) / 8);
startat+=9;
}
lastcol=Math.floor(eval(-1 + asq) % 8);
lastrow=Math.floor(eval(-1 + asq) / 8);
startat=eval(7 + asq);
while (startat >= 1 && startat <= 64 && Math.abs(lastcol - Math.floor(eval(-1 + startat) % 8)) == 1 && Math.abs(lastrow - Math.floor(eval(-1 + startat) / 8)) == 1) { // && startcol == Math.floor(eval(-1 + startat) % 8)) {
//alert('checking square ' + startat);
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(51);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(52);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
break;
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('Q') != -1 || twos[0].slice(-3).indexOf('B') != -1) {
isbad=true;
//alert(53);
return asq;
}
}
}
lastcol=Math.floor(eval(-1 + startat) % 8);
lastrow=Math.floor(eval(-1 + startat) / 8);
startat+=7;
}

// Knight check
for (ikposa=0; ikposa<kposa.length; ikposa++) {
startat=eval(kposa[ikposa] + asq);
if (startat >= 1 && startat <= 64 && startrow != Math.floor(eval(-1 + startat) / 8) && startcol != Math.floor(eval(-1 + startat) % 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('K1') != -1 || twos[0].slice(-3).indexOf('K2') != -1) {
isbad=true;
//alert(61);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('K1') != -1 || twos[0].slice(-3).indexOf('K2') != -1) {
isbad=true;
//alert(62);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('K1') != -1 || twos[0].slice(-3).indexOf('K2') != -1) {
isbad=true;
//alert(63);
return asq;
}
}
}
}
}

// Pawn check
for (ikposa=0; ikposa<pposa.length; ikposa++) {
startat=eval(pposa[ikposa] + asq);
if (startat >= 1 && startat <= 64 && startrow != Math.floor(eval(-1 + startat) / 8) && startcol != Math.floor(eval(-1 + startat) % 8)) {
if (thebrd.indexOf('_' + startat + 'w') != -1) {
twos=thebrd.split('_' + startat + 'w');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('P') != -1) {
isbad=true;
//alert(71);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + 'b') != -1) {
twos=thebrd.split('_' + startat + 'b');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('P') != -1) {
isbad=true;
//alert(72);
return asq;
}
}
} else if (thebrd.indexOf('_' + startat + '&') != -1) {
twos=thebrd.split('_' + startat + '&');
if (twos[0].slice(-3).indexOf(bwfriend) != -1) {
twos[0]=twos[0];
} else if (twos[0].slice(-3).indexOf(bwenemy) != -1) {
if (twos[0].slice(-3).indexOf('P') != -1) {
isbad=true;
//alert(73);
return asq;
}
}
}
}
}