/* Copyright 2007-2010 Richard Jones
This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.5/au/
*/
Gettext=function(_1){
this.domain="messages";
this.locale_data=undefined;
var _2=["domain","locale_data"];
if(this.isValidObject(_1)){
for(var i in _1){
for(var j=0;j<_2.length;j++){
if(i==_2[j]){
if(this.isValidObject(_1[i])){
this[i]=_1[i];
}
}
}
}
}
this.try_load_lang();
return this;
};
Gettext.context_glue="\x04";
Gettext._locale_data={};
Gettext.prototype.try_load_lang=function(){
if(typeof (this.locale_data)!="undefined"){
var _5=this.locale_data;
this.locale_data=undefined;
this.parse_locale_data(_5);
if(typeof (Gettext._locale_data[this.domain])=="undefined"){
throw new Error("Error: Gettext 'locale_data' does not contain the domain '"+this.domain+"'");
}
}
var _6=this.get_lang_refs();
if(typeof (_6)=="object"&&_6.length>0){
for(var i=0;i<_6.length;i++){
var _8=_6[i];
if(_8.type=="application/json"){
if(!this.try_load_lang_json(_8.href)){
throw new Error("Error: Gettext 'try_load_lang_json' failed. Unable to exec xmlhttprequest for link ["+_8.href+"]");
}
}else{
if(_8.type=="application/x-po"){
if(!this.try_load_lang_po(_8.href)){
throw new Error("Error: Gettext 'try_load_lang_po' failed. Unable to exec xmlhttprequest for link ["+_8.href+"]");
}
}else{
throw new Error("TODO: link type ["+_8.type+"] found, and support is planned, but not implemented at this time.");
}
}
}
}
};
Gettext.prototype.parse_locale_data=function(_9){
if(typeof (Gettext._locale_data)=="undefined"){
Gettext._locale_data={};
}
for(var _a in _9){
if((!_9.hasOwnProperty(_a))||(!this.isValidObject(_9[_a]))){
continue;
}
var _b=false;
for(var _c in _9[_a]){
_b=true;
break;
}
if(!_b){
continue;
}
var _d=_9[_a];
if(_a==""){
_a="messages";
}
if(!this.isValidObject(Gettext._locale_data[_a])){
Gettext._locale_data[_a]={};
}
if(!this.isValidObject(Gettext._locale_data[_a].head)){
Gettext._locale_data[_a].head={};
}
if(!this.isValidObject(Gettext._locale_data[_a].msgs)){
Gettext._locale_data[_a].msgs={};
}
for(var _e in _d){
if(_e==""){
var _f=_d[_e];
for(var _10 in _f){
var h=_10.toLowerCase();
Gettext._locale_data[_a].head[h]=_f[_10];
}
}else{
Gettext._locale_data[_a].msgs[_e]=_d[_e];
}
}
}
for(var _a in Gettext._locale_data){
if(this.isValidObject(Gettext._locale_data[_a].head["plural-forms"])&&typeof (Gettext._locale_data[_a].head.plural_func)=="undefined"){
var _12=Gettext._locale_data[_a].head["plural-forms"];
var _13=new RegExp("^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_()])+)","m");
if(_13.test(_12)){
var pf=Gettext._locale_data[_a].head["plural-forms"];
if(!/;\s*$/.test(pf)){
pf=pf.concat(";");
}
var _15="var plural; var nplurals; "+pf+" return { \"nplural\" : nplurals, \"plural\" : (plural === true ? 1 : plural ? plural : 0) };";
Gettext._locale_data[_a].head.plural_func=new Function("n",_15);
}else{
throw new Error("Syntax error in language file. Plural-Forms header is invalid ["+_12+"]");
}
}else{
if(typeof (Gettext._locale_data[_a].head.plural_func)=="undefined"){
Gettext._locale_data[_a].head.plural_func=function(n){
var p=(n!=1)?1:0;
return {"nplural":2,"plural":p};
};
}
}
}
return;
};
Gettext.prototype.try_load_lang_po=function(uri){
var _19=this.sjax(uri);
if(!_19){
return;
}
var _1a=this.uri_basename(uri);
var _1b=this.parse_po(_19);
var rv={};
if(_1b){
if(!_1b[""]){
_1b[""]={};
}
if(!_1b[""]["domain"]){
_1b[""]["domain"]=_1a;
}
_1a=_1b[""]["domain"];
rv[_1a]=_1b;
this.parse_locale_data(rv);
}
return 1;
};
Gettext.prototype.uri_basename=function(uri){
var rv;
if(rv=uri.match(/^(.*\/)?(.*)/)){
var _1f;
if(_1f=rv[2].match(/^(.*)\..+$/)){
return _1f[1];
}else{
return rv[2];
}
}else{
return "";
}
};
Gettext.prototype.parse_po=function(_20){
var rv={};
var _22={};
var _23="";
var _24=[];
var _25=_20.split("\n");
for(var i=0;i<_25.length;i++){
_25[i]=_25[i].replace(/(\n|\r)+$/,"");
var _27;
if(/^$/.test(_25[i])){
if(typeof (_22["msgid"])!="undefined"){
var _28=(typeof (_22["msgctxt"])!="undefined"&&_22["msgctxt"].length)?_22["msgctxt"]+Gettext.context_glue+_22["msgid"]:_22["msgid"];
var _29=(typeof (_22["msgid_plural"])!="undefined"&&_22["msgid_plural"].length)?_22["msgid_plural"]:null;
var _2a=[];
for(var str in _22){
var _27;
if(_27=str.match(/^msgstr_(\d+)/)){
_2a[parseInt(_27[1])]=_22[str];
}
}
_2a.unshift(_29);
if(_2a.length>1){
rv[_28]=_2a;
}
_22={};
_23="";
}
}else{
if(/^#/.test(_25[i])){
continue;
}else{
if(_27=_25[i].match(/^msgctxt\s+(.*)/)){
_23="msgctxt";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgid\s+(.*)/)){
_23="msgid";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgid_plural\s+(.*)/)){
_23="msgid_plural";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\s+(.*)/)){
_23="msgstr_0";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\[0\]\s+(.*)/)){
_23="msgstr_0";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\[(\d+)\]\s+(.*)/)){
_23="msgstr_"+_27[1];
_22[_23]=this.parse_po_dequote(_27[2]);
}else{
if(/^"/.test(_25[i])){
_22[_23]+=this.parse_po_dequote(_25[i]);
}else{
_24.push("Strange line ["+i+"] : "+_25[i]);
}
}
}
}
}
}
}
}
}
}
if(typeof (_22["msgid"])!="undefined"){
var _28=(typeof (_22["msgctxt"])!="undefined"&&_22["msgctxt"].length)?_22["msgctxt"]+Gettext.context_glue+_22["msgid"]:_22["msgid"];
var _29=(typeof (_22["msgid_plural"])!="undefined"&&_22["msgid_plural"].length)?_22["msgid_plural"]:null;
var _2a=[];
for(var str in _22){
var _27;
if(_27=str.match(/^msgstr_(\d+)/)){
_2a[parseInt(_27[1])]=_22[str];
}
}
_2a.unshift(_29);
if(_2a.length>1){
rv[_28]=_2a;
}
_22={};
_23="";
}
if(rv[""]&&rv[""][1]){
var cur={};
var _2d=rv[""][1].split(/\\n/);
for(var i=0;i<_2d.length;i++){
if(!_2d.length){
continue;
}
var pos=_2d[i].indexOf(":",0);
if(pos!=-1){
var key=_2d[i].substring(0,pos);
var val=_2d[i].substring(pos+1);
var _31=key.toLowerCase();
if(cur[_31]&&cur[_31].length){
_24.push("SKIPPING DUPLICATE HEADER LINE: "+_2d[i]);
}else{
if(/#-#-#-#-#/.test(_31)){
_24.push("SKIPPING ERROR MARKER IN HEADER: "+_2d[i]);
}else{
val=val.replace(/^\s+/,"");
cur[_31]=val;
}
}
}else{
_24.push("PROBLEM LINE IN HEADER: "+_2d[i]);
cur[_2d[i]]="";
}
}
rv[""]=cur;
}else{
rv[""]={};
}
return rv;
};
Gettext.prototype.parse_po_dequote=function(str){
var _33;
if(_33=str.match(/^"(.*)"/)){
str=_33[1];
}
str=str.replace(/\\"/,"");
return str;
};
Gettext.prototype.try_load_lang_json=function(uri){
var _35=this.sjax(uri);
if(!_35){
return;
}
var rv=this.JSON(_35);
this.parse_locale_data(rv);
return 1;
};
Gettext.prototype.get_lang_refs=function(){
var _37=new Array();
var _38=document.getElementsByTagName("link");
for(var i=0;i<_38.length;i++){
if(_38[i].rel=="gettext"&&_38[i].href){
if(typeof (_38[i].type)=="undefined"||_38[i].type==""){
if(/\.json$/i.test(_38[i].href)){
_38[i].type="application/json";
}else{
if(/\.js$/i.test(_38[i].href)){
_38[i].type="application/json";
}else{
if(/\.po$/i.test(_38[i].href)){
_38[i].type="application/x-po";
}else{
if(/\.mo$/i.test(_38[i].href)){
_38[i].type="application/x-mo";
}else{
throw new Error("LINK tag with rel=gettext found, but the type and extension are unrecognized.");
}
}
}
}
}
_38[i].type=_38[i].type.toLowerCase();
if(_38[i].type=="application/json"){
_38[i].type="application/json";
}else{
if(_38[i].type=="text/javascript"){
_38[i].type="application/json";
}else{
if(_38[i].type=="application/x-po"){
_38[i].type="application/x-po";
}else{
if(_38[i].type=="application/x-mo"){
_38[i].type="application/x-mo";
}else{
throw new Error("LINK tag with rel=gettext found, but the type attribute ["+_38[i].type+"] is unrecognized.");
}
}
}
}
_37.push(_38[i]);
}
}
return _37;
};
Gettext.prototype.textdomain=function(_3a){
if(_3a&&_3a.length){
this.domain=_3a;
}
return this.domain;
};
Gettext.prototype.gettext=function(_3b){
var _3c;
var _3d;
var n;
var _3f;
return this.dcnpgettext(null,_3c,_3b,_3d,n,_3f);
};
Gettext.prototype.dgettext=function(_40,_41){
var _42;
var _43;
var n;
var _45;
return this.dcnpgettext(_40,_42,_41,_43,n,_45);
};
Gettext.prototype.dcgettext=function(_46,_47,_48){
var _49;
var _4a;
var n;
return this.dcnpgettext(_46,_49,_47,_4a,n,_48);
};
Gettext.prototype.ngettext=function(_4c,_4d,n){
var _4f;
var _50;
return this.dcnpgettext(null,_4f,_4c,_4d,n,_50);
};
Gettext.prototype.dngettext=function(_51,_52,_53,n){
var _55;
var _56;
return this.dcnpgettext(_51,_55,_52,_53,n,_56);
};
Gettext.prototype.dcngettext=function(_57,_58,_59,n,_5b){
var _5c;
return this.dcnpgettext(_57,_5c,_58,_59,n,_5b,_5b);
};
Gettext.prototype.pgettext=function(_5d,_5e){
var _5f;
var n;
var _61;
return this.dcnpgettext(null,_5d,_5e,_5f,n,_61);
};
Gettext.prototype.dpgettext=function(_62,_63,_64){
var _65;
var n;
var _67;
return this.dcnpgettext(_62,_63,_64,_65,n,_67);
};
Gettext.prototype.dcpgettext=function(_68,_69,_6a,_6b){
var _6c;
var n;
return this.dcnpgettext(_68,_69,_6a,_6c,n,_6b);
};
Gettext.prototype.npgettext=function(_6e,_6f,_70,n){
var _72;
return this.dcnpgettext(null,_6e,_6f,_70,n,_72);
};
Gettext.prototype.dnpgettext=function(_73,_74,_75,_76,n){
var _78;
return this.dcnpgettext(_73,_74,_75,_76,n,_78);
};
Gettext.prototype.dcnpgettext=function(_79,_7a,_7b,_7c,n,_7e){
if(!this.isValidObject(_7b)){
return "";
}
var _7f=this.isValidObject(_7c);
var _80=this.isValidObject(_7a)?_7a+Gettext.context_glue+_7b:_7b;
var _81=this.isValidObject(_79)?_79:this.isValidObject(this.domain)?this.domain:"messages";
var _82="LC_MESSAGES";
var _7e=5;
var _83=new Array();
if(typeof (Gettext._locale_data)!="undefined"&&this.isValidObject(Gettext._locale_data[_81])){
_83.push(Gettext._locale_data[_81]);
}else{
if(typeof (Gettext._locale_data)!="undefined"){
for(var dom in Gettext._locale_data){
_83.push(Gettext._locale_data[dom]);
}
}
}
var _85=[];
var _86=false;
var _87;
if(_83.length){
for(var i=0;i<_83.length;i++){
var _89=_83[i];
if(this.isValidObject(_89.msgs[_80])){
for(var j=0;j<_89.msgs[_80].length;j++){
_85[j]=_89.msgs[_80][j];
}
_85.shift();
_87=_89;
_86=true;
if(_85.length>0&&_85[0].length!=0){
break;
}
}
}
}
if(_85.length==0||_85[0].length==0){
_85=[_7b,_7c];
}
var _8b=_85[0];
if(_7f){
var p;
if(_86&&this.isValidObject(_87.head.plural_func)){
var rv=_87.head.plural_func(n);
if(!rv.plural){
rv.plural=0;
}
if(!rv.nplural){
rv.nplural=0;
}
if(rv.nplural<=rv.plural){
rv.plural=0;
}
p=rv.plural;
}else{
p=(n!=1)?1:0;
}
if(this.isValidObject(_85[p])){
_8b=_85[p];
}
}
return _8b;
};
Gettext.strargs=function(str,_8f){
if(null==_8f||"undefined"==typeof (_8f)){
_8f=[];
}else{
if(_8f.constructor!=Array){
_8f=[_8f];
}
}
var _90="";
while(true){
var i=str.indexOf("%");
var _92;
if(i==-1){
_90+=str;
break;
}
_90+=str.substr(0,i);
if(str.substr(i,2)=="%%"){
_90+="%";
str=str.substr((i+2));
}else{
if(_92=str.substr(i).match(/^%(\d+)/)){
var _93=parseInt(_92[1]);
var _94=_92[1].length;
if(_93>0&&_8f[_93-1]!=null&&typeof (_8f[_93-1])!="undefined"){
_90+=_8f[_93-1];
}
str=str.substr((i+1+_94));
}else{
_90+="%";
str=str.substr((i+1));
}
}
}
return _90;
};
Gettext.prototype.strargs=function(str,_96){
return Gettext.strargs(str,_96);
};
Gettext.prototype.isArray=function(_97){
return this.isValidObject(_97)&&_97.constructor==Array;
};
Gettext.prototype.isValidObject=function(_98){
if(null==_98){
return false;
}else{
if("undefined"==typeof (_98)){
return false;
}else{
return true;
}
}
};
Gettext.prototype.sjax=function(uri){
var _9a;
if(window.XMLHttpRequest){
_9a=new XMLHttpRequest();
}else{
if(navigator.userAgent.toLowerCase().indexOf("msie 5")!=-1){
_9a=new ActiveXObject("Microsoft.XMLHTTP");
}else{
_9a=new ActiveXObject("Msxml2.XMLHTTP");
}
}
if(!_9a){
throw new Error("Your browser doesn't do Ajax. Unable to support external language files.");
}
_9a.open("GET",uri,false);
try{
_9a.send(null);
}
catch(e){
return;
}
var _9b=_9a.status;
if(_9b==200||_9b==0){
return _9a.responseText;
}else{
var _9c=_9a.statusText+" (Error "+_9a.status+")";
if(_9a.responseText.length){
_9c+="\n"+_9a.responseText;
}
alert(_9c);
return;
}
};
Gettext.prototype.JSON=function(_9d){
return eval("("+_9d+")");
};

CTSound=function(_1){
this.sounds=[];
this.soundPath=_1.soundPath;
var _2=!!((myAudioTag=document.createElement("audio")).canPlayType);
var _3=null;
if(typeof Audio!="undefined"){
_3=new Audio("");
}
this.haveAudio=_3&&!!(_3.canPlayType);
if(this.haveAudio){
this.canPlayOgg=(("no"!=_3.canPlayType("audio/ogg"))&&(""!=_3.canPlayType("audio/ogg")));
this.canPlayMp3=(("no"!=_3.canPlayType("audio/mpeg"))&&(""!=_3.canPlayType("audio/mpeg")));
this.canPlayWav=(("no"!=_3.canPlayType("audio/wav"))&&(""!=_3.canPlayType("audio/wav")));
}
};
CTSound.prototype.createSound=function(_4,_5){
if(!this.haveAudio){
return;
}
var _6=null;
var _7="";
if(this.canPlayMp3){
_7=this.soundPath+"/"+_4+".mp3";
}else{
if(this.canPlayOgg){
_7=this.soundPath+"/"+_4+".ogg";
}else{
if(this.canPlayWav){
_7=this.soundPath+"/"+_4+".wav";
}
}
}
if(_7){
_6=new Audio(_7);
}
if(_6){
_6.id=_5+"-"+_4;
this.sounds[_4]=_6;
if(_5){
this.sounds[_5]=_6;
}
}
};
CTSound.prototype.playSound=function(_8){
var _9=this.sounds[_8];
if(_9){
_9.play();
}
};

function getLocale(){
if(navigator){
if(navigator.language){
return navigator.language;
}else{
if(navigator.browserLanguage){
return navigator.browserLanguage;
}else{
if(navigator.systemLanguage){
return navigator.systemLanguage;
}else{
if(navigator.userLanguage){
return navigator.userLanguage;
}
}
}
}
}
}
var gt=null;
function init_gettext(){
if(typeof json_locale_data!=="undefined"){
var _1={"domain":"js-messages","locale_data":json_locale_data};
gt=new Gettext(_1);
}
}
init_gettext();
function _js(_2){
if(gt){
return gt.gettext(_2);
}else{
return _2;
}
}
function __js(_3,a){
var _3=_js(_3);
for(var i=0;i<a.length;i++){
var re=new RegExp("{"+a[i][0]+"}","g");
_3=_3.replace(re,a[i][1]);
}
return _3;
}
function _jn(_7,_8,_9){
var _a;
if(gt){
_a=gt.ngettext(_7,_8,_9);
}else{
if(_9==0||_9>1){
_a=_8;
}else{
_a=_7;
}
}
return _a;
}
function __jn(_b,_c,_d,a){
var _f=_jn(_b,_c,_d);
return __gt_expand(_f,a);
return _f;
}
function __gt_expand(msg,a){
for(var i=0;i<a.length;i++){
var re=new RegExp("{"+a[i][0]+"}","g");
msg=msg.replace(re,a[i][1]);
}
return msg;
}

PgnViewer=function(_1,_2){
var _3=new BoardConfig();
if(_1){
_3.applyConfig(_1);
}
if(!window._pvObject){
window._pvObject=new Array();
}
window._pvObject[_3.boardName]=this;
_1=_3;
_1.pgnMode=true;
_1.scrollVariations=true;
this.chessapp=new ChessApp(_1);
this.finishedCallback=_2;
if(_1.loadImmediately){
this.chessapp.init(null,null,null,this,true);
this.board=this.chessapp.board;
}else{
YAHOO.util.Event.onDOMReady(this.setup,this,true);
}
};
PgnViewer.prototype.setup=function(){
this.chessapp.init(null,null,null,this,true);
this.board=this.chessapp.board;
};
PgnViewer.prototype.updatePieceCallback=function(_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f){
var _10=new Object();
var _11=_e;
var _12=false;
var _13=Board.getVarMove(_11,_7,_6,_5,_4);
if(_11.fromColumn==_5.column&&_11.fromRow==_5.row&&_11.toRow==_7&&_11.toColumn==_6&&(_4==""||(_4==_11.promotion))){
_12=true;
}else{
if(_13){
_11=_13;
_12=true;
}
}
_10.move=_11;
_10.allowMove=_12;
_10.dontMakeOpponentMove=false;
return _10;
};
PgnViewer.prototype.setupFromPgn=function(pgn,_15){
this.chessapp.pgn.setupFromPGN(pgn,_15);
};
PgnViewer.prototype.setupFromFen=function(fen,_17,_18,_19){
this.chessapp.pgn.board.setupFromFen(fen,_17,_18,_19);
};
PGNGame=function(_1a,_1b,_1c,_1d,_1e,_1f,_20,_21,_22,_23,_24,_25){
this.movesseq=_1a;
this.startFen=_1b;
this.blackPlayer=_1c;
this.whitePlayer=_1d;
this.pgn_result=_1e;
this.event=_1f;
this.site=_20;
this.date=_21;
this.round=_22;
this.start_movenum=_23;
this.whitePlayerElo=_24;
this.blackPlayerElo=_25;
};
PGN=function(_26){
this.board=_26;
this.pgnGames=new Array();
this.lastShownGame=0;
};
PGN.prototype.pollPGNFromURL=function(url,_28,_29){
var _2a=this;
this.getPGNFromURL(url,_28);
if(this.foundResult){
_29=this.board.pollPGNMillisecondsPostResult;
this.foundResultPolls++;
}
if(this.foundResultPolls>=this.board.numberPollsAfterResult){
return;
}
setTimeout(function(){
_2a.pollPGNFromURL(url,_28,_29);
},_29);
};
PGN.prototype.getPGNFromURL=function(url,_2c){
var _2d=(new Date()).getTime()+"-"+parseInt(Math.random()*99999);
YAHOO.util.Connect.asyncRequest("GET",url+"?rs="+_2d,{success:function(o){
var _2f="";
var _30="";
var _31="";
var re=eval("/\\n[^[]/");
if(o.responseText.indexOf("\r")>=0){
eval("/\\r[^[]/");
}
var ind=o.responseText.search(re);
if(ind>=0){
_31=o.responseText.substring(ind);
}
re=eval("/\\[Result /");
ind=o.responseText.search(re);
if(ind>=0){
var _34=o.responseText.indexOf("\n",ind);
if(_34<0){
_34=o.responseText.indexOf("\r",ind);
}
if(_34>=0){
_2f=o.responseText.substring(ind,_34);
}
}
re=eval("/\\[Site /");
ind=o.responseText.search(re);
if(ind>=0){
var _34=o.responseText.indexOf("]",ind);
if(_34>=0){
_30=o.responseText.substring(ind+6,_34-1);
}
}
if(_30){
if(this.board.fideClock){
var _35=YAHOO.util.Dom.get(this.board.boardName+"-whitePlayerClock");
var _36=YAHOO.util.Dom.get(this.board.boardName+"-blackPlayerClock");
var ss=_30.split("-");
var _38=ss[0];
var _39="0";
if(_38.charAt(0)=="\""){
_38=_38.substr(1);
}
if(ss.length>1){
_39=ss[1];
}
if(_35){
_35.innerHTML=_38;
}
if(_36){
_36.innerHTML=_39;
}
}else{
var _3a=YAHOO.util.Dom.get(this.board.boardName+"-site");
if(_3a){
_3a.innerHTML=_30;
}
}
}
if(this.currentMoveText==_31&&this.currentResultTag==_2f){
return;
}
this.currentMoveText=_31;
this.currentResultTag=_2f;
this.setupFromPGN(o.responseText,_2c);
},failure:function(o){
if(!this.board.hidePGNErrors){
alert("pgn load failed:"+o.statusText+" for file:"+url);
}
},scope:this},"rs2="+_2d);
};
PGN.prototype.getMoveFromPGNMove=function(_3c,_3d,_3e){
var _3f=false;
var _40=false;
var _41=false;
var _42;
var _43=null;
var _44=false;
var _45=null;
if(_3c.charAt(_3c.length-1)=="#"){
_40=true;
_3f=true;
_3c=_3c.substr(0,_3c.length-1);
}else{
if(_3c.charAt(_3c.length-1)=="+"){
_40=true;
if(_3c.length>1&&_3c.charAt(_3c.length-2)=="+"){
_3f=true;
_3c=_3c.substr(0,_3c.length-2);
}else{
_3c=_3c.substr(0,_3c.length-1);
}
}
}
if(_3c=="O-O-O"){
if(_3d=="w"){
return this.board.createMoveFromString("e1c1");
}else{
return this.board.createMoveFromString("e8c8");
}
}else{
if(_3c=="O-O"){
if(_3d=="w"){
return this.board.createMoveFromString("e1g1");
}else{
return this.board.createMoveFromString("e8g8");
}
}
}
var _46=_3c.indexOf("=");
if(_46>=0){
var _47;
_43=_3c.substr(_46+1,1);
_47=_43.charAt(0);
_42=this.board.pieceCharToPieceNum(_47);
_41=true;
_3c=_3c.substr(0,_46);
}
var _48=_3c.charAt(_3c.length-1);
if(_48=="Q"||_48=="R"||_48=="N"||_48=="B"){
_43=_48+"";
_42=this.board.pieceCharToPieceNum(_43);
_41=true;
_3c=_3c.substr(0,_3c.length-1);
}
var _49=_3c.substr(_3c.length-2,2);
var _4a=_49.charCodeAt(0)-"a".charCodeAt(0);
var _4b=_49.charCodeAt(1)-"1".charCodeAt(0);
if(_4a>7||_4a<0||_4b>7||_4b<0){
this.lastMoveFromError=__js("Error processing to Square:{TO_SQUARE} on move:{MOVE}",[["TO_SQUARE",_49],["MOVE",_3c]]);
return null;
}
if(_3c.length>2){
if(_3c.charAt(_3c.length-3)=="x"){
_44=true;
_45=_3c.substr(0,_3c.length-3);
}else{
_45=_3c.substr(0,_3c.length-2);
}
}
var _4c=new Array();
var _4d=0;
var _4e=null;
var _4f=(_3d=="w")?ChessPiece.WHITE:ChessPiece.BLACK;
switch(_3c.charAt(0)){
case "K":
case "k":
_4e=ChessPiece.KING;
break;
case "Q":
case "q":
_4e=ChessPiece.QUEEN;
break;
case "R":
case "r":
_4e=ChessPiece.ROOK;
break;
case "B":
_4e=ChessPiece.BISHOP;
break;
case "N":
case "n":
_4e=ChessPiece.KNIGHT;
break;
case "P":
case "p":
_4e=ChessPiece.PAWN;
break;
default:
_4e=ChessPiece.PAWN;
}
var _50=null;
var _51=null;
if(_45){
var _52=_45.toLowerCase().charAt(0);
if(_52==_45.charAt(0)&&_52>="a"&&_52<="h"){
_51=_52;
if(_45.length==2){
_50=_45.charAt(1);
}
}else{
if(_45.length>1){
if(_45.length==2){
var c=_45.charAt(1);
if(c>="1"&&c<="8"){
_50=c;
}else{
_51=c;
}
}else{
if(_45.length==3){
_51=_45.charAt(1);
_50=_45.charAt(2);
if(_51>="1"&&_51<="9"){
var tmp=_51;
_51=_50;
_50=tmp;
}
}else{
this.lastMoveFromError=__js("Error: unhandled fromChars:{FROM_CHARS}",[["FROM_CHARS",_45]]);
return null;
}
}
}
}
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.board.boardPieces[i][j];
if(bp!=null&&bp.colour==_4f&&bp.piece==_4e){
if(this.board.canMove(bp,_4a,_4b,_3e,true)){
var _58=String.fromCharCode("a".charCodeAt(0)+i).charAt(0);
var _59=String.fromCharCode("1".charCodeAt(0)+j).charAt(0);
if((_51==null||_51==_58)&&(_50==null||_50==_59)){
_4c[_4d++]=bp;
}else{
}
}
}
}
}
if(_4d==0){
this.lastMoveFromError=__js("no candidate pieces for:{MOVE}",[["MOVE",_3c]]);
return null;
}
if(_4d>1){
this.lastMoveFromError=__js("Ambiguous:{MOVE} with fromChars:{FROM_CHARS} disambigRow:{DISAMBIG_ROW} disambigCol:{DISAMBIG_COL}",[["MOVE",_3c],["FROM_CHARS",_45],["DISAMBIG_ROW",_50],["DISAMBIG_COL",_51]]);
return null;
}
var _5a=_4c[0];
var _5b="";
_5b+=String.fromCharCode("a".charCodeAt(0)+_5a.column);
_5b+=String.fromCharCode("1".charCodeAt(0)+_5a.row);
if(_44){
_5b+="x";
}
_5b+=_49;
if(_43){
_5b+=_43;
}
var _5c=this.board.createMoveFromString(_5b);
return _5c;
};
PGN.prototype.parseTag=function(_5d,pgn,_5f){
if(pgn.substr(_5f,_5d.length+3)=="["+_5d+" \""){
var _60=pgn.indexOf("\"",_5f+_5d.length+3);
if(_60>=0){
return pgn.substring(_5f+_5d.length+3,_60);
}
}
return null;
};
PGN.prototype.parsePGN=function(pgn,_62,_63){
if(ctime){
console.time("parsePGN");
}
pgn=pgn.replace(/^\s+|\s+$/g,"");
var _64=0;
this.pgn=pgn;
var _65=new Array();
var _66=1;
var _67=0;
this.pgnGames=new Array();
this.finishedParseCallback=_62;
this.startParseTime=new Date().getTime();
var ret=this.parsePGN_cont(_65,_66,_67,_64,_63);
var _69=new Object();
if(!ret){
_69.parsedOk=true;
_69.pgnGames=this.pgnGames;
}else{
_69.parsedOk=false;
_69.errorString=ret;
_69.pgnGames=null;
}
if(ctime){
console.timeEnd("parsePGN");
}
return _69;
};
PGN.prototype.parsePGN_cont=function(_6a,_6b,_6c,_6d,_6e){
var pgn=this.pgn;
var _70=this.board.boardName+"-progress";
var _71=YAHOO.util.Dom.get(_70);
while(_6d<pgn.length){
var _72="";
var _73="";
var _74="";
var _75="";
var _76="";
var _77="";
var _78="";
var _79="?";
var _7a="?";
var _7b="w";
var _7c=0;
var _7d=0;
var _7e=new Array();
var _7f=0;
var _80="";
var _81=null;
var _82=null;
var _83=new Array();
var _84=new Array();
var _85=new Array();
var _86=new Array();
var _87=new Array();
this.board.pieceMoveDisabled=true;
if(this.board.initialFen){
this.board.startFen=this.board.initialFen;
}else{
this.board.startFen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
}
var i=0;
for(i=_6d;i<pgn.length;i++){
var tag=this.parseTag("FEN",pgn,i);
if(tag&&tag!="?"){
this.board.startFen=tag;
}else{
tag=this.parseTag("White",pgn,i);
if(tag&&tag!="?"){
_78=tag;
}else{
tag=this.parseTag("Black",pgn,i);
if(tag&&tag!="?"){
_73=tag;
}else{
tag=this.parseTag("Result",pgn,i);
if(tag&&tag!="?"){
_72=tag;
}else{
tag=this.parseTag("Event",pgn,i);
if(tag&&tag!="?"){
_74=tag;
}else{
tag=this.parseTag("Site",pgn,i);
if(tag&&tag!="?"){
_75=tag;
}else{
tag=this.parseTag("Date",pgn,i);
if(tag&&tag!="?"){
_76=tag;
}else{
tag=this.parseTag("Round",pgn,i);
if(tag&&tag!="?"){
_77=tag;
}else{
tag=this.parseTag("WhiteElo",pgn,i);
if(tag&&tag!="?"){
_79=tag;
}else{
tag=this.parseTag("BlackElo",pgn,i);
if(tag&&tag!="?"){
_7a=tag;
}
}
}
}
}
}
}
}
}
}
if(pgn.charAt(i)=="["){
var j=pgn.indexOf;
for(j=i+1;j<pgn.length&&pgn.charAt(j)!="]";j++){
}
if(j==pgn.length){
var err=_js("PgnViewer: Error parsing PGN. Found unclosed [");
if(this.finishedParseCallback){
this.finishedParseCallback(_6e,err);
}
return err;
}
i=j-1;
continue;
}
if(pgn.charAt(i)=="{"){
var _8c=pgn.indexOf("}",i+1);
if(_8c>=0){
var _8d=pgn.substring(i+1,_8c);
i=_8c;
_80+="{ "+_8d+" } ";
}else{
var err=_js("PgnViewer: Error parsing PGN. Found unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_6e,err);
}
return err;
}
continue;
}
if(pgn.substr(i,1)=="."){
var j=i-1;
while(j>=0&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
j--;
}
j++;
if(pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
_6b=parseInt(pgn.substring(j,i));
}
break;
}
}
if(pgn.substr(i,1)!="."){
}
this.board.prev_move=null;
this.board.setupFromFen(this.board.startFen,false,false,true,true);
_81=this.board.prev_move;
var _8e=i;
var _8f=null;
for(i=i;i<pgn.length;i++){
var _90=-1;
if(pgn.substr(i,3)=="1-0"||pgn.substr(i,3)=="0-1"){
_90=3;
}else{
if(pgn.substr(i,7)=="1/2-1/2"){
_90=7;
}else{
if(pgn.substr(i,1)=="*"){
_90=1;
}
}
}
if(_90>0){
_8f=pgn.substr(i,_90);
_6d=i+_90;
break;
}
if(pgn.charAt(i)=="["){
_6d=i;
break;
}
if(pgn.charAt(i)==" "||pgn.charAt(i)=="\t"||pgn.charAt(i)=="\n"||pgn.charAt(i)=="\r"){
_8e=i+1;
continue;
}
if(pgn.charAt(i)>="0"&&pgn.charAt(i)<="9"){
continue;
}
if(pgn.charAt(i)=="."){
var _91=pgn.substring(_8e,i).replace(/^\s+|\s+$/g,"");
_8e=i;
while(i+1<pgn.length&&pgn.charAt(i+1)=="."){
i++;
}
if(_8e!=i){
_7b="b";
}else{
_7b="w";
}
_8e=i+1;
}else{
if(pgn.charAt(i)=="{"){
var _8c=pgn.indexOf("}",i+1);
if(_8c>=0){
var _8d=pgn.substring(i+1,_8c);
i=_8c;
_80+="{ "+_8d+" } ";
}
_8e=i+1;
}else{
if(pgn.charAt(i)=="("){
_83[_7c]=this.board.boardPieces;
_84[_7c]=_7b;
_86[_7c]=_81;
_87[_7c]=_82;
this.board.boardPieces=_85[_7c];
this.board.boardPieces=this.board.copyBoardPieces(false);
_81=_82;
_7c++;
_8e=i+1;
_80+="( ";
}else{
if(pgn.charAt(i)==")"){
boardPool.putObject(_83[_7c]);
_7c--;
this.board.boardPieces=_83[_7c];
_7b=_84[_7c];
_81=_86[_7c];
_82=_87[_7c];
_8e=i+1;
_80+=") ";
}else{
if(pgn.charAt(i)=="$"){
var j;
for(j=i+1;j<pgn.length&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9";j++){
}
j--;
if(j>i){
var _92=parseInt(pgn.substr(i+1,j+1));
if(_92<=9){
switch(_92){
case 1:
_80=_80.substr(0,_80.length-1)+"! ";
break;
case 2:
_80=_80.substr(0,_80.length-1)+"? ";
break;
case 3:
_80=_80.substr(0,_80.length-1)+"!! ";
break;
case 4:
_80=_80.substr(0,_80.length-1)+"?? ";
break;
case 5:
_80=_80.substr(0,_80.length-1)+"!? ";
break;
case 6:
_80=_80.substr(0,_80.length-1)+"?! ";
break;
case 7:
case 8:
case 9:
case 0:
default:
}
}else{
_80+=pgn.substring(i,j+1)+" ";
}
i=j;
}
continue;
}else{
var _93=-1;
for(var j=i+1;j<pgn.length;j++){
if(pgn.charAt(j)==")"||pgn.charAt(j)=="("||pgn.charAt(j)=="{"||pgn.charAt(j)=="}"||pgn.charAt(j)==" "||pgn.charAt(j)=="\t"||pgn.charAt(j)=="\n"||pgn.charAt(j)=="\r"){
_93=j;
break;
}
}
if(_93==-1){
_93=pgn.length;
}
var _94=_8e;
var _95=pgn.substring(_8e,_93).replace(/^\s+|\s+$/g,"");
_8e=_93;
i=_8e-1;
if(_95.length>=4&&_95.substring(0,4)=="e.p."){
continue;
}
if(_95.length==0){
var err=__js("PgnViewer: Error: got empty move endMoveInd:{ENDMOVE_INDEX} upto:{UPTO} from:{FROM}",[["ENDMOVE_INDEX",_93],["UPTO",_94],["FROM",pgn.substr(_94)]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_6e,err);
}
return err;
}
var _96=_95.length-1;
while(_96>=0){
if(_95.charAt(_96)=="?"){
_96--;
}else{
if(_95.charAt(_96)=="!"){
_96--;
}else{
break;
}
}
}
var _97=_95.substring(0,_96+1);
var _98=this.getMoveFromPGNMove(_97,_7b,_81);
if(_98==null){
_80+="unknown ";
var err=__js("PgnViewer: Error parsing:{MOVE}, {ERROR_REASON}",[["MOVE",_95],["ERROR_REASON",this.lastMoveFromError]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_6e,err);
}
return err;
}
_82=_81;
_81=_98;
var _99=this.board.boardPieces[_98.fromColumn][_98.fromRow];
boardPool.putObject(_85[_7c]);
_85[_7c]=this.board.copyBoardPieces(false);
if(_99){
this.board.makeMove(_98,_99,false,0.5,false,false);
}
_7d=_7c;
_7f++;
_7b=this.board.flipToMove(_7b);
_80+=_98.moveString+"|"+_95+" ";
}
}
}
}
}
}
if(_6d<i){
_6d=i;
}
var _9a=pgn.indexOf("{",_6d);
var _9b=pgn.indexOf("[",_6d);
if(_9a>=0){
if(_9b==-1||_9a<_9b){
var _9c=pgn.indexOf("}",_9a+1);
if(_9c>=0){
var _8d=pgn.substring(_9a+1,_9c);
_6d=_9c+1;
_80+="{ "+_8d+" } ";
}else{
var err=_js("PgnViewer: Error: Unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_6e,err);
}
return err;
}
}
}
_80=_80.replace(/^\s+|\s+$/g,"");
this.board.pieceMoveDisabled=false;
if(_8f!=null){
if(_72.length==0||_72=="?"){
_72=_8f;
}
}
this.pgnGames[_6c++]=new PGNGame(_80,this.board.startFen,_73,_78,_72,_74,_75,_76,_77,_6b,_79,_7a);
if(_71){
_71.innerHTML="Loaded "+_6c+" games";
}
if(this.finishedParseCallback&&new Date().getTime()-this.startParseTime>500){
this.startParseTime=new Date().getTime();
setTimeout("window._pvObject[\""+this.board.boardName+"\"].chessapp.pgn.parsePGN_cont(\""+_6a+"\",\""+_6b+"\",\""+_6c+"\",\""+_6d+"\","+_6e+");",0);
return;
}
}
if(this.finishedParseCallback){
this.finishedParseCallback(_6e);
}
return false;
};
PGN.prototype.setupFromPGN=function(pgn,_9e){
this.parsePGN(pgn,this.setupFromPGNCallback,_9e);
};
PGN.prototype.setupFromPGNCallback=function(_9f,err){
var _a1=this.board.boardName+"-progress";
var _a2=YAHOO.util.Dom.get(_a1);
if(err){
if(!this.board.hidePGNErrors){
alert(err);
}
return false;
}
if(this.pgnGames.length==0){
if(!this.board.hidePGNErrors){
alert("PgnViewer: Error: Unable to find any pgn games in:"+pgn);
}
return false;
}
if(this.pgnGames.length==1){
var _a3=0;
if(_9f){
_a3=-1;
}
this.showGame(0,_a3);
}else{
var _a4=this.board.boardName+"-container";
var _a5=YAHOO.util.Dom.get(_a4);
var _a6=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
var _a7=document.createElement("div");
var _a8="<form id=\""+this.board.boardName+"-problemSelectorForm\" action=\"\" method=\"\">";
var _a9="<select id=\""+this.board.boardName+"-problemSelector\" name=\""+this.board.boardName+"-problemSelector\" style=\"width: "+this.board.pieceSize*8+"px;\">";
var _aa="";
for(i=0;i<this.pgnGames.length;i++){
var _ab=this.pgnGames[i];
var _ac=this.board.boardName+"-game-"+i;
var _ad=(i+1)+". "+_ab.whitePlayer+" vs "+_ab.blackPlayer;
if(_ab.pgn_result.length>0&&_ab.pgn_result!="?"&&this.board.showResult==1){
_ad+=" "+_ab.pgn_result;
}
if(_ab.event.length>0&&_ab.event!="?"&&this.board.showEvent==1){
_ad+=" "+_ab.event;
}
if(_ab.round.length>0&&_ab.round!="?"&&this.board.showRound==1){
_ad+=" Rnd:"+_ab.round;
}
if(_ab.site.length>0&&_ab.site!="?"&&this.board.showSite==1){
_ad+=" "+_ab.site;
}
if(_ab.date.length>0&&_ab.date!="?"&&this.board.showDate==1){
_ad+=" "+_ab.date;
}
var sel="";
if(i==this.lastShownGame){
sel="selected=\"\"";
}
_aa+="<option "+sel+" id=\""+_ac+"\" value=\""+i+"\">"+_ad+"</option>";
}
if(_a6){
if(this.board.selectorBody!=_aa){
_a6.innerHTML=_aa;
this.board.selectorBody=_aa;
}
}else{
_a8+=_a9+_aa+"</select></form>";
_a7.innerHTML=_a8;
_a5.insertBefore(_a7,_a5.firstChild);
this.board.selectorBody=_aa;
}
var _a6=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
YAHOO.util.Event.addListener(_a6,"change",this.selectGame,this,true);
var _a3=0;
var _af=0;
if(_9f){
_a3=-1;
_af=this.lastShownGame;
}
this.showGame(_af,_a3);
}
if(_a2){
YAHOO.util.Dom.setStyle(_a2,"visibility","hidden");
}
if(window._pvObject[this.board.boardName].finishedCallback){
window._pvObject[this.board.boardName].finishedCallback();
}
return;
};
PGN.prototype.selectGame=function(e){
var _b1=YAHOO.util.Event.getTarget(e).selectedIndex;
var _b2=0;
if(this.board.gotoEndOnRefresh){
_b2=-1;
}
this.showGame(_b1,_b2);
var _b3=this.board.boardName+"-piecestaken";
var _b4=YAHOO.util.Dom.get(_b3);
if(_b4){
_b4.innerHTML="";
}
this.board.resetMoveListScrollPosition();
};
PGN.prototype.showGame=function(_b5,_b6){
_b6=(typeof _b6=="undefined")?0:_b6;
var _b7=this.lastShownGame;
this.lastShownGame=_b5;
var _b8=this.board.moveArray;
var _b9=this.board.currentMove;
var _ba=false;
if(_b9&&_b9.atEnd){
_ba=true;
}
var _bb=this.pgnGames[_b5];
var _bc=_bb.pgn_result;
if(_bc&&(_bc=="1/2-1/2"||_bc=="0-1"||_bc=="1-0")){
this.foundResult=true;
}else{
this.foundResult=false;
this.foundResultPolls=0;
}
this.board.startFen=_bb.startFen;
this.board.setupFromFen(_bb.startFen,false,false,false);
this.board.setMoveSequence(_bb.movesseq,"NA",_bb.start_movenum,_bb.pgn_result);
var _bd=true;
var _be=-1;
if(_b5==_b7&&_ba){
_be=this.board.moveArray.length-1;
}
if(!Move.moveArraysEqual(_b8,this.board.moveArray)){
_bd=false;
}else{
var _bf=Move.findMoveInNewArray(_b8,this.board.moveArray,_b9);
if(_bf&&_bf.prev){
_be=_bf.prev.index;
}
}
this.board.displayPendingMoveList();
if(this.board.moveArray.length>0){
this.board.setCurrentMove(this.board.moveArray[0]);
}
if(_bd){
if(_be>0&&_be<this.board.moveArray.length){
if(clog){
console.log("going to currMoveIndex:"+_be);
}
this.board.gotoMoveIndex(_be,false,true);
}else{
}
}else{
if(_b6==-1){
var _c0=this.board.moveArray.length-1;
if(_c0>=0){
this.board.gotoMoveIndex(_c0,false,true);
}
}else{
if(_b6!=0){
this.board.gotoMoveIndex(_b6);
}
}
if(_b6!=-1&&this.board.autoplayFirst){
this.board.forwardMove();
}
}
this.board.displayMode=true;
var _c1=this.board.boardName;
var _c2=YAHOO.util.Dom.get(_c1+"-whitePlayer");
if(_c2){
_c2.innerHTML=_bb.whitePlayer;
}
var _c3=YAHOO.util.Dom.get(_c1+"-blackPlayer");
if(_c3){
_c3.innerHTML=_bb.blackPlayer;
}
var _c4=YAHOO.util.Dom.get(_c1+"-event");
if(_c4){
_c4.innerHTML=_bb.event;
}
var _c5=YAHOO.util.Dom.get(_c1+"-site");
if(_c5){
_c5.innerHTML=_bb.site;
}
var _c6=YAHOO.util.Dom.get(_c1+"-date");
if(_c6){
_c6.innerHTML=_bb.date;
}
var _c7=YAHOO.util.Dom.get(_c1+"-round");
if(_c7){
_c7.innerHTML=_bb.round;
}
var _c8=YAHOO.util.Dom.get(_c1+"-whiteElo");
if(_c8){
_c8.innerHTML=_bb.whitePlayerElo;
}
var _c9=YAHOO.util.Dom.get(_c1+"-blackElo");
if(_c9){
_c9.innerHTML=_bb.blackPlayerElo;
}
if(clog){
if(this.board.currentMove){
console.log("after show game currentMove:"+this.board.currentMove.output());
}else{
console.log("after show game currentMove is null");
}
}
};

var SITE_VERSION=1;
var clog=false;
var ctime=false;
var cprof=false;
var move_obj_id_counter=0;
var activeBoard=null;
var boardSounds=new CTSound({soundPath:"/sounds"});
YAHOO.util.Event.onDOMReady(function(){
boardSounds.createSound("takesounds/78263__SuGu14__Metall01","takePiece1");
boardSounds.createSound("movesounds/77971__SuGu14__Fusta_0_05","movePiece3");
boardSounds.createSound("movesounds/10537__batchku__Hit_knuckle_15_004","movePiece7");
});
function isMouseOver(_1,e){
var el=YAHOO.util.Dom.get(_1);
if(!el){
return false;
}
var _4=YAHOO.util.Dom.getRegion(el);
if(!_4){
return false;
}
var _5=_4.top;
var _6=_4.left;
var _7=_4.bottom;
var _8=_4.right;
var _9=YAHOO.util.Event.getXY(e);
var mX=_9[0];
var mY=_9[1];
var _c=(mX>_6&&mX<_8&&mY>_5&&mY<_7);
}
function trimStr(_d){
if(!_d){
return "";
}
var _d=_d.replace(/^\s\s*/,"");
var ws=/\s/;
var i=_d.length;
while(ws.test(_d.charAt(--i))){
}
return _d.slice(0,i+1);
}
BoardConfig=function(){
this.boardName="board";
this.puzzle=false;
this.showToMoveIndicators=false;
this.scrollVariations=false;
this.pgnString=null;
this.pgnDiv=null;
this.pgnFile=null;
this.scrollOffsetCorrection=0;
this.handleCommentClicks=false;
this.pollPGNMilliseconds=0;
this.pollPGNMillisecondsPostResult=30000;
this.numberPollsAfterResult=5;
this.gotoEndOnRefresh=false;
this.allowPreMoveSelection=false;
this.pieceSet="merida";
this.pieceSize=46;
this.isEndgame=false;
this.tr=false;
this.ie6FixCoordsOffsetSize=4;
this.allIeFixCoordsOffsetSize=0;
this.addVersion=true;
this.ml=9999;
this.r=false;
this.g=false;
this.g2=false;
this.canPasteFen=false;
this.makeActive=false;
this.avoidMouseoverActive=false;
this.autoScrollMoves=false;
this.moveAnimationLength=0.5;
this.showBracketsOnVariation=true;
this.hideBracketsOnTopLevelVariation=false;
this.variationStartString=" ( ";
this.variationEndString=" ) ";
this.ignoreCommentRegex=null;
this.newlineForEachMainMove=true;
this.useDivClearForNewline=false;
this.showNPS=false;
this.squareColorClass="";
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=false;
this.hidePGNErrors=false;
this.previewMode=false;
this.movesFormat="default";
this.boardImagePath="http://chesstempo.com";
this.showCoordinates=false;
this.highlightFromTo=false;
this.highlightValidSquares=false;
this.fideClock=false;
this.disableFlipper=false;
this.showResult=1;
this.showEvent=1;
this.showRound=1;
this.showSite=1;
this.showDate=1;
this.ignoreFlipping=false;
this.reverseFlip=false;
this.autoplayFirst=false;
this.dontOutputNavButtons=false;
this.dontCheckLeavingPage=false;
this.clickAndClick=false;
this.clickAndClickDisabled=false;
this.whiteMoveSoundName="movePiece3";
this.blackMoveSoundName="movePiece7";
this.whiteTakeSoundName="takePiece1";
this.blackTakeSoundName="takePiece1";
this.soundEnabled=false;
this.gamedb=false;
};
BoardConfig.prototype.applyConfig=function(_10){
for(var _11 in _10){
this[_11]=_10[_11];
}
};
ChessApp=function(_12){
this.displayMode=false;
this.config=_12;
this.board=null;
};
ChessApp.prototype.setDisplayMode=function(_13){
this.displayMode=_13;
};
ChessApp.prototype.setProblemNumber=function(_14,_15){
this.problemNumber=_14;
this.attId=_15;
};
ChessApp.prototype.init=function(e,_17,_18,us,_1a){
ChessPiece.init();
this.board=new Board(this.config.boardName);
if(_1a){
this.board.addUpdatePieceListener(us);
}
this.board.moveArray=new Array();
if(!this.hideOnInit){
YAHOO.util.Dom.setStyle(this.config.boardName+"-container","display","block");
YAHOO.util.Dom.setStyle("toPlaySpan","display","inline");
}
this.tactics=(this.displayMode||this.config.pgnMode||this.config.previewMode||this.config.fenBoard)?null:new TacticsUI(this.board);
this.problem=(this.config.pgnMode||this.config.previewMode||this.config.fenBoard)?null:new ProblemUI(this.board,this.tactics);
this.board.tactics=this.tactics;
this.board.problem=this.problem;
this.board.puzzle=this.config.puzzle;
if(this.problem){
this.problem.autoPlayOpponent=1;
}
this.pgn=(this.config.pgnMode)?new PGN(this.board):null;
var _1b=MovesDisplay.DEFAULT_DISPLAY_TYPE;
if(this.config.movesFormat=="main_on_own_line"){
_1b=MovesDisplay.MAIN_ON_OWN_LINE;
}
this.movesDisplay=new MovesDisplay(this.board,_1b);
this.movesDisplay.variationOnOwnLine=this.config.variationOnOwnLine;
this.board.movesDisplay=this.movesDisplay;
this.board.boardImagePath=this.config.boardImagePath;
this.board.showNPS=this.config.showNPS;
this.board.squareColorClass=this.config.squareColorClass;
this.board.tr=this.config.tr;
this.board.scrollToBoardTop=this.config.scrollToBoardTop;
this.board.ml=this.config.ml;
this.board.r=this.config.r;
this.board.g=this.config.g;
this.board.g2=this.config.g2;
this.board.canPasteFen=this.config.canPasteFen;
this.board.addVersion=this.config.addVersion;
this.board.ie6FixCoordsOffsetSize=this.config.ie6FixCoordsOffsetSize;
this.board.allIeFixCoordsOffsetSize=this.config.allIeFixCoordsOffsetSize;
this.board.allowingFreeMovement=this.config.allowingFreeMovement;
this.board.autoScrollMoves=this.config.autoScrollMoves;
this.board.moveAnimationLength=this.config.moveAnimationLength;
this.board.showBracketsOnVariation=this.config.showBracketsOnVariation;
this.board.hideBracketsOnTopLevelVariation=this.config.hideBracketsOnTopLevelVariation;
this.board.variationStartString=this.config.variationStartString;
this.board.variationEndString=this.config.variationEndString;
this.board.ignoreCommentRegex=this.config.ignoreCommentRegex;
this.board.newlineForEachMainMove=this.config.newlineForEachMainMove;
this.board.useDivClearForNewline=this.config.useDivClearForNewline;
this.board.pieceSize=this.config.pieceSize;
this.board.showToMoveIndicators=this.config.showToMoveIndicators;
this.board.handleCommentClicks=this.config.handleCommentClicks;
this.board.scrollOffsetCorrection=this.config.scrollOffsetCorrection;
this.board.pollPGNMilliseconds=this.config.pollPGNMilliseconds;
this.board.pollPGNMillisecondsPostResult=this.config.pollPGNMillisecondsPostResult;
this.board.numberPollsAfterResult=this.config.numberPollsAfterResult;
this.board.gotoEndOnRefresh=this.config.gotoEndOnRefresh;
this.board.allowPreMoveSelection=this.config.allowPreMoveSelection;
this.board.pieceTakenSize=this.config.pieceTakenSize;
this.board.pieceSet=this.config.pieceSet;
this.board.pauseBetweenMoves=this.config.pauseBetweenMoves;
this.board.showCoordinates=this.config.showCoordinates;
this.board.highlightFromTo=this.config.highlightFromTo;
this.board.highlightValidSquares=this.config.highlightValidSquares;
this.board.fideClock=this.config.fideClock;
this.board.disableFlipper=this.config.disableFlipper;
this.board.showDate=this.config.showDate;
this.board.showEvent=this.config.showEvent;
this.board.showGame=this.config.showGame;
this.board.showResult=this.config.showResult;
this.board.showRound=this.config.showRound;
this.board.showSite=this.config.showSite;
this.board.ignoreFlipping=this.config.ignoreFlipping;
this.board.reverseFlip=this.config.reverseFlip;
this.board.autoplayFirst=this.config.autoplayFirst;
this.board.scrollVariations=this.config.scrollVariations;
this.board.dontOutputNavButtons=this.config.dontOutputNavButtons;
this.board.clickAndClick=this.config.clickAndClick;
this.board.clickAndClickDisabled=this.config.clickAndClickDisabled;
this.board.avoidMouseoverActive=this.config.avoidMouseoverActive;
this.board.dontCheckLeavingPage=this.config.dontCheckLeavingPage;
this.board.whiteMoveSoundName=this.config.whiteMoveSoundName;
this.board.whiteTakeSoundName=this.config.whiteTakeSoundName;
this.board.blackMoveSoundName=this.config.blackMoveSoundName;
this.board.blackTakeSoundName=this.config.blackTakeSoundName;
this.board.soundEnabled=this.config.soundEnabled;
this.board.hidePGNErrors=this.config.hidePGNErrors;
this.board.gamedb=this.config.gamedb;
if(this.config.makeActive){
activeBoard=this.board;
}
if(this.problem){
this.problem.isEndgame=this.config.isEndgame;
}
if(!this.board.puzzle&&typeof loginManager!="undefined"){
if(this.tactics){
loginManager.setLoginCallback(this.tactics.loginCallback,this.tactics);
loginManager.setLogoutCallback(this.tactics.logoutCallback,this.tactics);
}
if(this.problem){
loginManager.setSessionCallback(this.problem.sessionCallback,this.problem);
}
}
YAHOO.util.DragDropMgr.clickTimeThresh=50;
YAHOO.util.DragDropMgr.clickPixelThresh=1;
this.board.createBoardUI();
if(!this.board.puzzle){
if(this.problem){
this.problem.createProblemUI();
}
if(this.tactics){
this.tactics.initProblemCompleteOverlay();
}
if(this.problem){
this.problem.initLoadingOverlay();
}
if(this.config.pgnMode){
if(this.config.pgnFile){
this.pgn.getPGNFromURL(this.config.pgnFile,this.config.gotoEndOnRefresh);
if(this.config.pollPGNMilliseconds){
this.pgn.foundResult=false;
this.pgn.foundResultPolls=0;
this.pgn.pollPGNFromURL(this.config.pgnFile,this.config.gotoEndOnRefresh,this.config.pollPGNMilliseconds);
}
}else{
if(this.config.pgnString){
this.pgn.setupFromPGN(this.config.pgnString);
}else{
if(this.config.pgnDiv){
var _1c=YAHOO.util.Dom.get(this.config.pgnDiv);
if(_1c){
this.pgn.setupFromPGN(_1c.innerHTML);
}
}
}
}
}else{
if(!this.board.dontCheckLeavingPage&&this.tactics){
YAHOO.util.Event.addListener(window,"beforeunload",this.tactics.checkLeavingPage,this.tactics,true);
YAHOO.util.Event.addListener(window,"unload",this.tactics.leavingPage,this.tactics,true);
this.tactics.updateSessionDisplay(0,0);
if(typeof showingStart!="undefined"&&showingStart){
var _1d=this;
var _1e="";
if(loggedIn){
if(this.config.isEndgame){
_1e=_js("Endgame Problem Set")+": <span id=\"startProblemSetStr\">"+_js(startEndgameSetName)+"</span>";
}else{
_1e=_js("Tactics Problem Set")+": <span id=\"startProblemSetStr\">"+_js(startTacticsSetName)+"</span>";
}
}
this.board.preloadPieces();
var _1f=new YAHOO.widget.SimpleDialog("starttacticdialog1",{width:"300px",fixedcenter:true,modal:false,visible:true,draggable:true,close:false,text:"<div style=\"color:black\">"+_1e+"</div><br/>"+"<div style=\"color:black\">"+_js("Click start to begin solving problems")+"</div>",icon:YAHOO.widget.SimpleDialog.ICON_INFO,constraintoviewport:true,buttons:[{text:_js("Start"),handler:function(){
if(_1d.board.imagesLoaded){
this.hide();
_1d.problem.getProblem();
}else{
alert(_js("Still trying to load piece images.\n If you keep receiving this message you may need to reload the page."));
}
},isDefault:true}]});
var _20=YAHOO.util.Dom.get("ctb-"+this.board.boardName);
_1f.render(document.body);
}else{
this.problem.getProblem();
}
}else{
if(this.problem){
if(this.problemNumber!=""){
YAHOO.util.Dom.setStyle("boardandmoves","display","block");
this.problem.getProblem(this.problemNumber,this.attId);
}
}
}
}
}
this.board.setupEventHandlers();
if(this.problem){
this.problem.setupEventHandlers();
}
if(this.tactics){
this.tactics.setupEventHandlers();
}
if(this.board.scrollToBoardTop){
var xy=YAHOO.util.Dom.getXY(this.board.boardName+"-boardBorder");
window.scrollTo(xy[0],xy[1]);
}
if(this.config.flipListener){
this.board.addFlipListener(this.config.flipListener);
}
};
function clearClone(o){
if(o==null){
return;
}
for(prop in o){
if(typeof (o[prop])=="object"&&o[prop]!=null&&o[prop].alreadyCloned){
o[prop].alreadyCloned=false;
clearClone(o[prop]);
}
}
}
function cloneWork(o){
if(o==null){
return null;
}
var _24=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_24[prop]=o[prop];
}else{
_24[prop]=o[prop];
}
}
return _24;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_26,_27,_28,_29,_2a){
var _2b=".vers"+SITE_VERSION;
if(!_2a){
_2b="";
}
if(check_bad_msie()){
return _27+"/images/"+_28+"/"+_26+_29+_2b+".png";
}else{
return _27+"/images/"+_28+"/"+_26+_29+_2b+".png";
}
};
check_bad_msie=function(){
var _2c=(window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
return _2c;
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _2e=(img.id)?"id='"+img.id+"' ":"";
var _2f=(img.className)?"class='"+img.className+"' ":"";
var _30=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _31="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_31="float:left;"+_31;
}
if(img.align=="right"){
_31="float:right;"+_31;
}
if(img.parentElement.href){
_31="cursor:hand;"+_31;
}
var _32="<span "+_2e+_2f+_30+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_31+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_32;
};
Move=function(_33,_34,_35,_36,_37,_38,_39){
this.fromColumn=_33;
this.fromRow=_34;
this.toColumn=_35;
this.toRow=_36;
this.take=_37;
this.promotion=_38;
this.moveString=_39;
this.prev=null;
this.next=null;
this.numVars=0;
this.prevMoveEnpassant=false;
this.ravLevel=0;
this.atEnd=false;
this.obj_id=move_obj_id_counter++;
this.beforeComment="";
this.afterComment="";
};
Move.prototype.freeMove=function(){
if(this.taken){
this.taken=null;
}
if(this.vars&&this.vars.length>0){
var i=0;
for(var i=0;i<this.vars.length;i++){
this.vars[i].freeMove();
}
}
};
Move.prototype.clone=function(_3b){
var _3c=this.take;
if(_3b&&_3c){
_3c=_3c.makeLightWeight();
}
var _3d=new Move(this.fromColumn,this.fromRow,this.toColumn,this.toRow,_3c,this.promotion,this.moveString);
_3d.moveNum=this.moveNum;
_3d.atEnd=this.atEnd;
_3d.beforeComment=this.beforeComment;
_3d.afterComment=this.afterComment;
_3d.prevMoveEnpassant=this.prevMoveEnpassant;
if(this.vars){
_3d.vars=[];
var cnt=0;
for(var i=0;i<this.vars.length;i++){
_3d.vars[i]=this.vars[i].clone(_3b);
cnt++;
}
_3d.numVars=cnt;
}
return _3d;
};
Move.columnToChar=function(col){
var a=String.fromCharCode("a".charCodeAt(0)+col);
return a;
};
Move.prototype.output=function(){
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+":"+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+" prom:"+this.promotion+" objid:"+this.obj_id+" dummy:"+this.dummy+" endNode:"+this.endNode+" index:"+this.index+" moveNum:"+this.moveNum+" atEnd:"+this.atEnd+" beforeCom:"+this.beforeComment+" afterCom:"+this.afterComment;
};
Move.prototype.equals=function(m){
return (m&&(this.fromColumn==m.fromColumn&&this.fromRow==m.fromRow&&this.promotion==m.promotion&&this.toColumn==m.toColumn&&this.toRow==m.toRow));
};
Move.moveArraysEqual=function(a1,a2){
if(a1==a2){
return true;
}
if(a1==null||a2==null){
return false;
}
if(a1.length!=a2.length){
return false;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return false;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return false;
}
}
return true;
};
Move.findMoveInNewArray=function(a1,a2,_48){
if(a1==a2){
return _48;
}
if(a1==null||a2==null){
return null;
}
if(a1.length!=a2.length){
return null;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return null;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return null;
}
if(a1[i]==_48){
return a2[i];
}
}
return null;
};
Move.prototype.toMoveString=function(){
var _4a="";
if(this.promotion){
_4a=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_4a;
};
function getTagValue(_4b,_4c){
var _4d=_4b.getElementsByTagName(_4c);
if(_4d==null){
YAHOO.log("got null node for tag:"+_4c);
return null;
}
if(_4d.length==0){
YAHOO.log("got empty array node for tag:"+_4c);
return null;
}
if(_4d[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_4c);
return null;
}
if(_4d[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_4c);
return null;
}
if(typeof (_4d[0].textContent)!="undefined"){
return _4d[0].textContent;
}
return _4d[0].firstChild.nodeValue;
}
var ua=navigator.userAgent.toLowerCase();
var isOpera=(ua.indexOf("opera")>-1);
var isIphone=(navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i));
var isIpad=(navigator.userAgent.match(/iPad/i));
var isSafari=(ua.indexOf("safari")>-1);
var isGecko=(!isOpera&&!isSafari&&ua.indexOf("gecko")>-1);
var isIE=(!isOpera&&ua.indexOf("msie")>-1);
function unescapeHtml(s){
var n=document.createElement("div");
n.innerHTML=s;
if(n.innerText){
return n.innerText;
}else{
return n.textContent;
}
}
ChessPiece=function(div,_51,_52,_53){
var id=div.id;
this.board=_53;
this.icon=get_image_str(ChessPiece.pieceIconNames[_51][_52],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_51;
this.piece=_52;
this.id=id;
this.div=div;
var _55=_53.getPieceDragDiv();
var _56=false;
var _57="";
if(_55==null){
_55=document.createElement("div");
_55.id="pieceDragDiv";
_56=true;
YAHOO.util.Dom.setStyle(_55,"visibility","hidden");
YAHOO.util.Dom.setStyle(_55,"border","0px");
YAHOO.util.Dom.setStyle(_55,"position","absolute");
}
this.pieceDragEl=_55;
this.pieceDragElId="pieceDragDiv";
if(_56){
var _58=this.board.getDocBody();
if(_58){
_58.appendChild(_55);
}
}
if(YAHOO.util.Event.isIE||isOpera){
var _59=this.div;
_59.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_59.firstChild;
fix_ie_png(img);
}else{
YAHOO.util.Dom.setStyle([this.div],"backgroundImage","url("+this.icon+")");
}
YAHOO.util.Dom.setStyle([this.div],"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"width",this.board.pieceSize+"px");
if(isIphone||isIpad){
if(!this.board.clickAndClick){
initIphone(this.div);
}
}
YAHOO.util.Dom.setStyle([this.div],"position","relative");
if(!this.board.clickAndClick){
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:true,centerFrame:false,isTarget:false});
this.initFrame();
}
};
ChessPiece.prototype=new YAHOO.util.DDProxy();
ChessPiece.PAWN=0;
ChessPiece.BISHOP=1;
ChessPiece.KNIGHT=2;
ChessPiece.ROOK=3;
ChessPiece.KING=4;
ChessPiece.QUEEN=5;
ChessPiece.WHITE=0;
ChessPiece.BLACK=1;
ChessPiece.init=function(){
ChessPiece.pieceIconNames=new Array(2);
ChessPiece.pieceIconNames[0]=new Array(6);
ChessPiece.pieceIconNames[1]=new Array(6);
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.PAWN]="whitepawn";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.BISHOP]="whitebishop";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.KNIGHT]="whiteknight";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.ROOK]="whiterook";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.KING]="whiteking";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.QUEEN]="whitequeen";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.PAWN]="blackpawn";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.BISHOP]="blackbishop";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.KNIGHT]="blackknight";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.ROOK]="blackrook";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.KING]="blackking";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.QUEEN]="blackqueen";
};
ChessPiece.materialValue=function(_5b){
switch(_5b){
case ChessPiece.PAWN:
return 1;
break;
case ChessPiece.BISHOP:
return 3;
break;
case ChessPiece.KNIGHT:
return 3;
break;
case ChessPiece.ROOK:
return 5;
break;
case ChessPiece.KING:
return 0;
break;
case ChessPiece.QUEEN:
return 9;
break;
}
return 0;
};
ChessPiece.prototype.free=function(){
if(!this.board.clickAndClick){
this.unreg();
}
};
ChessPiece.prototype.clickValidator=function(e){
if(this.board.dragDisabled){
return false;
}
if(!this.board.allowPreMoveSelection&&(this.board.toMove!=this.colour)){
return false;
}
if(this.board.restrictedColourMovement!=-1&&this.colour!=this.board.restrictedColourMovement){
return;
}
if(false&&this.board.clickAndClick){
return false;
}
var _5d=YAHOO.util.Event.getTarget(e);
var _5e=(this.isValidHandleChild(_5d)&&(this.id==this.handleElId||this.DDM.handleWasClicked(_5d,this.id)));
this.board.selectDestSquare(e);
if(true||!_5e){
YAHOO.util.Event.preventDefault(e);
}
return _5e;
};
ChessPiece.prototype.onDragOut=function(e,id){
this.insideBoard=false;
};
ChessPiece.prototype.onDragEnter=function(e,id){
this.insideBoard=true;
};
ChessPiece.prototype.endDrag=function(e){
if(this.board.lastOverSquare){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
}
this.board.lastOverSquare=null;
if(!this.insideBoard){
this.board.board_xy=null;
this.setPosition(this.column,this.row,false,null,this.board.moveAnimationLength);
}
if(!this.hideAfterDragEnd){
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","visible");
}else{
this.hideAfterDragEnd=false;
}
};
ChessPiece.prototype.startDrag=function(x,y){
this.insideBoard=true;
var _66=null;
if(this.board.currentMove){
if(this.board.currentMove.prev){
_66=this.board.currentMove.prev;
}else{
_66=this.board.prev_move;
}
}else{
_66=this.board.prev_move;
}
if(this.board.highlightValidSquares){
this.candidates=null;
this.candidates=new Array(8);
for(var i=0;i<8;i++){
this.candidates[i]=new Array(8);
for(var j=0;j<8;j++){
this.candidates[i][j]=false;
}
}
}
this.pieceDragEl.innerHTML="<img src=\""+this.icon+"\"/>";
var img=this.pieceDragEl.firstChild;
fix_ie_png(img);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"zIndex",1000);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.pieceDragEl,"width",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","hidden");
if(this.board.highlightValidSquares){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _6a=7-i;
var _6b=j;
if(this.board.isFlipped){
_6a=7-_6a;
_6b=7-_6b;
}
if((_6a==this.row&&_6b==this.column)||this.board.canMove(this.makeLightWeight(),_6b,_6a,_66,true)){
this.candidates[j][i]=true;
}
}
}
}
};
ChessPiece.prototype.onDragOver=function(e,id){
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _70=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _71=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_70)/this.board.pieceSize);
var r=parseInt((y-_71)/this.board.pieceSize);
var _74=this.board.boardName+"-s"+c+""+(7-r);
var _75=YAHOO.util.Dom.get(_74);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_75){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
this.board.lastOverSquare=null;
if(this.candidates&&c<8&&c>=0&&r<8&&r>=0&&this.candidates[c][r]){
YAHOO.util.Dom.addClass(_75,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_75,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_75;
}
};
ChessPiece.prototype.onDragDrop=function(e,id){
if(this.board.blockFowardBack||this.board.deferredBlockForwardBack){
return false;
}
if(this.board.allowPreMoveSelection&&this.board.toMove!=this.colour){
return false;
}
if(this.board.lastOverSquare){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
}
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _7a=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _7b=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_7a)/this.board.pieceSize);
var r=parseInt((y-_7b)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
if(this.board.allowPreMoveSelection&&(this.board.boardPieces[this.column][this.row]!=this)){
this.setVisible(false);
this.hideAfterDragEnd=true;
return false;
}
var _7e=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_7e=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_7e&&this.board.currentMove&&!this.board.allowingFreeMovement&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
ChessPiece.prototype.makeLightWeight=function(){
var cp=this.board.createPiece(this.colour,this.piece,true);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
ChessPiece.prototype.removeFromParent=function(){
var _80=this.div;
if(_80.parentNode){
_80.parentNode.removeChild(_80);
}
};
ChessPiece.prototype.setVisible=function(_81){
var _82;
var _83;
if(_81){
_83="block";
_82="visible";
}else{
_83="none";
_82="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_82);
};
ChessPiece.prototype.moveResponse=function(o){
};
ChessPiece.prototype.getIcon=function(){
return this.icon;
};
ChessPiece.prototype.makeHeavyWeight=function(){
return this.copyPiece();
};
ChessPiece.prototype.copyPiece=function(){
var cp=new ChessPiece(this.div,this.colour,this.piece,this.board);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
ChessPiece.prototype.changePieceKeepImage=function(_86){
var _87=(_86+"").toLowerCase().charAt(0);
switch(_87){
case "k":
this.piece=ChessPiece.KING;
break;
case "q":
this.piece=ChessPiece.QUEEN;
break;
case "r":
this.piece=ChessPiece.ROOK;
break;
case "b":
this.piece=ChessPiece.BISHOP;
break;
case "n":
this.piece=ChessPiece.KNIGHT;
break;
case "p":
this.piece=ChessPiece.PAWN;
break;
default:
}
};
ChessPiece.prototype.changePiece=function(_88){
this.changePieceKeepImage(_88);
this.icon=get_image_str(ChessPiece.pieceIconNames[this.colour][this.piece],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
if(YAHOO.util.Event.isIE||isOpera){
var _89=this.div;
_89.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_89.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle(this.div,"backgroundImage","url("+this.icon+")");
YAHOO.util.Dom.setStyle(this.div,"background-repeat","no-repeat");
}
};
ChessPiece.prototype.getNewXYPosition=function(_8b,row){
var _8d=this.board.getBoardDiv();
var _8e=this.board.getXY();
var _8f=_8e[0];
var _90=_8e[1];
var _91=[0,0];
if(this.board.isFlipped){
_91[0]=_8f+((7-_8b)*this.board.pieceSize);
_91[1]=_90+((row)*this.board.pieceSize);
}else{
_91[0]=_8f+((_8b)*this.board.pieceSize);
_91[1]=_90+((7-row)*this.board.pieceSize);
}
return _91;
};
ChessPiece.prototype.setPosition=function(_92,row,_94,_95,_96,_97,_98){
this.column=_92;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _99=this.div;
var _9a=null;
if(this.board.isFlipped){
_9a=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_9a=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _9b=this.board.getBoardDivFromId(_9a);
var _9c=null;
if(!_97){
_9c=(this.colour==ChessPiece.WHITE)?this.board.whiteMoveSoundName:this.board.blackMoveSoundName;
}else{
_9c=(this.colour==ChessPiece.WHITE)?this.board.whiteTakeSoundName:this.board.blackTakeSoundName;
}
if(!_94){
if(!this.board.settingUpPosition){
var _9d=this.getNewXYPosition(_92,row);
YAHOO.util.Dom.setXY(_99,_9d,false);
}else{
if(_99.parentNode){
_99.parentNode.removeChild(_99);
}
_9b.appendChild(_99);
}
this.setVisible(true);
if(_98&&this.board.soundEnabled){
boardSounds.playSound(_9c);
}
if(_95){
_95();
}
}else{
var _9d=this.getNewXYPosition(_92,row);
if(this.board.oldAnim&&this.board.oldAnim.isAnimated()){
this.board.oldAnim.stop();
YAHOO.util.Dom.setXY(this.board.oldAnimPieceDiv,this.board.old_new_xy,false);
}
var _9e=new YAHOO.util.Motion(_99,{points:{to:_9d}});
this.board.oldAnim=_9e;
this.board.oldAnimPieceDiv=_99;
this.board.old_new_xy=_9d;
_9e.duration=_96;
var _9f=this;
_9e.onComplete.subscribe(function(){
if(_9f.board.soundEnabled){
boardSounds.playSound(_9c);
}
});
if(_95){
_9e.onComplete.subscribe(_95);
}
_9e.animate();
}
};
ChessPiece.prototype.getFenLetter=function(){
var _a0=ChessPiece.pieceTypeToChar(this.piece)+"";
if(this.colour!=ChessPiece.WHITE){
_a0=_a0.toLowerCase();
}
return _a0;
};
ChessPiece.pieceTypeToChar=function(_a1){
switch(_a1){
case ChessPiece.KING:
return "K";
case ChessPiece.QUEEN:
return "Q";
case ChessPiece.ROOK:
return "R";
case ChessPiece.BISHOP:
return "B";
case ChessPiece.KNIGHT:
return "N";
case ChessPiece.PAWN:
return "P";
}
return "?";
};
LightweightChessPiece=function(div,_a3,_a4,_a5){
this.board=_a5;
this.colour=_a3;
this.piece=_a4;
this.div=div;
};
LightweightChessPiece.prototype.getFenLetter=ChessPiece.prototype.getFenLetter;
LightweightChessPiece.prototype.makeLightWeight=function(){
return this.copyPiece();
};
LightweightChessPiece.prototype.makeHeavyWeight=function(){
var cp=this.board.createPiece(this.colour,this.piece,false);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
LightweightChessPiece.prototype.setVisible=function(_a7){
};
LightweightChessPiece.prototype.free=function(){
};
LightweightChessPiece.prototype.setPosition=function(_a8,row,_aa,_ab,_ac){
this.column=_a8;
this.row=row;
};
LightweightChessPiece.prototype.copyPiece=function(){
var cp=new LightweightChessPiece(this.id,this.colour,this.piece,this.board);
cp.column=this.column;
cp.row=this.row;
return cp;
};
LightweightChessPiece.prototype.changePiece=function(_ae){
this.changePieceKeepImage(_ae);
};
LightweightChessPiece.prototype.changePieceKeepImage=function(_af){
var _b0=(_af+"").toLowerCase().charAt(0);
switch(_b0){
case "k":
this.piece=ChessPiece.KING;
break;
case "q":
this.piece=ChessPiece.QUEEN;
break;
case "r":
this.piece=ChessPiece.ROOK;
break;
case "b":
this.piece=ChessPiece.BISHOP;
break;
case "n":
this.piece=ChessPiece.KNIGHT;
break;
case "p":
this.piece=ChessPiece.PAWN;
break;
default:
}
};
MovesDisplay=function(_b1,_b2){
this.board=_b1;
this.displayType=_b2;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_b3){
this.boardName=_b3;
if(_b3){
this.initTarget("ctb-"+_b3,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.imagesLoaded=false;
this.disableNavigation=false;
this.currentMove=null;
this.moveIndex=-1;
this.restrictedColourMovement=-1;
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
this.isUserFlipped=false;
this.registeredFlipListeners=[];
this.registeredForwardAtEndListeners=[];
this.registeredPasteFenClickedListeners=[];
this.registeredGotoMoveIndexListeners=[];
this.registeredBackMovePreCurrentListeners=[];
this.registeredForwardMovePostUpdateListeners=[];
this.registeredUpdateListeners=[];
this.registeredUpdatePieceFinishedListeners=[];
this.registeredUpdateEndOfMovesListeners=[];
this.registeredUpdateHaveAltListeners=[];
this.registeredUpdateWrongMoveListeners=[];
this.registeredUpdateAllowMoveListeners=[];
this.moveNumber=1;
this.halfMoveNumber=0;
};
Board.prototype=new YAHOO.util.DDTarget();
Board.invertToMove=function(_b4){
if(_b4==ChessPiece.WHITE){
return ChessPiece.BLACK;
}else{
return ChessPiece.WHITE;
}
};
Board.boardStyleToClassName=function(_b5){
var _b6="";
switch(_b5){
case 0:
_b6="-lightgrey";
break;
case 1:
_b6="-grey";
break;
case 2:
_b6="-brown";
break;
case 3:
_b6="-green";
break;
case 4:
_b6="-woodlight";
break;
case 5:
_b6="-wooddark";
break;
case 6:
_b6="-metal";
break;
case 7:
_b6="-marblebrown";
break;
case 8:
_b6="-stucco";
break;
case 9:
_b6="-goldsilver";
break;
case 10:
_b6="-sandsnow";
break;
case 11:
_b6="-crackedstone";
break;
case 12:
_b6="-granite";
break;
case 13:
_b6="-marblegreen";
break;
case 14:
_b6="-greenwhite";
break;
default:
}
return _b6;
};
Board.createBoardArray=function(){
var _b7=boardPool.getObject();
if(_b7==null){
_b7=new Array(8);
for(var i=0;i<8;i++){
_b7[i]=new Array(8);
}
}
return _b7;
};
Board.prototype.preloadPieces=function(){
var _b9=[];
for(var i=0;i<ChessPiece.QUEEN;i++){
for(var j=0;j<2;j++){
var _bc=get_image_str(ChessPiece.pieceIconNames[j][i],this.boardImagePath,this.pieceSet,this.pieceSize,true);
_b9.push(_bc);
}
}
var _bd=this;
function checkImages(){
var _be=true;
for(var i=0;i<_b9.length;i++){
var img=document.createElement("img");
img.src=_b9[i];
if(!img.complete||(typeof img.naturalWidth!="undefined"&&img.naturalWidth==0)){
_be=false;
}
}
if(!_be){
setTimeout(checkImages,1000);
}else{
_bd.imagesLoaded=true;
}
}
checkImages();
};
Board.prototype.selectDestSquare=function(e){
if(this.clickAndClickDisabled){
return true;
}
var _c2=(new Date()).getTime();
var _c3=false;
if(_c2-this.lastDestClick<100){
_c3=true;
}
this.lastDestClick=_c2;
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _c6=YAHOO.util.Dom.getX("ctb-"+this.boardName);
var _c7=YAHOO.util.Dom.getY("ctb-"+this.boardName);
var c=parseInt((x-_c6)/this.pieceSize);
var r=parseInt((y-_c7)/this.pieceSize);
var _ca=this.boardName+"-s"+c+""+(7-r);
var _cb=YAHOO.util.Dom.get(_ca);
if(_cb==this.oldSelectedSquare){
if(!_c3){
YAHOO.util.Dom.removeClass(_cb,"ct-source-square");
this.oldSelectedSquare=null;
this.oldSelectedPiece=null;
if(this.oldDestSquare){
YAHOO.util.Dom.removeClass(this.oldDestSquare,"ct-dest-square");
this.oldDestSquare=null;
}
}
return true;
}
if(this.isFlipped){
c=7-c;
r=7-r;
}
r=7-r;
var _cc=this.boardPieces[c][r];
if(_cc&&(_cc.colour==this.toMove||this.allowPreMoveSelection)&&(this.restrictedColourMovement==-1||(_cc.colour==this.restrictedColourMovement))){
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
}
if(this.oldDestSquare){
YAHOO.util.Dom.removeClass(this.oldDestSquare,"ct-dest-square");
this.oldDestSquare=null;
}
YAHOO.util.Dom.addClass(_cb,"ct-source-square");
this.oldSelectedSquare=_cb;
this.oldSelectedPiece=_cc;
}else{
if(this.oldSelectedSquare){
if(this.oldSelectedPiece&&this.oldSelectedPiece.colour!=this.toMove){
return false;
}
var _cd=null;
if(this.currentMove){
if(this.currentMove.prev){
_cd=this.currentMove.prev;
}else{
_cd=this.prev_move;
}
}else{
_cd=this.prev_move;
}
if(this.canMove(this.oldSelectedPiece.makeLightWeight(),c,r,_cd,true)){
this.lastDestSquare=_cb;
this.lastDestRow=r;
this.lastDestColumn=c;
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
var _ce=false;
if(!this.currentMove||this.currentMove.atEnd){
_ce=true;
}
this.updatePiece(this.oldSelectedPiece,c,r,false,false,true);
this.oldSelectedPiece=null;
this.oldSelectedSquare=null;
if(!_ce&&this.currentMove&&!this.allowingFreeMovement&&this.currentMove.atEnd){
this.toggleToMove();
this.updateToPlay();
}
}else{
}
}else{
return true;
}
}
};
Board.prototype.selectSourcePiece=function(_cf){
if(this.lastSourceSquare){
YAHOO.util.Dom.removeClass(_d0,"ct-source-square");
}
var r=_cf.row;
var c=_cf.column;
if(this.isFlipped){
r=7-r;
c=7-c;
}
var _d3=this.boardName+"-s"+c+""+r;
var _d0=YAHOO.util.Dom.get(_d3);
YAHOO.util.Dom.addClass(_d0,"ct-source-square");
this.lastSourceSquare=_d0;
this.lastSourcePiece=_cf;
this.lastSourceRow=_cf.row;
this.lastSourceColumn=_cf.column;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _d4=this.getBoardDiv();
if(this.pieces){
for(var i=0;i<32;i++){
if(this.pieces[i]){
this.pieces[i].setVisible(false);
this.pieces[i].free();
this.pieces[i]=null;
}
}
}
if(this.availPieceDivs){
for(var i=0;i<32;i++){
if(this.availPieceDivs[i]){
if(this.availPieceDivs[i].parentNode){
this.availPieceDivs[i].parentNode.removeChild(this.availPieceDivs[i]);
}
}
}
}
this.availids=null;
this.availIds=new Array(32);
this.availPieceDivs=null;
this.availPieceDivs=new Array(32);
this.pieces=null;
this.pieces=new Array(32);
this.uptoId=0;
this.uptoPiece=0;
};
Board.prototype.getXY=function(){
if(true||!this.board_xy){
this.board_xy=YAHOO.util.Dom.getXY("ctb-"+this.boardName);
}
return this.board_xy;
};
Board.prototype.updateFromTo=function(_d6,_d7,_d8,_d9,_da,_db){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_d8==null){
return;
}
this.lastFromSquare=_d6;
this.lastToSquare=_d7;
this.lastFromRow=_d8;
this.lastFromColumn=_d9;
this.lastToRow=_da;
this.lastToColumn=_db;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_d6,"ct-from-square");
YAHOO.util.Dom.addClass(_d7,"ct-to-square");
}
};
Board.prototype.makeMove=function(_dc,_dd,_de,_df,_e0,_e1,_e2,_e3,_e4){
var _e5;
var _e6;
if(!this.isFlipped){
_e5=YAHOO.util.Dom.get(this.boardName+"-s"+_dc.fromColumn+""+_dc.fromRow);
_e6=YAHOO.util.Dom.get(this.boardName+"-s"+_dc.toColumn+""+_dc.toRow);
}else{
_e5=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_dc.fromColumn)+""+(7-_dc.fromRow));
_e6=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_dc.toColumn)+""+(7-_dc.toRow));
}
if(this.oldSelectedSquare){
if(!this.allowPreMoveSelection||(this.oldSelectedPiece&&_dd&&(this.oldSelectedPiece.colour==_dd.colour))){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
this.oldSelectedSquare=null;
this.oldSelectedPiece=null;
}
}
if(_e1){
this.updateFromTo(_e5,_e6,_dc.fromRow,_dc.fromColumn,_dc.toRow,_dc.toColumn);
}
var _e7=this.boardPieces[_dc.toColumn][_dc.toRow];
if(_e7!=null){
_e7.enPassant=false;
_e7.castled=false;
}
if(_dd.piece==ChessPiece.PAWN&&_dc.toColumn!=_dc.fromColumn&&this.boardPieces[_dc.toColumn][_dc.toRow]==null){
_e7=this.boardPieces[_dc.toColumn][_dc.fromRow];
this.boardPieces[_dc.toColumn][_dc.fromRow]=null;
if(_e7!=null){
_e7.enPassant=true;
}
}
var _e8=null;
if(_dd.piece==ChessPiece.KING&&Math.abs(_dc.toColumn-_dc.fromColumn)>1){
var _e9;
var _ea;
if(_dc.toColumn>_dc.fromColumn){
_e8=this.boardPieces[7][_dc.fromRow];
_e9=_dc.fromRow;
_ea=5;
this.boardPieces[7][_dc.toRow]=null;
}else{
_e8=this.boardPieces[0][_dc.fromRow];
_e9=_dc.fromRow;
_ea=3;
this.boardPieces[0][_dc.toRow]=null;
}
if(!_e8){
alert("No castle piece");
}else{
_e8.setPosition(_ea,_e9,_de,null,_df,null,_e4);
this.boardPieces[_e8.column][_e8.row]=_e8;
_e8.castled=true;
}
}
_dc.taken=_e7;
if(_e7&&_e0){
this.processTaken(_e7,true);
}
this.moveNumber++;
_dc.preHalfMoveNumber=this.halfMoveNumber;
this.halfMoveNumber++;
if(_e7||_dd.piece==ChessPiece.PAWN){
this.halfMoveNumber=0;
}
this.board_xy=null;
if(_dc.promotion!=null){
_dd.changePieceKeepImage(_dc.promotion);
}
_dd.setPosition(_dc.toColumn,_dc.toRow,_de,function(){
var tp=_e7;
if(tp){
tp.setVisible(false);
}
if(_dc.promotion!=null){
_dd.changePiece(_dc.promotion);
}
if(_e2){
_e2.call(_e3);
}
},_df,_e7,_e4);
if(!_de){
if(_dc.promotion!=null){
_dd.changePiece(_dc.promotion);
}
}
this.boardPieces[_dc.fromColumn][_dc.fromRow]=null;
this.boardPieces[_dc.toColumn][_dc.toRow]=_dd;
if(_e8!=null){
_dc.taken=_e8;
}
_dc.preCastleQueenSide=new Array(2);
_dc.preCastleKingSide=new Array(2);
_dc.preCastleQueenSide[0]=this.canCastleQueenSide[0];
_dc.preCastleQueenSide[1]=this.canCastleQueenSide[1];
_dc.preCastleKingSide[0]=this.canCastleKingSide[0];
_dc.preCastleKingSide[1]=this.canCastleKingSide[1];
if(_dd.piece==ChessPiece.ROOK){
if(_dc.fromColumn==0){
this.canCastleQueenSide[_dd.colour]=false;
}else{
if(_dc.fromColumn==7){
this.canCastleKingSide[_dd.colour]=false;
}
}
}else{
if(_dd.piece==ChessPiece.KING){
this.canCastleQueenSide[_dd.colour]=false;
this.canCastleKingSide[_dd.colour]=false;
}else{
if(_e7&&(_e7.piece==ChessPiece.ROOK)){
if(_dc.toColumn==0){
if(((_e7.colour==ChessPiece.WHITE)&&_dc.toRow==0)||((_e7.colour==ChessPiece.BLACK)&&_dc.toRow==7)){
this.canCastleQueenSide[_e7.colour]=false;
}
}else{
if(_dc.toColumn==7){
if(((_e7.colour==ChessPiece.WHITE)&&_dc.toRow==0)||((_e7.colour==ChessPiece.BLACK)&&_dc.toRow==7)){
this.canCastleKingSide[_e7.colour]=false;
}
}
}
}
}
}
this.updatePositionReached(_dd.colour);
};
Board.prototype.isThreeFoldRep=function(_ec){
var _ed=this.toMove;
if(_ec){
if(_ed==ChessPiece.WHITE){
_ed=ChessPiece.BLACK;
}else{
_ed=ChessPiece.WHITE;
}
}
var _ee=this.boardToUniqueFen(_ed);
return (this.positionsSeen[_ee]>=3);
};
Board.prototype.updatePositionReached=function(_ef){
var _f0=this.boardToUniqueFen(_ef);
if(!this.positionsSeen){
this.positionsSeen=[];
}
if(this.positionsSeen[_f0]){
this.positionsSeen[_f0]++;
}else{
this.positionsSeen[_f0]=1;
}
};
Board.prototype.promptPromotion=function(_f1,col,row,_f4,_f5){
_f1.prePromotionColumn=_f1.column;
_f1.prePromotionRow=_f1.row;
_f1.setPosition(col,row,false,null,this.moveAnimationLength);
var _f6=this;
var _f7=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_f7.hide();
_f6.updatePiece(_f1,col,row,_f4,_f5,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_f7.hide();
_f6.updatePiece(_f1,col,row,_f4,_f5,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_f7.hide();
_f6.updatePiece(_f1,col,row,_f4,_f5,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_f7.hide();
_f6.updatePiece(_f1,col,row,_f4,_f5,false,"n");
},isDefault:false}]});
_f7.setHeader(_js("Select Promotion Piece"));
_f7.setBody("<div></div>");
_f7.render(document.body);
};
Board.moveToLocale=function(_f8){
if(!_f8||_f8==""){
return _f8;
}
var _f9="";
for(var i=0;i<_f8.length;i++){
var _fb=_f8.charAt(i);
switch(_fb){
case "K":
_fb=_js("K");
break;
case "Q":
_fb=_js("Q");
break;
case "R":
_fb=_js("R");
break;
case "N":
_fb=_js("N");
break;
case "B":
_fb=_js("B");
break;
case "P":
_fb=_js("P");
break;
case "a":
_fb=_js("a");
break;
case "b":
_fb=_js("b");
break;
case "c":
_fb=_js("c");
break;
case "d":
_fb=_js("d");
break;
case "e":
_fb=_js("e");
break;
case "f":
_fb=_js("f");
break;
case "g":
_fb=_js("g");
break;
case "h":
_fb=_js("h");
break;
case "x":
_fb=_js("x");
break;
case "#":
_fb=_js("#");
break;
}
_f9+=_fb;
}
return _f9;
};
Board.prototype.updatePiece=function(_fc,col,row,_ff,_100,_101,_102,_103){
if(_102){
this.board_xy=null;
if(_fc.prePromotionRow){
_fc.row=_fc.prePromotionRow;
_fc.column=_fc.prePromotionColumn;
}
}
if(_102==null&&_fc.column==col&&_fc.row==row){
this.board_xy=null;
_fc.setPosition(_fc.column,_fc.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _104=null;
if(this.currentMove){
if(this.currentMove.prev){
_104=this.currentMove.prev;
}else{
_104=this.prev_move;
}
}else{
_104=this.prev_move;
}
if(clog){
if(this.currentMove){
console.log("updatepiece currentMove:"+this.currentMove.output());
}else{
console.log("updatepiece currentmove null");
}
}
if(!_ff&&!this.canMove(_fc.makeLightWeight(),col,row,_104,true)){
this.board_xy=null;
_fc.setPosition(_fc.column,_fc.row,false,null,0.5);
if(clog){
console.log("move not legal , move back to orig:"+this.toMove);
if(_104){
console.log("prevMove was:"+_104.output());
}else{
console.log("prevMove was null");
}
}
return;
}
var _105="";
if(_101&&_fc.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_fc,col,row,_ff,_100);
return;
}else{
if(_102!=null){
_105=_102;
}
}
var _106=true;
var _107="";
_107+=Move.columnToChar(_fc.column);
_107+=String.fromCharCode("1".charCodeAt(0)+_fc.row);
_107+=Move.columnToChar(col);
_107+=String.fromCharCode("1".charCodeAt(0)+(row));
if(_105){
_107+=_105;
}
var _108=this.createMoveFromString(_107);
var move=this.currentMove;
if(move){
_108.moveNum=move.moveNum;
}
var res=null;
for(var i=0;i<this.registeredUpdateListeners.length;i++){
_10c=this.registeredUpdateListeners[i].updatePieceCallback(_105,_fc,col,row,_ff,_100,_101,_102,_103,_104,this.currentMove,_108);
if(!_10c){
return false;
}
if(!_10c.ignoreRetVal){
res=_10c;
}
}
if(!res){
if(clog){
console.log("Got no update piece callbak");
}
return false;
}
if(res.allowMove){
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
}
var move=res.move;
for(var i=0;i<this.registeredUpdateAllowMoveListeners.length;i++){
var res2=this.registeredUpdateAllowMoveListeners[i].updateAllowMoveCallback(_105,_fc,col,row,_ff,_100,_101,_102,_103,move);
}
this.makeMove(move,_fc,_100,this.moveAnimationLength,true,true,null,null,true);
var _10e=!res.dontMakeOpponentMove&&!_ff&&(this.currentMove&&this.currentMove.next&&!this.currentMove.next.atEnd);
if(clog){
if(move.next){
console.log("setting current move in updatepiece to:"+move.next.output());
}else{
console.log("in updatepiece, current move being set to null");
}
}
this.setCurrentMove(move.next,false,_10e);
if(this.currentMove.atEnd){
for(var i=0;i<this.registeredUpdateEndOfMovesListeners.length;i++){
var res=this.registeredUpdateEndOfMovesListeners[i].updateEndOfMovesCallback(_105,_fc,col,row,_ff,_100,_101,_102,_103);
}
}
if(_10e){
opponentMove=this.currentMove;
if(this.currentMove&&this.currentMove.next.atEnd){
this.toggleToMove();
}
this.updatePiece(this.boardPieces[opponentMove.fromColumn][opponentMove.fromRow],opponentMove.toColumn,opponentMove.toRow,true,true,false);
}
}else{
var move=res.move;
var _10f=_fc.column;
var _110=_fc.row;
this.board_xy=null;
_fc.setPosition(_fc.column,_fc.row,false,null,this.moveAnimationLength);
for(var i=0;i<this.registeredUpdateWrongMoveListeners.length;i++){
var res=this.registeredUpdateWrongMoveListeners[i].updateWrongMoveCallback(_105,_fc,col,row,_ff,_100,_101,_102,_103,move);
}
}
for(var i=0;i<this.registeredUpdatePieceFinishedListeners.length;i++){
var _10c=this.registeredUpdatePieceFinishedListeners[i].updatePieceFinishedCallback(_105,_fc,col,row,_ff,_100,_101,_102,_103,_104,this.currentMove,_108);
}
};
Board.prototype.addGotoMoveIndexListener=function(_111){
this.registeredGotoMoveIndexListeners.push(_111);
};
Board.prototype.addPasteFenClickedListener=function(_112){
this.registeredPasteFenClickedListeners.push(_112);
};
Board.prototype.addBackMovePreCurrentListener=function(_113){
this.registeredBackMovePreCurrentListeners.push(_113);
};
Board.prototype.addForwardMovePostUpdateListener=function(_114){
this.registeredForwardMovePostUpdateListeners.push(_114);
};
Board.prototype.addForwardAtEndListener=function(_115){
this.registeredForwardAtEndListeners.push(_115);
};
Board.prototype.addUpdatePieceListener=function(_116){
this.registeredUpdateListeners.push(_116);
};
Board.prototype.addUpdatePieceFinishedListener=function(_117){
this.registeredUpdatePieceFinishedListeners.push(_117);
};
Board.prototype.addUpdatePieceEndOfMovesListener=function(_118){
this.registeredUpdateEndOfMovesListeners.push(_118);
};
Board.prototype.addUpdatePieceHaveAltListener=function(_119){
this.registeredUpdateHaveAltListeners.push(_119);
};
Board.prototype.addUpdatePieceAllowMoveListener=function(_11a){
this.registeredUpdateAllowMoveListeners.push(_11a);
};
Board.prototype.addUpdatePieceWrongMoveListener=function(_11b){
this.registeredUpdateWrongMoveListeners.push(_11b);
};
Board.prototype.scoreToShortString=function(_11c){
if(_11c=="draw"){
return "D";
}
if(_11c>=0){
return "M"+_11c;
}else{
return "L"+(-1*_11c);
}
};
Board.prototype.scoreToLongString=function(_11d){
if(_11d=="draw"){
return _js("Draw");
}
if(_11d==0){
return _js("Mate");
}else{
if(_11d>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_11d]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_11d)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_11e){
var _11f=_11e.score;
var _120=_11e.optimal_score;
var s=this.scoreToShortString(_11f);
var opt=this.scoreToShortString(_120);
var _123=this.scoreToLongString(_11f);
var _124=this.scoreToLongString(_120);
if(_11f==_120){
return ["",_123];
}else{
var _125="ct-subopt-move-score";
if(_11f=="draw"||_11f<0){
_125="ct-bad-move-score";
}
return ["<span class=\""+_125+"\">"+s+"("+opt+")</span>",_123+"("+_124+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_126,_127,_128,_129,_12a){
if(clog){
console.log("fromCol:"+_126+" fromRow:"+_127+" toCol:"+_128+" toRow:"+_129);
}
var _12b=this.boardPieces[_126][_127];
var _12c=_12b.piece;
var _12d=ChessPiece.pieceTypeToChar(_12c);
var move="";
if(_12c==ChessPiece.PAWN){
if(_126==_128){
move=Move.columnToChar(_126)+""+(_129+1);
}else{
move=Move.columnToChar(_126)+"x"+Move.columnToChar(_128)+""+(_129+1);
if(!this.boardPieces[_128][_129]){
move+=" e.p.";
}
}
}else{
if(_12c==ChessPiece.KING){
var _12f=Math.abs(_126-_128);
if(_12f==1||_12f==0){
move=_12d;
if(this.boardPieces[_128][_129]){
move+="x";
}
move+=Move.columnToChar(_128)+""+(_129+1);
}else{
if(_128==6){
move="O-O";
}else{
move="O-O-O";
}
}
}else{
var _130=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_12b.colour&&cp.piece==_12c&&!(_12b.column==cp.column&&_12b.row==cp.row)){
var prev=null;
if(this.currentMove){
prev=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_128,_129,prev,true)){
_130.push(cp);
}
}
}
}
move=_12d;
if(_130.length>0){
var _135=false;
var _136=false;
for(var i=0;i<_130.length;i++){
if(_130[i].row==_127){
_136=true;
}
if(_130[i].column==_126){
_135=true;
}
}
if(_136||!(_136||_135)){
move+=Move.columnToChar(_126);
}
if(_135){
move+=""+(_127+1);
}
}
if(this.boardPieces[_128][_129]){
move+="x";
}
move+=Move.columnToChar(_128)+""+(_129+1);
}
}
var _138="";
var _139="";
if(_12a){
var _13a=this.cloneBoard();
var _13b=ChessPiece.WHITE;
if(_13a.boardPieces[_12a.fromColumn][_12a.fromRow].colour==ChessPiece.WHITE){
_13b=ChessPiece.BLACK;
}
_13a.makeMove(_12a,_13a.boardPieces[_12a.fromColumn][_12a.fromRow],false,_13a.moveAnimationLength,false,false);
if(!_13a.isKingSafe(_13b,_12a)){
_138="+";
if(_13a.isKingMated(_13b,_12a)){
_138="#";
}
}
if(_12a.promotion){
_139="="+((_12a.promotion+"").toUpperCase());
}
}
move+=_139+_138;
return move;
};
Board.getVarMove=function(move,row,col,_13f,_140){
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _142=move.vars[i];
if(_142.fromColumn==_13f.column&&_142.fromRow==_13f.row&&_142.toRow==row&&_142.toColumn==col&&(_140==""||(_140==_142.promotion))){
return _142;
}
}
}
};
Board.prototype.createMoveFromString=function(_143){
var _144=0;
var take=false;
var _146=null;
var _147=_143.charCodeAt(_144++);
var _148=_143.charCodeAt(_144++);
var _149=_143.split("|");
var pgn=null;
if(_149.length>1){
pgn=_149[1];
_143=_149[0];
}else{
_143=_149[0];
}
if(_143.charAt(_144)=="x"){
_144++;
take=true;
}
var _14b=_143.charCodeAt(_144++);
var _14c=_143.charCodeAt(_144++);
if(_144<_143.length){
_146=_143.charAt(_144);
}
var move=new Move(_147-("a".charCodeAt(0)),_148-("1".charCodeAt(0)),_14b-("a".charCodeAt(0)),_14c-("1".charCodeAt(0)),take,_146,_143);
move.pgn=pgn;
return move;
};
Board.prototype.getBackButton=function(){
if(!this.backButton){
this.backButton=YAHOO.util.Dom.get(this.boardName+"-back");
}
return this.backButton;
};
Board.prototype.getForwardButton=function(){
if(!this.forwardButton){
this.forwardButton=YAHOO.util.Dom.get(this.boardName+"-forward");
}
return this.forwardButton;
};
Board.prototype.getEndButton=function(){
if(!this.endButton){
this.endButton=YAHOO.util.Dom.get(this.boardName+"-end");
}
return this.endButton;
};
Board.prototype.getStartButton=function(){
if(!this.startButton){
this.startButton=YAHOO.util.Dom.get(this.boardName+"-start");
}
return this.startButton;
};
Board.prototype.setForwardBack=function(){
var back=this.getBackButton();
var _14f=this.getForwardButton();
var end=this.getEndButton();
var _151=this.getStartButton();
if(!this.currentMove){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_151){
_151.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
if(_14f){
_14f.src=this.boardImagePath+"/images/resultset_next_disabled"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/disabled_resultset_last"+this.getVersString()+".gif";
}
return;
}
if(this.currentMove.prev==null){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_151){
_151.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
}else{
if(back){
back.src=this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif";
}
if(_151){
_151.src=this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif";
}
}
if(this.currentMove.atEnd){
if(_14f){
_14f.src=this.boardImagePath+"/images/resultset_next_disabled"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/disabled_resultset_last"+this.getVersString()+".gif";
}
}else{
if(_14f){
_14f.src=this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/resultset_last"+this.getVersString()+".gif";
}
}
};
Board.prototype.convertPiecesFromLightWeight=function(_152){
var _153=this.settingUpPosition;
this.settingUpPosition=true;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
var _156=this.boardPieces[i][j];
var p=_156.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var move=this.moveArray[_152];
while(move!=null){
if(move.taken){
move.taken=move.taken.makeHeavyWeight();
}
move=move.prev;
}
this.settingUpPosition=_153;
};
MovesDisplay.prototype.setToMove=function(_159){
this.toMove=_159;
};
MovesDisplay.prototype.clickComment=function(e){
var t=e.currentTarget?e.currentTarget:e.targetElement?e.targetElement:false;
if(!t){
t=YAHOO.util.Event.getTarget(e);
}
if(!t.id){
t=t.parentNode;
}
var _15c=t.id.substr((this.board.boardName+"-mcX").length);
var _15d=true;
if(t.id.indexOf("-mca")>=0){
_15d=false;
}
var move=this.board.moveArray[_15c];
var _15f="";
if(_15d){
_15f=move.beforeComment;
}else{
_15f=move.afterComment;
}
mySimpleDialog=new YAHOO.widget.SimpleDialog(this.boardName+"-editCommentDialog",{width:"20em",fixedcenter:true,modal:true,visible:false,draggable:false});
mySimpleDialog.setHeader("Edit Comment");
mySimpleDialog.setBody("<textarea id=\""+this.board.boardName+"-editComment\">"+_15f+"</textarea>");
mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_INFO);
var me=this;
var _161=function(){
if(_15d){
move.beforeComment=null;
}else{
move.afterComment=null;
}
t.innerHTML="";
this.hide();
};
var _162=function(){
var _163=YAHOO.util.Dom.get(me.board.boardName+"-editComment");
var txt=trimStr(_163.value);
if(_15d){
move.beforeComment=txt;
}else{
move.afterComment=txt;
}
if(_15d){
t.innerHTML=me.outputComment(txt,0)+" ";
}else{
t.innerHTML=" "+me.outputComment(txt,0);
}
this.hide();
};
var _165=function(){
this.hide();
};
var _166=[{text:"Delete",handler:_161},{text:"Save",handler:_162},{text:"Cancel",handler:_165,isDefault:true}];
mySimpleDialog.cfg.queueProperty("buttons",_166);
mySimpleDialog.render(document.body);
mySimpleDialog.show();
};
MovesDisplay.prototype.gotoMove=function(e){
if(this.board.disableNavigation){
return;
}
if(this.board.tactics&&this.board.tactics.problemActive){
return;
}
if(this.board.blockFowardBack||this.board.deferredBlockForwardBack){
return;
}
var t=e.currentTarget?e.currentTarget:e.targetElement?e.targetElement:false;
if(!t){
t=YAHOO.util.Event.getTarget(e);
}
if(!t.id){
t=t.parentNode;
}
var _169=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_169);
}
this.board.gotoMoveIndex(_169,false,false,false,false);
if(this.board.problem){
if(this.board.currentMove.bestMoves){
this.board.problem.showBestMoves(this.board.currentMove,this.board.currentMove.bestMoves,this.board.currentMove.correctMove,this.board.currentMove.wrongMove);
}else{
this.board.problem.clearBestMoves();
}
}
};
MovesDisplay.prototype.getMovesDisplay=function(){
if(!this.cachedMovesDisplay&&!this.allreadyCachedMovesDisplay){
var name=this.board.boardName+"-moves";
if(this.moveListName){
name=this.moveListName;
}
this.cachedMovesDisplay=YAHOO.util.Dom.get(name);
this.allreadyCachedMovesDisplay=true;
}
return this.cachedMovesDisplay;
};
MovesDisplay.prototype.outputVariationStart=function(_16b,_16c,_16d,_16e){
var _16f="";
if(_16c>this.board.ml){
return _16f;
}
if(this.board.ml==1&&_16e>1){
return _16f;
}
var _170=this.getMovesDisplay();
if(_170){
if(_16b==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
if(this.board.useDivClearForNewline){
_16f+="<div style=\"clear:both;\"></div>";
}
_16f+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
if(this.board.useDivClearForNewline){
_16f+="<div style=\"clear:both;\"></div>";
}else{
_16f+="<br/>";
}
}
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_16b>0)){
_16f+="<span>"+this.board.variationStartString+"</span>";
}
}
this.firstNonMove=false;
return _16f;
};
MovesDisplay.prototype.outputVariationEnd=function(_171,_172,_173,_174){
var _175=this.getMovesDisplay();
var _176="";
if(this.board.ml==1&&_172>0&&this.board.outputFirstVar){
return _176;
}
this.board.outputFirstVar=true;
if(_175){
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_171>1)){
_176+="<span>"+this.board.variationEndString+"</span>";
}
}
if(_171==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _176;
};
MovesDisplay.prototype.outputComment=function(_177,_178,_179){
if(this.board.ignoreCommentRegex){
var _17a=new RegExp(this.board.ignoreCommentRegex);
if(_17a.test(_177)){
return "";
}
}
var _17b="";
if(this.board.ml==1){
return _17b;
}
var _17c=this.getMovesDisplay();
if(_17c){
if(_178==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_17b+="<br/>";
}
_17b+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _17d="ct-board-move-comment";
if(_179){
_17d="ct-board-move-alt-comment";
}
if(this.board.handleCommentClicks){
_17d+=" ct-board-clickable-comment";
}
_17b+="<span class=\""+_17d+"\"> "+_177+" </span>";
if(_178==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _17b;
};
MovesDisplay.prototype.outputNag=function(_17e){
var _17f="";
var _180=this.getMovesDisplay();
if(_180){
var _181=null;
switch(_17e){
case 11:
_181="=";
break;
case 14:
_181="+=";
break;
case 15:
_181="=+";
break;
case 16:
_181="+/-";
break;
case 17:
_181="-/+";
break;
case 18:
_181="+-";
break;
case 19:
_181="-+";
break;
case 20:
_181="+--";
break;
case 21:
_181="--+";
break;
default:
}
if(_181){
_17f+="<span> "+_181+" </span>";
}
}
return _17f;
};
MovesDisplay.prototype.outputResult=function(_182){
return "<span class=\"ct-result\">"+_182+"</span>";
};
MovesDisplay.prototype.outputMove=function(_183,_184,_185,_186,_187,_188,_189,move,_18b,_18c){
if(clog){
console.log("outputMove:"+_186+" hideScore:"+_18b);
}
var _18d="";
var _18e=this.getMovesDisplay();
if(this.board.tr&&_184>0&&(_188>1||_189>3)&&!_187){
return _18d;
}
if(this.board.ml==1&&_188>0&&this.board.outputFirstVar){
return _18d;
}
if(_18e){
var _18f=""+Math.round(_185/2)+". ";
var _190=false;
if(_185%2!=1){
if(clog){
console.log("firstRav:"+_187+" firstNonMove:"+this.firstNonMove);
}
if(_187||!this.firstNonMove){
_18f=Math.round(_185/2)+"... ";
_190=true;
}else{
_18f="";
}
}
if(clog){
console.log("moveNum:"+_185+" moveNumOut:"+_18f);
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_184==0&&(!this.firstNonMove||_185%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_18d+="</div>";
}
if(this.board.newlineForEachMainMove){
if(this.board.useDivClearForNewline){
_18d+="<div style=\"clear:both;\"></div>";
}else{
_18d+="<br/>";
}
}
}
var _191="";
var _192="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_191=res[0];
_192=res[1];
}
var _194="";
if(_18b){
_194="initially_hidden";
}
if(_191!=""){
_191=" "+_191;
}
var _195="title";
if(_18b){
_195="alt";
}
var _196="";
if(_18c){
_196=" rel=\""+_186+"\" ";
_186="___";
}
var _197="";
if(_190&&_184==0){
_197="<span class=\"ct-board-move-dottedempty\">&nbsp;</span>";
}
var _198="";
if(_18f){
_198="<span class=\"ct-board-move-movenum\">"+_18f+"</span>";
}
_18d+="<span "+_196+_195+"=\""+_192+"\" id=\""+this.board.boardName+"-m"+_183+"\" class=\""+((_184==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_198+_197+"<span class=\"ct-board-move-movetext\">"+_186+"</span><span id=\""+this.board.boardName+"-msc"+_183+"\" class=\""+_194+"\">"+_191+"</span></span>";
}
this.firstNonMove=true;
return _18d;
};
Board.prototype.setMoveSeqLalg=function(_199,_19a,_19b,_19c){
var _19d=new Array();
if(_199&&_199.length>0){
_19d=_199.replace(/\s+$/g,"").split(" ");
}
this.setupFromLalgArray(_19d,_19c,_19b,_19a);
};
Board.prototype.setupFromLalgArray=function(_19e,_19f,_1a0,_1a1){
this.outputFirstVar=false;
if(this.movesDisplay){
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
var md=this.movesDisplay.getMovesDisplay();
if(md){
YAHOO.util.Event.purgeElement(md,true);
md.innerHTML="";
}
}
if(!_1a1){
_1a1=new Array();
}
var _1a3=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _1a4=new Array();
var _1a5=new Array();
if(this.prev_move){
_1a3.makeMove(this.prev_move,_1a3.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_1a3.moveAnimationLength,false,false);
}
var _1a6=_1a3.cloneBoard();
var _1a7=null;
var _1a8=0;
var _1a9="";
var _1aa=false;
var _1ab=false;
var _1ac=0;
var _1ad=false;
var _1ae=new Array();
var _1af=new Array();
_1af[0]=0;
var _1b0=new Array();
var _1b1=new Array();
var _1b2=_1a0*2-1;
var _1b3=_1a0*2-1;
var _1b4=new Array();
var _1b5=ChessPiece.WHITE;
var _1b6=0;
var eval="";
var _1b8="";
var _1b9="";
var time="";
var _1bb=-1;
var _1bc=0;
for(var i=0;i<_19e.length;i++){
var _1be=0;
if(_19e[i]=="ALT"){
_1ab=true;
continue;
}
if(_19e[i].indexOf("EVAL")==0){
eval=_19e[i].split(":")[1];
if(parseInt(eval)>=175&&_1ac>0&&_1af[_1ac]>1){
_1ab=true;
}
continue;
}
if(_19e[i].indexOf("DEPTH")==0){
_1b8=_19e[i].split(":")[1];
continue;
}
if(_19e[i].indexOf("NODES")==0){
_1b9=_19e[i].split(":")[1];
continue;
}
if(_19e[i].indexOf("TIME")==0){
time=_19e[i].split(":")[1];
var e=eval;
if(eval.indexOf("mate")!=0){
e=(parseFloat(eval)/100).toFixed(2);
if(e>0){
e="+"+e;
}
}else{
e=e.replace(/_/," ");
var _1c0=e.split(" ");
_1be=parseInt(_1c0[1]);
e=_js("mate")+" "+_1c0[1];
if(_1af[_1ac]==1){
_1bb=_1be;
}
}
_1bc=_1be;
if(_1be<0){
_1ab=false;
}else{
if(_1be>0&&_1be<8&&_1ac>0&&_1af[_1ac]>1){
_1ab=true;
}
}
var _1c1="";
if(_1ab){
_1c1=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_1b9)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_1ac>0&&_1af[_1ac]>this.ml)){
_19e[i]=_1c1+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_1b8]])+nps+")";
}else{
_19e[i]="";
}
}
if(_19e[i]=="}"){
_1aa=false;
if(this.movesDisplay){
_1a9=_1a9.replace(/\s+$/g,"");
_1b4.push(this.movesDisplay.outputComment(_1a9,_1ac,_1ab));
}
continue;
}else{
if(_1aa){
_1a9+=_19e[i]+" ";
continue;
}else{
if(_19e[i]=="{"){
_1a9="";
_1aa=true;
continue;
}else{
if(_19e[i]=="("){
if(!_1af[_1ac+1]){
_1af[_1ac+1]=0;
}
_1af[_1ac+1]++;
if(this.movesDisplay){
_1b4.push(this.movesDisplay.outputVariationStart(_1ac,_1af[_1ac+1],_1b2,_1ae[0]));
}
_1ae[_1ac]=_1b2;
_1b0[_1ac]=_1a7;
_1b1[_1ac]=_1b5;
_1a4[_1ac]=_1a3;
_1a5[_1ac]=_1a6;
_1a3=_1a6.cloneBoard();
_1ac++;
_1b2--;
_1ad=true;
continue;
}else{
if(_19e[i]==")"){
if(this.movesDisplay){
_1b4.push(this.movesDisplay.outputVariationEnd(_1ac,_1af[_1ac],_1b2,_1ae[0]));
}
var _1c4=new Move();
_1c4.atEnd=true;
_1a7.next=_1c4;
_1c4.prev=_1a7;
_1ac--;
_1b2=_1ae[_1ac];
_1a7=_1b0[_1ac];
_1b5=_1b1[_1ac];
_1a3=_1a4[_1ac];
_1a6=_1a5[_1ac];
_1ab=false;
continue;
}else{
if(_19e[i].charAt(0)=="$"){
if(this.movesDisplay){
_1b4.push(this.movesDisplay.outputNag(parseInt(_19e[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_19e[i]);
var _1c6=false;
if(_1b2==_1b3&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1b2++;
_1c6=true;
_1b5=ChessPiece.BLACK;
}
move.index=_1a8;
var _1c7=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1c7=move.pgn;
}else{
_1c7=_1a3.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1c7;
}
_1c7=Board.moveToLocale(_1c7);
if(this.movesDisplay){
this.movesDisplay.setToMove(_1b5);
_1b4.push(this.movesDisplay.outputMove(_1a8,_1ac,_1b2,_1c7+" ",_1ad,_1af[_1ac],_1ae[0]));
}
_1b5=(_1b5==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_1b2;
_1b2++;
if(_1ac>0){
if(_1ad){
var _1c8=_1a7;
if(_1c8==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1c8.numVars==0){
_1c8.vars=new Array();
}
move.isAlt=_1ab;
move.mateInMoves=_1bc;
_1c8.vars[_1c8.numVars++]=move;
move.prev=_1c8.prev;
_1ad=false;
}else{
move.prev=_1a7;
if(_1a7!=null){
_1a7.next=move;
}
}
}else{
move.prev=_1a7;
if(_1a7!=null){
_1a7.next=move;
}
}
_1af[_1ac+1]=0;
if(_1ac==0){
_1b6=_1a8;
}
_1a1[_1a8++]=move;
_1a3.moveArray[_1a8-1]=move;
_1a7=move;
_1a6=_1a3.cloneBoard();
_1a3.makeMove(move,_1a3.boardPieces[move.fromColumn][move.fromRow],false,_1a3.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _1c9=this.movesDisplay.getMovesDisplay();
_1b4.push(this.movesDisplay.outputResult(_19f));
this.pendingMovesOutput=_1b4.join("");
this.pendingMovesOutputCount=_1a8;
}
this.lastMoveIndex=_1b6;
if(_1a7!=null){
var _1c4=new Move();
_1c4.atEnd=true;
_1a7.next=_1c4;
_1c4.prev=_1a7;
}
this.lastCount=_1a8;
};
Board.prototype.getMaterialCount=function(){
var _1ca=0;
var _1cb=0;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _1ce=this.boardPieces[i][j];
if(_1ce){
if(_1ce.colour==ChessPiece.WHITE){
_1ca+=ChessPiece.materialValue(_1ce.piece);
}else{
_1cb+=ChessPiece.materialValue(_1ce.piece);
}
}
}
}
return [_1ca,_1cb];
};
Board.prototype.getMaterialBalance=function(){
var cnt=this.getMaterialCount();
return cnt[0]-cnt[1];
};
Board.prototype.getMaterialBalances=function(){
var _1d0=this.cloneBoard();
var mv=this.moveArray[0];
_1d0.gotoMoveIndex(-1,true,true,true,true);
var _1d2=[];
while(mv&&!mv.atEnd){
_1d0.makeMove(mv,_1d0.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
_1d2.push(_1d0.getMaterialBalance());
mv=mv.next;
_1d0.toggleToMove();
}
return _1d2;
};
Board.prototype.lalgToMoveList=function(_1d3,_1d4,_1d5,_1d6,_1d7){
if(ctime){
console.time("lalgToMoveList");
}
if(clog){
console.log("startMoveNum:"+_1d5);
}
if(!_1d6){
_1d6=new Array();
}
var _1d8=this.cloneBoard();
var _1d9=new Array();
var _1da=new Array();
if(!_1d7&&this.prev_move){
_1d8.makeMove(this.prev_move,_1d8.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_1d8.moveAnimationLength,false,false);
}
var _1db=_1d8.cloneBoard();
var nags=[];
var _1dd=null;
var _1de=0;
var _1df="";
var _1e0=false;
var _1e1=0;
var _1e2=false;
var _1e3=new Array();
var _1e4=new Array();
_1e4[0]=0;
var _1e5=new Array();
var _1e6=new Array();
var _1e7=_1d5*2-1;
var _1e8=new Array();
var _1e9=ChessPiece.WHITE;
var _1ea=0;
var _1eb=true;
for(var i=0;i<_1d3.length;i++){
if(_1d3[i]=="}"){
_1e0=false;
_1df=_1df.replace(/\s+$/g,"");
continue;
}else{
if(_1e0){
_1df+=_1d3[i]+" ";
continue;
}else{
if(_1d3[i]=="{"){
if(_1df){
if(_1dd){
_1dd.afterComment=trimStr(_1df);
}
}
_1df="";
_1e0=true;
continue;
}else{
if(_1d3[i]=="("){
if(clog){
console.log("var start comment:"+_1df);
}
if(_1dd){
_1dd.afterComment=trimStr(_1df);
_1df="";
}
if(clog){
if(_1dd){
console.log("old:"+_1dd.output());
}else{
console.log("no old move");
}
}
if(!_1e4[_1e1+1]){
_1e4[_1e1+1]=0;
}
_1e4[_1e1+1]++;
_1e3[_1e1]=_1e7;
_1e5[_1e1]=_1dd;
_1e6[_1e1]=_1e9;
_1d9[_1e1]=_1d8;
_1da[_1e1]=_1db;
_1d8=_1db.cloneBoard();
_1e1++;
_1e7--;
_1e2=true;
continue;
}else{
if(_1d3[i]==")"){
if(_1dd){
if(clog){
console.log("var end comment:"+_1df);
console.log("var end comment:"+_1dd.output());
}
_1dd.afterComment=trimStr(_1df);
_1df="";
}
var _1ed=new Move();
_1ed.atEnd=true;
_1dd.next=_1ed;
_1ed.prev=_1dd;
_1e1--;
_1e7=_1e3[_1e1];
_1dd=_1e5[_1e1];
_1e9=_1e6[_1e1];
_1d8=_1d9[_1e1];
_1db=_1da[_1e1];
continue;
}else{
if(_1d3[i].charAt(0)=="$"){
nags.push(parseInt(_1d3[i].substring(1)));
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1d3[i]);
move.nags=nags;
move.beforeComment=trimStr(_1df);
_1df=null;
nags=[];
if(_1eb){
if(this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1e7++;
_1e9=ChessPiece.BLACK;
if(clog){
console.log("first move black new movenum:"+_1e7);
}
}
_1eb=false;
}
move.index=_1de;
var _1ef=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1ef=move.pgn;
move.SAN=move.pgn;
}else{
_1ef=_1d8.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1ef;
}
_1e9=(_1e9==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_1e7;
_1e7++;
if(_1e1>0){
if(_1e2){
var _1f0=_1dd;
if(_1f0==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1f0.numVars==0){
_1f0.vars=new Array();
}
_1f0.vars[_1f0.numVars++]=move;
move.prev=_1f0.prev;
_1e2=false;
}else{
move.prev=_1dd;
if(_1dd!=null){
_1dd.next=move;
}
}
}else{
move.prev=_1dd;
if(_1dd!=null){
_1dd.next=move;
}
}
_1e4[_1e1+1]=0;
if(_1e1==0){
_1ea=_1de;
}
_1d6[_1de++]=move;
_1d8.moveArray[_1de-1]=move;
_1dd=move;
_1db=_1d8.cloneBoard();
_1d8.makeMove(move,_1d8.boardPieces[move.fromColumn][move.fromRow],false,_1d8.moveAnimationLength,false,false);
}
if(_1dd!=null){
var _1ed=new Move();
_1ed.atEnd=true;
_1dd.next=_1ed;
_1ed.prev=_1dd;
if(_1df){
_1dd.afterComment=trimStr(_1df);
}
}
if(ctime){
console.timeEnd("lalgToMoveList");
}
return _1d6;
};
Board.prototype.reset=function(fen,_1f2){
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.clearMoveList();
if(fen){
this.startFen=fen;
this.setupFromFen(fen,false,this.isFlipped,false,_1f2,true);
}else{
this.startFen=Board.INITIAL_FEN;
this.setupFromFen(Board.INITIAL_FEN,false,this.isFlipped,false,false,true);
}
this.setForwardBack();
};
Board.prototype.clearMoveList=function(_1f3){
this.movesDisplay.firstNonMove=false;
var _1f4=this.movesDisplay.getMovesDisplay();
if(_1f4){
YAHOO.util.Event.purgeElement(_1f4,true);
_1f4.innerHTML="";
}
this.currentMove=null;
this.moveIndex=-1;
this.moveArray=new Array();
if(_1f3){
_1f3.prev=null;
this.startMoveNum=_1f3.moveNum;
}else{
this.startMoveNum=1;
}
};
Board.prototype.insertMovesFromMoveList=function(_1f5,_1f6,_1f7){
var _1f8=!_1f6;
if(ctime&&_1f8){
console.time("insertMovesFromMoveList");
}
if(!this.movesDisplay){
return;
}
if(_1f8){
this.clearMoveList(_1f5);
}
var _1f9=0;
var _1fa=_1f5.moveNum;
var move=_1f5;
while(move!=null&&!move.atEnd){
if(clog){
console.log("move:"+move.output());
}
var _1fc=move.next;
if(clog){
if(this.currentMove){
console.log("current move:"+this.currentMove.output());
}else{
console.log("no current move");
}
if(_1fc){
console.log("next move:"+_1fc.output());
}else{
console.log("no next move");
}
}
if(_1f8||_1f5!=move||_1f7==null){
if(clog){
console.log("about to call insertmoveafter");
}
this.insertMoveAfter(this.currentMove,move);
if(clog){
console.log("finished call to insertmoveafter");
}
}else{
if(clog){
console.log("about to replace variationParent:"+_1f7.output()+" with move:"+move.output()+" and board:"+this.boardToFen());
}
this.replaceMove(_1f7,move,true,true);
}
if(move.beforeComment){
this.insertCommentIntoMoveDisplay(move,move.beforeComment,false);
}
if(move.afterComment){
this.insertCommentIntoMoveDisplay(move,move.afterComment,true);
}
if(clog){
console.log("about to make move:"+move.output()+" with board pos:"+this.boardToFen());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("made move");
}
this.setCurrentMove(move,true,true);
if(move.numVars>0){
var _1fd=move.index;
var bm=move.prev;
var _1ff=-1;
if(bm){
_1ff=bm.index;
}
var _200=move.numVars;
var vars=move.vars;
move.numVars=0;
move.vars=[];
for(var i=0;i<_200;i++){
this.gotoMoveIndex(_1ff,true,true,true,true);
if(clog){
console.log("about to call insertMovesFromMoveList with head of variation");
}
this.insertMovesFromMoveList(vars[i],true,move);
if(clog){
console.log("about to reset currentMoveIndex  after variation insert:"+_1fd);
}
}
this.gotoMoveIndex(_1fd,true,true,true,true);
this.backMove();
var cm=this.currentMove;
this.makeMove(cm,this.boardPieces[cm.fromColumn][cm.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
if(this.currentMove){
console.log("popped up from variation, current set back to:"+this.currentMove.output());
}else{
console.log("popped up from variation, current set to null");
}
}
}
move=_1fc;
}
if(_1f8){
this.gotoMoveIndex(-1,false,false,false,false);
}
if(clog){
var m=this.currentMove;
while(m){
console.log("m:"+m.output());
m=m.next;
}
}
if(ctime&&_1f8){
console.timeEnd("insertMovesFromMoveList");
}
};
Board.prototype.setupFromLalgArrayIncremental=function(_205,_206,_207,_208){
this.outputFirstVar=false;
if(this.movesDisplay&&this.lastCount){
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
for(var i=0;i<this.lastCount;i++){
var mv=YAHOO.util.Dom.get(this.boardName+"-m"+i);
if(mv){
YAHOO.util.Event.purgeElement(mv);
}
}
}
var _20b=0;
var _20c=_207*2-1;
var _20d="";
var _20e=false;
var _20f=false;
var _210=ChessPiece.WHITE;
var _211=false;
var _212=true;
this.currentMove=null;
for(var i=0;i<_205.length;i++){
if(_205[i]=="}"){
_211=false;
if(this.movesDisplay){
_20d=_20d.replace(/\s+$/g,"");
}
continue;
}else{
if(_211){
_20d+=_205[i]+" ";
continue;
}else{
if(_205[i]=="{"){
_20d="";
_211=true;
continue;
}else{
if(_205[i]=="("){
_20e=true;
continue;
}else{
if(_205[i]==")"){
_20f=true;
continue;
}else{
if(_205[i].charAt(0)=="$"){
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_205[i]);
var _214=false;
if(_212&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_20c++;
_214=true;
_210=ChessPiece.BLACK;
}
this.startMoveNum=_20c;
_212=false;
move.index=_20b++;
var _215=move.moveString;
_215=Board.moveToLocale(_215);
_210=(_210==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
this.insertMoveAfter(this.currentMove,move);
if(clog){
if(move.prev){
if(move.prev.next){
console.log("move.prev.next:"+move.prev.next.output());
}else{
console.log("move.prev:"+move.prev.output()+" next null");
}
}
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
this.setCurrentMove(move);
}
this.gotoMoveIndex(-1,false,false,false,false);
};
Board.prototype.displayPendingMoveList=function(){
if(this.pendingMovesOutput&&this.movesDisplay){
var _216=this.movesDisplay.getMovesDisplay();
if(_216){
_216.innerHTML=this.pendingMovesOutput;
var _217=new YAHOO.util.Scroll(_216,{scroll:{to:[0,0]}},0);
_217.animate();
}
if(this.movesDisplay){
for(var i=0;i<this.pendingMovesOutputCount;i++){
var mv1=YAHOO.util.Dom.get(this.boardName+"-m"+i);
if(mv1){
YAHOO.util.Event.addListener(mv1,"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
if(this.handleCommentClicks){
var _21a=YAHOO.util.Dom.get(this.boardName+"-mcb"+i);
if(_21a){
YAHOO.util.Event.addListener(_21a,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
_21a=YAHOO.util.Dom.get(this.boardName+"-mca"+i);
if(_21a){
YAHOO.util.Event.addListener(_21a,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
}
}
}
}
}
};
Board.prototype.setMoveSequence=function(_21b,_21c,_21d,_21e){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_21b,this.tacticMoveArray,_21d,_21e);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_21c!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_21c,this.fullmoveArray,_21d,_21e);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_21f,_220){
if(_21f.numVars>0){
for(var i=0;i<_21f.numVars;i++){
_21f.vars[i].prev=_220;
this.resetVariationsPreviousNodes(_21f.vars[i],_220);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_222,_223){
if(!_223){
return;
}
if(_223.numVars>0){
for(var i=0;i<_223.numVars;i++){
_223.vars[i].prev=_222;
this.reconnectNextNodeVariations(_222,_223.vars[i]);
}
}
};
Board.prototype.findFirstMoveFromList=function(move){
var m=move;
while(m&&m.prev!=null){
m=m.prev;
}
return m;
};
Board.prototype.findVariationHeadFromMove=function(move){
var m=move;
while(m&&m.prev&&m.prev.next==m){
m=m.prev;
}
if(m&&m.prev&&m.prev.next!=m){
return m;
}else{
if(m&&!m.prev){
var _229=this.moveArray[0];
if(m!=_229){
return m;
}
}
return null;
}
};
Board.prototype.liftVariation=function(_22a){
if(!_22a){
return;
}
var _22b=null;
var _22c=null;
if(_22a.prev){
_22b=_22a.prev.next;
}else{
_22b=this.moveArray[0];
_22c=_22a;
}
var _22d=null;
if(this.currentMove&&this.currentMove.prev){
_22d=this.currentMove.prev;
}
if(_22b){
var _22e=_22b.numVars;
var vars=_22b.vars;
_22b.numVars=0;
_22b.vars=[];
if(_22a.numVars==0){
_22a.vars=[];
}
for(var i=0;i<_22e;i++){
var _231=vars[i];
if(clog){
console.log("processing var:"+_231.output());
}
if(_231==_22a){
if(clog){
console.log("inserted parent var");
}
_22a.vars.push(_22b);
_22a.numVars++;
}else{
_22a.vars.push(_231);
_22a.numVars++;
}
}
if(_22a.prev){
_22a.prev.next=_22a;
}
if(clog){
console.log("finished moving variations");
}
if(!_22c){
_22c=this.findFirstMoveFromList(_22a);
}
this.moveArray[0]=_22c;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_22c.output());
}
this.insertMovesFromMoveList(_22c);
}
if(_22d){
this.gotoMoveIndex(_22d.index);
}
};
Board.prototype.deleteMoveAndLine=function(move){
var m=move;
var oldM=m;
var _235=false;
var _236=null;
var _237=this.moveArray[0];
var _238=null;
if(clog){
console.log("delete line:"+move.output());
}
if(clog){
console.log("delete line prev:"+move.prev);
}
if(clog&&move.prev){
console.log("delete line prev.next:"+move.prev.next);
}
if(move&&move.prev&&move.prev.next!=move){
if(clog){
console.log("var is head and not front of move list");
}
_235=true;
_236=move.prev.next;
}else{
if(move&&!move.prev&&move!=this.moveArray[0]){
if(clog){
console.log("var is head and front of move list");
}
_235=true;
_236=this.moveArray[0];
}
}
if(clog){
console.log("isVariationHead:"+_235);
}
if(clog){
console.log("fm:"+_237.output());
}
var _239=m.prev;
if(_235){
_238=_236;
if(_236){
if(clog){
console.log("delete variation from parent:"+_236.output());
}
var _23a=[];
for(var i=0;i<_236.numVars;i++){
if(!(_236.vars[i]==oldM)){
if(clog){
console.log("saving var:"+_236.vars[i].output());
}
_23a.push(_236.vars[i]);
}else{
if(clog){
console.log("dropping var:"+_236.vars[i].output());
}
}
}
_236.vars=_23a;
_236.numVars=_23a.length;
}
}else{
if(_239){
_239.next=null;
_238=_239;
}else{
if(clog){
console.log("deleting entire list");
}
if(this.movesDisplay){
this.movesDisplay.firstNonMove=false;
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
}
var _23c=this.movesDisplay.getMovesDisplay();
if(_23c){
_23c.innerHTML="";
}
this.currentMove=null;
this.startMoveNum=_237.moveNum;
if(clog){
console.log("startFen:"+this.startFen);
}
this.moveIndex=-1;
this.moveArray=[];
this.setupFromFen(this.startFen);
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.setForwardBack();
return;
}
}
this.moveArray[0]=_237;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_237.output());
}
this.insertMovesFromMoveList(_237);
if(_238){
this.gotoMoveIndex(_238.index);
}
};
Board.prototype.insertMoveAfter=function(_23d,_23e,_23f,_240,_241,_242){
addToMovelist=!_23f;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _243="null";
if(_23d){
_243=_23d.output();
}
if(clog){
console.log("insert newMove:"+_23e.output()+" after:"+_243);
}
if(_23d==null){
this.currentMove=_23e;
_23e.atEnd=0;
_23e.prev=null;
_23e.next=null;
this.firstMove=_23e;
if(this.startMoveNum>0){
this.currentMove.moveNum=this.startMoveNum;
}else{
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
}
if(clog){
console.log("startMoveNum:"+this.startMoveNum+" currMoveNum:"+this.currentMove.moveNum);
}
}else{
_23e.atEnd=_23d.atEnd;
_23e.prev=_23d;
_23d.atEnd=0;
if(clog){
if(_23d.next){
console.log("prevMove.next:"+_23d.next.output());
}
}
if(_23e.equals(_23d.next)||_23e.equals(_23d)){
if(clog){
console.log("inserting move that already exists in variation:"+_23d.next.output());
}
var _244=_23d.next;
if(this.firstMove==_244){
this.firstMove=_23e;
}
if(_23e.equals(_23d)){
_244=_23d;
}
if(_244.prev&&(_244.prev.next==_244)){
_244.prev.next=_23e;
}
if(_244.next){
_244.next.prev=_23e;
}
addToMovelist=false;
_23e.moveNum=_244.moveNum;
_23e.ravLevel=_244.ravLevel;
_23e.index=_244.index;
_23e.fen=_244.fen;
_23e.nextFen=_244.nextFen;
_23e.bestMoves=_244.bestMoves;
_23e.correctMove=_244.correctMove;
_23e.wrongMove=_244.wrongMove;
_23e.next=_244.next;
_23e.vars=_244.vars;
_23e.numVars=_244.numVars;
this.reconnectNextNodeVariations(_23e,_244.next);
this.moveArray[_23e.index]=_23e;
if(this.currentMove==_244){
this.setCurrentMove(_23e);
}
}else{
_23e.moveNum=_23d.moveNum+1;
_23e.ravLevel=_23d.ravLevel;
_23e.next=_23d.next;
if(_23e.next){
_23e.next.prev=_23e;
}
}
_23d.next=_23e;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_23d,_23e,_240,_241,_242);
}
if(_23e.next==null){
var _245=this.createMoveFromString("i1i2");
_23e.next=_245;
_245.prev=_23e;
_245.moveNum=_23e.moveNum+1;
_245.ravLevel=_23e.ravLevel;
_245.next=null;
_245.atEnd=1;
_245.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_245.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_23e.next.output());
}
_23e.next.moveNum=_23e.moveNum+1;
}
};
function insertBefore(node,_247){
if(_247){
_247.parentNode.insertBefore(node,_247);
}
}
function insertAfter(node,_249){
var _24a=_249.parentNode;
_24a.insertBefore(node,_249.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_24b,_24c,_24d,_24e,_24f){
var _250="null";
if(_24b){
_250=_24b.output();
}
if(clog){
console.log("replace display newMove:"+_24c.output()+" after:"+_250+" hideScore:"+_24e);
}
if(!_24b){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_24c,false,_24e);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _251=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_251){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_24c.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_24c.fromColumn,_24c.fromRow,_24c.toColumn,_24c.toRow,_24c);
if(clog){
console.log("about to made san:"+san);
}
_24c.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_24b.index);
}
var _253=this.boardName+"-ms"+_24b.index;
var _254=-1;
if(_24b.next){
_254=this.boardName+"-m"+_24b.next.index;
}
if(clog){
console.log("oldMoveId:"+_253);
}
var _255=YAHOO.util.Dom.get(_253);
var _256=YAHOO.util.Dom.get(_254);
if(_24d){
this.moveIndex++;
_24c.index=this.moveIndex;
this.moveArray[this.moveIndex]=_24c;
if(clog){
console.log("replace as variation old:"+_24b.output()+" new:"+_24c.output());
}
var _257=document.createElement("span");
var _258=this.movesDisplay.outputVariationStart(0,0,_24c.moveNum,0);
_24c.ravLevel=_24b.ravlevel+1;
var _250=Board.moveToLocale(san);
if(_24c.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _259=this.movesDisplay.outputMove(this.moveIndex,_24c.ravLevel,_24c.moveNum,_250,_24d,0,_24c.moveNum,_24c,_24e,_24f);
var _25a=document.createElement("span");
_25a.id=(this.boardName+"-ms"+_24c.index);
_25a.innerHTML=_259+"&nbsp;";
var _25b=this.movesDisplay.outputVariationEnd(0,0,_24c.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _25c=document.createElement("span");
_25c.innerHTML=_258;
var _25d=document.createElement("span");
_25d.innerHTML=_25b;
_257.appendChild(_25c);
var els=YAHOO.util.Dom.getElementsByClassName("ct-mainline-commentary","div",_257);
var _25f=_257;
if(els.length>0){
_25f=els[0];
}
_25f.appendChild(_25a);
_25f.appendChild(_25d);
_255.appendChild(_257);
if(_256){
var els=YAHOO.util.Dom.getElementsByClassName("ct-board-move-movenum","span",_256);
if(els.length==0){
var _260=_24b.next.moveNum;
var _261=""+Math.round(_260/2)+". ";
var _262=false;
if(_260%2!=1){
if(clog){
console.log("firstRav:"+firstRav+" firstNonMove:"+this.firstNonMove);
}
if(true||firstRav||!this.firstNonMove){
_261=Math.round(_260/2)+"... ";
_262=true;
}else{
_261="";
}
}
var _25a=document.createElement("span");
_25a.className="ct-board-move-movenum";
_25a.innerHTML=_261;
insertBefore(_25a,_256.firstChild);
_25a=document.createElement("span");
if(_262){
_25a.className="ct-board-move-dottedempty";
_25a.innerHTML="&nbsp;";
insertAfter(_25a,_256.firstChild);
}
}
}
}else{
_24c.index=_24b.index;
this.moveArray[_24c.index]=_24c;
var _250=Board.moveToLocale(san);
if(_24c.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _259=this.movesDisplay.outputMove(_24c.index,_24c.ravLevel,_24c.moveNum,_250,_24d,0,_24c.moveNum,_24c,_24e,_24f);
var _25a=document.createElement("span");
_25a.innerHTML=_259+"&nbsp;";
_25a.id=(this.boardName+"-ms"+_24c.index);
var _263=[];
if(_255&&_255.childNodes){
for(var i=1;i<_255.childNodes.length;i++){
_263[i-1]=_255.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_24b.output()+" new:"+_24c.output());
}
_255.parentNode.replaceChild(_25a,_255);
if(_263){
for(var i=0;i<_263.length;i++){
_25a.appendChild(_263[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_24c.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_24c.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertCommentIntoMoveDisplay=function(move,_266,_267){
var _268=this.movesDisplay.getMovesDisplay();
if(!_268){
return;
}
var _269="b";
if(_267){
_269="a";
}
if(move){
var _26a=this.boardName+"-mc"+_269+move.index;
var _26b=YAHOO.util.Dom.get(_26a);
var _26c=false;
if(!_26b){
_26b=document.createElement("span");
_26b.id=_26a;
_26c=true;
}
_26b.innerHTML=this.movesDisplay.outputComment(_266,0);
var _26d=YAHOO.util.Dom.get((this.boardName+"-m"+move.index));
if(_26d){
if(_267){
move.afterComment=_266;
if(_26c){
insertAfter(_26b,_26d);
}
}else{
move.beforeComment=_266;
if(_26c){
insertBefore(_26b,_26d);
}
}
}
if(_26b&&_26c&&this.handleCommentClicks){
YAHOO.util.Event.addListener(_26b,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
}else{
}
};
Board.prototype.insertIntoMoveDisplay=function(_26e,_26f,_270,_271,_272){
var _273=this.movesDisplay.getMovesDisplay();
if(!_273){
return;
}
if(clog){
var _274="null";
if(_26e){
_274=_26e.output();
}
console.log("insert display newMove:"+_26f.output()+" after:"+_274);
}
var san=_26f.SAN;
if(!san){
san=this.makeShortAlgabraic(_26f.fromColumn,_26f.fromRow,_26f.toColumn,_26f.toRow,_26f);
_26f.SAN=san;
}
this.moveIndex++;
_26f.index=this.moveIndex;
this.moveArray[this.moveIndex]=_26f;
var _274=Board.moveToLocale(san);
var _276=false;
var _277=null;
if(_26e){
_277=YAHOO.util.Dom.get((this.boardName+"-ms"+_26e.index));
}
if(_277){
var els=YAHOO.util.Dom.getElementsByClassName("ct-mainline-commentary","div",_277);
if(els.length>0){
_276=true;
}
}
var _279=this.movesDisplay.outputMove(this.moveIndex,_26f.ravLevel,_26f.moveNum,_274,_276,0,_26f.moveNum,_26f,_271,_272);
var _27a=document.createElement("span");
_27a.innerHTML=_279+"&nbsp;";
_27a.id=(this.boardName+"-ms"+this.moveIndex);
if(_270){
YAHOO.util.Dom.setStyle(_27a,"visibility","hidden");
}
if(_26e){
if(clog){
console.log("prevMove.index:"+_26e.index+"prevMove:"+_26e.output());
}
if(_277){
insertAfter(_27a,_277);
}else{
_273.appendChild(_27a);
}
}else{
if(_26f.next){
var _27b=YAHOO.util.Dom.get((this.boardName+"-ms"+_26f.next.index));
insertBefore(_27a,_27b);
}else{
_273.appendChild(_27a);
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+this.moveIndex);
YAHOO.util.Event.addListener((this.boardName+"-m"+this.moveIndex),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
};
Board.prototype.replaceMove=function(_27c,_27d,_27e,_27f,_280,_281){
var _282="null";
if(_27c){
_282=_27c.output();
}
if(clog){
console.log("replace newMove:"+_27d.output()+" after:"+_282+" replace as var"+_27e+" rep move display:"+_27f+" hideScore:"+_280);
if(_27c&&_27c.prev){
console.log("replace oldMove.prev:"+_27c.prev.output());
}
if(_27c&&_27c.next){
console.log("replace oldMove.next:"+_27c.next.output());
}
}
var _283=false;
var _284=null;
var _285=0;
if(_27c.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_27c.prev,_27d,false,false,_280,_281);
_27d.fen=_27c.fen;
_27d.nextFen=_27c.nextFen;
return;
}
if(_27d.equals(_27c)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_27e=false;
}else{
if(_27c&&_27c.numVars>0){
for(var i=0;i<_27c.numVars;i++){
var _287=_27c.vars[i];
if(_27d.equals(_287)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_287.output());
if(_287.next){
console.log("variation next:"+_287.next.output());
}
}
_283=true;
_284=_27c;
_27c=_287;
_285=i;
break;
}
}
}
}
if(_27c==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_27d;
_27d.atEnd=1;
_27d.next=null;
_27d.prev=null;
if(this.startPositionAfterOpponentMove){
_27d.fen=this.startPositionAfterOpponentMove;
_27d.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_27d;
}else{
var _288=false;
if(_27c&&_27c.prev&&_27c.prev.next!=_27c){
_288=true;
}
if(this.currentMove==_27c&&!_27e){
this.currentMove=_27d;
}else{
if(clog){
console.log("not setting current move in replacemove");
}
}
_27d.atEnd=_27c.atEnd;
_27d.prev=_27c.prev;
_27d.next=_27c.next;
_27d.fen=_27c.fen;
_27d.nextFen=_27c.nextFen;
_27d.bestMoves=_27c.bestMoves;
_27d.correctMove=_27c.correctMove;
_27d.wrongMove=_27c.wrongMove;
_27d.moveNum=_27c.moveNum;
_27d.ravLevel=_27c.ravLevel;
_27d.index=_27c.index;
if(clog){
console.log("replacingVariation with var not null:"+_283);
}
if(_283){
_284.vars[_285]=_27d;
_27d.vars=_27c.vars;
_27d.numVars=_27c.numVars;
this.reconnectNextNodeVariations(_27d,_27c.next);
if(_27c.next){
_27c.next.prev=_27d;
}
this.moveArray[_27d.index]=_27d;
if(clog){
console.log("replacing existing sub variation of main line");
if(_27d.next){
console.log("next of replacement variation:"+_27d.next.output());
}
}
return;
}
if(!_27e){
if(clog){
console.log("not replacing as variation");
}
if(!_288&&_27c.prev){
_27c.prev.next=_27d;
}
if(_27c.next){
_27c.next.prev=_27d;
}
_27d.vars=_27c.vars;
_27d.numVars=_27c.numVars;
this.reconnectNextNodeVariations(_27d,_27c.next);
if(this.firstMove==_27c){
this.firstMove=_27d;
}
this.moveArray[_27d.index]=_27d;
}else{
if(clog){
console.log("replacing as variation");
}
if(_27c.numVars==0){
_27c.vars=new Array();
}
_27c.vars[_27c.numVars++]=_27d;
_27c.atEnd=0;
_27d.next=null;
var _289=this.createMoveFromString("i1i2");
_27d.next=_289;
_289.prev=_27d;
_289.next=null;
_289.atEnd=1;
_289.moveNum=_27d.moveNum+1;
_289.ravLevel=_27d.ravLevel;
_289.endNode=true;
}
}
if(_27f){
this.replaceIntoMoveDisplay(_27c,_27d,_27e,_280,_281);
}
};
Board.prototype.setCurrentMove=function(move,_28b,_28c){
if(!this.cloned&&this.currentMove!=null){
if(this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.boardName+"-m"+this.currentMove.prev.index,"ct-board-move-current");
}
}
this.currentMove=move;
if(!this.cloned&&this.currentMove!=null&&this.currentMove.prev!=null){
var _28d=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_28d+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_28d);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(!_28c&&(this.scrollVariations||cls.indexOf("ct-board-move-variation")==-1)){
var _290=this.movesDisplay.getMovesDisplay();
if(_290){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_290);
var _292=new YAHOO.util.Scroll(_290,{scroll:{by:[0,y-this.scrollOffsetCorrection]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_292.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_28b){
this.setForwardBack();
}
};
Board.prototype.distanceFromInitial=function(){
var _293=this.cloneBoard();
_293.setupFromFen(Board.INITIAL_FEN);
var _294=0;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var p1=this.boardPieces[i][j];
var p2=_293.boardPieces[i][j];
if(p1==p2){
continue;
}
if(!p2){
continue;
}
if(!p1){
_294++;
continue;
}
if(p1.piece==p2.piece&&p1.colour==p2.colour){
continue;
}
_294++;
}
}
return _294;
};
Board.INITIAL_FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board.isFenLegal=function(fen){
function isLegalCastling(c){
if(!c){
return false;
}
c=c.toLowerCase();
for(var i=0;i<c.length;i++){
if(!(c.charAt(i)=="q"||c.charAt(i)=="k"||c.charAt(i)=="-")){
return false;
}
}
return true;
}
function isLegalEnpassant(m){
if(!m){
return false;
}
if(m=="-"){
return true;
}
if(m.length!=2){
return false;
}
if(m.charAt(0)<"a"||m.charAt(0)>"h"){
return false;
}
var n=parseInt(m.charAt(1));
if(isNaN(n)||n<1||n>8){
return false;
}
return true;
}
function isRowLegal(r){
if(!r){
return false;
}
r=r.toLowerCase();
for(var i=0;i<r.length;i++){
if(!isSquareCharLegal(r.charAt(i))){
return false;
}
}
return true;
}
function isSquareCharLegal(c){
switch(c){
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "p":
case "k":
case "b":
case "q":
case "r":
case "k":
return true;
default:
false;
}
}
if(!fen){
return false;
}
var ss=fen.split(" ");
if(ss.length!=6){
return false;
}
var pos=ss[0].split("/");
if(pos.length!=8){
return false;
}
if(ss[1]!="w"&&ss[1]!="b"){
return false;
}
if(isNaN(parseInt(ss[4]))){
return false;
}
if(isNaN(parseInt(ss[5]))){
return false;
}
if(!isLegalCastling(ss[2])){
return false;
}
if(!isLegalEnpassant(ss[3])){
return false;
}
return true;
};
Board.prototype.boardToUniqueFen=function(_2a3){
var fen=this.boardToFen();
var ss=fen.split(" ");
var _2a6="w";
if(_2a3==ChessPiece.BLACK){
_2a6="b";
}
var _2a7=ss[0]+" "+_2a6+" "+ss[2]+" "+ss[3];
return _2a7;
};
Board.prototype.boardToFen=function(_2a8){
var _2a9="";
for(var row=7;row>=0;row--){
var _2ab=0;
var line="";
if(row<7){
line="/";
}
for(var col=0;col<8;col++){
var _2ae=this.boardPieces[col][row];
if(_2ae){
var _2af="";
if(_2ab>0){
_2af=_2ab+"";
}
line+=_2af+_2ae.getFenLetter();
_2ab=0;
}else{
_2ab++;
}
}
if(_2ab>0){
line+=_2ab+"";
}
_2a9+=line;
}
var fen=_2a9;
var _2b1=" w ";
if(_2a8){
if(this.toMove==ChessPiece.WHITE){
_2b1=" b ";
}
}else{
if(this.toMove==ChessPiece.BLACK){
_2b1=" b ";
}
}
fen+=_2b1;
var _2b2="";
_2b2+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.WHITE);
_2b2+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.WHITE);
_2b2+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.BLACK);
_2b2+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.BLACK);
if(_2b2==""){
fen+="- ";
}else{
fen+=_2b2+" ";
}
var _2b3=null;
if(this.currentMove){
if(this.currentMove.prev){
_2b3=this.currentMove.prev;
}else{
_2b3=this.prev_move;
}
}else{
_2b3=this.prev_move;
}
var _2b4="- ";
if(_2b3){
if(_2b3){
var _2b5=this.boardPieces[_2b3.toColumn][_2b3.toRow];
if(_2b5){
if(_2b5.piece==ChessPiece.PAWN){
if(_2b5.colour==ChessPiece.WHITE){
if(_2b3.fromRow==1&&_2b3.toRow==3){
_2b4=Move.columnToChar(_2b3.fromColumn)+"3 ";
}
}else{
if(_2b3.fromRow==6&&_2b3.toRow==4){
_2b4=Move.columnToChar(_2b3.fromColumn)+"6 ";
}
}
}
}
}
}
fen+=_2b4;
fen+=this.halfMoveNumber+" "+parseInt((this.moveNumber+1)/2);
if(clog){
console.log("moveNumber:"+this.moveNumber+" fen:"+fen);
}
return fen;
};
Board.getFenCastleChar=function(_2b6,_2b7,_2b8){
if(_2b6[_2b8]){
if(_2b8==ChessPiece.WHITE){
return _2b7.toUpperCase();
}else{
return _2b7.toLowerCase();
}
}
return "";
};
Board.prototype.getCastlingString=function(_2b9){
var _2ba=_js("None");
if(this.canCastleKingSide[_2b9]){
_2ba="O-O";
}
if(this.canCastleQueenSide[_2b9]){
if(_2ba==_js("None")){
_2ba="O-O-O";
}else{
_2ba+=",O-O-O";
}
}
return _2ba;
};
Board.prototype.updateToPlay=function(){
if(this.disableUpdateToPlay){
return;
}
if(this.showToMoveIndicators){
if(this.isFlipped){
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","background-color","white");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","border","1px solid black");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","background-color","black");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","border","1px solid white");
}else{
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","background-color","white");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","border","1px solid black");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","background-color","black");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","border","1px solid white");
}
if(this.toMove==ChessPiece.WHITE){
if(this.isFlipped){
YAHOO.util.Dom.addClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
}else{
YAHOO.util.Dom.addClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
}
}else{
if(this.isFlipped){
YAHOO.util.Dom.addClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
}else{
YAHOO.util.Dom.addClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
}
}
}
var _2bb=YAHOO.util.Dom.get("toPlay");
if(_2bb==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_2bb.src="/images/whiteknight"+this.getVersString()+".gif";
_2bb.alt=_js("White to play");
}else{
_2bb.src="/images/blackknight"+this.getVersString()+".gif";
_2bb.alt=_js("Black to play");
}
var _2bc=YAHOO.util.Dom.get("fenStatus");
if(_2bc){
var _2bd=this.getCastlingString(ChessPiece.BLACK);
var _2be=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_2be+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_2bd+"</span></div>";
_2bc.innerHTML=s;
}
};
Board.prototype.getBoardDivFromId=function(id){
if(!this[id]){
this[id]=YAHOO.util.Dom.get(id);
}
return this[id];
};
Board.prototype.getBoardDiv=function(){
if(!this.boardDiv){
this.boardDiv=YAHOO.util.Dom.get("ctb-"+this.boardName);
}
return this.boardDiv;
};
Board.prototype.getDocBody=function(){
if(!this.docBody){
var _2c1=document.getElementsByTagName("body");
if(_2c1==null||_2c1.length==0){
alert("Could not find body tag");
}else{
this.docBody=_2c1[0];
}
}
return this.docBody;
};
Board.prototype.getPieceDragDiv=function(){
if(!this.pieceDragDiv){
this.pieceDragDiv=YAHOO.util.Dom.get("pieceDragDiv");
}
return this.pieceDragDiv;
};
Board.prototype.createBoardCoords=function(){
this.coordinatesShown=false;
var _2c2=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _2c3=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_2c2||!_2c3){
return;
}
YAHOO.util.Event.purgeElement(_2c2,true);
_2c3.innerHTML="";
_2c2.innerHTML="";
var _2c4=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_2c2,"display","none");
YAHOO.util.Dom.setStyle(_2c3,"display","none");
var _2c5=0;
YAHOO.util.Dom.setStyle(_2c4,"width",(this.pieceSize*8+_2c5)+"px");
YAHOO.util.Dom.setStyle(_2c4,"height",(this.pieceSize*8+_2c5)+"px");
return;
}
YAHOO.util.Dom.setStyle(_2c2,"display","block");
YAHOO.util.Dom.setStyle(_2c3,"display","block");
var _2c5=15;
var _2c6=0;
if(check_bad_msie()){
_2c6=this.ie6FixCoordsOffsetSize;
}
if(YAHOO.util.Event.isIE){
_2c6+=this.allIeFixCoordsOffsetSize;
if(document.compatMode!="CSS1Compat"){
_2c6=8;
}
}
YAHOO.util.Dom.setStyle(_2c4,"width",(this.pieceSize*8+_2c5+_2c6)+"px");
YAHOO.util.Dom.setStyle(_2c4,"height",(this.pieceSize*8+_2c5)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _2c8=document.createElement("div");
YAHOO.util.Dom.setStyle(_2c8,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_2c8,"width","15px");
YAHOO.util.Dom.setStyle(_2c8,"text-align","center");
YAHOO.util.Dom.setStyle(_2c8,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_2c8.innerHTML=""+(i+1);
}else{
_2c8.innerHTML=""+9-(i+1);
}
_2c3.appendChild(_2c8);
}
for(var i=0;i<9;i++){
var _2c9=document.createElement("span");
YAHOO.util.Dom.setStyle(_2c9,"float","left");
YAHOO.util.Dom.setStyle(_2c9,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_2c9,"width","15px");
YAHOO.util.Dom.setStyle(_2c9,"clear","both");
YAHOO.util.Dom.setStyle(_2c9,"margin-top","-5px");
if(_2c6){
YAHOO.util.Dom.setStyle(_2c9,"margin-left","-3px");
}else{
YAHOO.util.Dom.setStyle(_2c9,"margin-left","-2px");
}
var _2ca="";
if(this.isFlipped){
_2ca="whiteblack-flipper"+this.getVersString()+".png";
}else{
_2ca="blackwhite-flipper"+this.getVersString()+".png";
}
_2c9.innerHTML="<span><img id=\""+this.boardName+"-flipper\" title=\""+_js("Flip Board")+"\" src=\""+this.boardImagePath+"/images/"+_2ca+"\"/></span>";
if(!this.disableFlipper){
YAHOO.util.Event.addListener(this.boardName+"-flipper","click",this.flipBoard,this,true);
}
}else{
YAHOO.util.Dom.setStyle(_2c9,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_2c9,"text-align","center");
if(this.isFlipped){
_2c9.innerHTML=_js(Move.columnToChar(8-(i)));
}else{
_2c9.innerHTML=_js(Move.columnToChar((i-1)));
}
}
_2c2.appendChild(_2c9);
}
var _2cb=YAHOO.util.Dom.get(this.boardName+"-flipper");
if(_2cb){
fix_ie_png(_2cb);
}
};
Board.prototype.showNavigation=function(){
this.disableNavigation=false;
YAHOO.util.Dom.setStyle(this.boardName+"-ct-nav-container","display","block");
};
Board.prototype.hideNavigation=function(){
this.disableNavigation=true;
YAHOO.util.Dom.setStyle(this.boardName+"-ct-nav-container","display","none");
};
Board.prototype.createBoardUI=function(){
var _2cc=this.boardName+"-container";
var _2cd=YAHOO.util.Dom.get(_2cc);
if(_2cd==null){
alert("Could not find board container:"+_2cc);
return;
}
YAHOO.util.Dom.addClass(_2cd,"ct-board-container");
this.boardDiv=null;
var _2ce=document.createElement("div");
_2ce.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_2ce,"ct-board-border"+this.squareColorClass);
var _2cf=0;
if(this.showCoordinates){
_2cf=15;
}
YAHOO.util.Dom.setStyle(_2ce,"width",(this.pieceSize*8+_2cf)+"px");
YAHOO.util.Dom.setStyle(_2ce,"height",(this.pieceSize*8+_2cf)+"px");
var _2d0=document.createElement("div");
YAHOO.util.Dom.setStyle(_2d0,"float","left");
_2d0.id=this.boardName+"-rankLabels";
_2ce.appendChild(_2d0);
var _2d1=document.createElement("div");
YAHOO.util.Dom.addClass(_2d1,"ct-board");
YAHOO.util.Dom.setStyle(_2d1,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_2d1,"height",(this.pieceSize*8)+"px");
_2d1.id="ctb-"+this.boardName;
var _2d2="ct-white-square"+this.squareColorClass;
var _2d3="";
var _2d4=[];
for(var i=7;i>=0;i--){
var s="<div>";
for(var j=0;j<8;j++){
var _2d8=document.createElement("div");
var _2d9=this.boardName+"-s"+j+""+i;
var _2da=(((j+1)*(i+1))%19/19*100);
var _2db=((65-((j+1)*(i+1)))%19/19*100);
s+="<div id=\""+_2d9+"\" class=\""+_2d2+"\" style=\"width:"+this.pieceSize+"px;height:"+this.pieceSize+"px;background-position:"+_2da+"% "+_2db+"%\"></div>";
_2d4.push(_2d9);
_2d2=(_2d2=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_2d2=(_2d2=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
s+="</div>";
_2d3+=s;
}
_2d1.innerHTML=_2d3;
var _2dc=document.createElement("div");
_2dc.id=this.boardName+"-fileLabels";
_2ce.appendChild(_2d1);
_2ce.appendChild(_2dc);
_2cd.appendChild(_2ce);
if(this.showToMoveIndicators){
var _2dd=document.createElement("div");
_2dd.id=this.boardName+"-moveIndicators";
YAHOO.util.Dom.addClass(_2dd,"ct-move-indicators");
_2dd.innerHTML="<div class=\"ct-top-to-move-outer\" id=\""+this.boardName+"-top-to-move-outer\"><div  class=\"ct-top-to-move-inner\" id=\""+this.boardName+"-top-to-move-inner\"></div></div><div class=\"ct-bottom-to-move-outer\"  id=\""+this.boardName+"-bottom-to-move-outer\"><div class=\"ct-bottom-to-move-inner\" id=\""+this.boardName+"-bottom-to-move-inner\" ></div>";
_2cd.appendChild(_2dd);
YAHOO.util.Dom.setStyle(_2ce,"float","left");
YAHOO.util.Dom.setStyle(_2dd,"float","left");
YAHOO.util.Dom.setStyle(_2dd,"margin-left","2px");
YAHOO.util.Dom.setStyle(_2dd,"height",((this.pieceSize*8)+2)+"px");
YAHOO.util.Dom.setStyle(_2dd,"position","relative");
var _2de=document.createElement("div");
YAHOO.util.Dom.setStyle(_2de,"clear","both");
_2cd.appendChild(_2de);
}
this.createBoardCoords();
var _2df=false;
var _2e0=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_2e0){
_2e0=document.createElement("div");
}else{
_2df=true;
_2e0.innerHTML="";
}
_2e0.id=this.boardName+"-ct-nav-container";
if(!this.dontOutputNavButtons||this.r){
var _2e1="";
if(!this.dontOutputNavButtons){
if(!this.problem||!this.problem.isEndgame){
_2e1="<span id=\"playStopSpan\"><img class=\"ct-end\" id=\""+this.boardName+"-end\" src=\""+this.boardImagePath+"/images/resultset_last"+this.getVersString()+".gif\" alt=\""+_js("End position")+"\" title=\""+_js("Go to final position")+"\"/>"+"<img class=\"ct-play\" id=\""+this.boardName+"-play\" src=\""+this.boardImagePath+"/images/control_play_blue"+this.getVersString()+".gif\" alt=\""+_js("Play moves")+"\" title=\""+_js("Play sequence of moves")+"\"/>"+"<img class=\"ct-stop\" id=\""+this.boardName+"-stop\" src=\""+this.boardImagePath+"/images/control_stop_blue"+this.getVersString()+".gif\" alt=\""+_js("Stop playing")+"\" title=\""+_js("Stop playing move sequence")+"\"/></span>";
}
}
var _2e2="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\"><span id=\""+this.boardName+"-nav-buttons-only\">";
if(!this.dontOutputNavButtons){
var size="";
if(isIphone){
size=" width=\"50px\" height=\"34px\" ";
_2e1="";
}
if(!isIphone){
_2e2+="<img class=\"ct-start\" id=\""+this.boardName+"-start\" src=\""+this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif\" alt=\""+_js("Start position")+"\" title=\""+_js("Go to starting position")+"\"/>";
}
_2e2+="<img class=\"ct-back\" id=\""+this.boardName+"-back\" "+size+" src=\""+this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif\" alt=\""+_js("Previous Move")+"\" title=\""+_js("Go back a move")+"\"/>"+"<img class=\"ct-forward\" id=\""+this.boardName+"-forward\" "+size+" src=\""+this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif\" alt=\""+_js("Next Move")+"\" title=\""+_js("Go forward a move")+"\"/>"+_2e1;
}
if(this.r){
_2e2+="<img class=\"ct-forward\" id=\""+this.boardName+"-analyse\" src=\""+this.boardImagePath+"/images/anboard"+this.getVersString()+".gif\" alt=\""+_js("Analyse")+"\" title=\""+_js("Launch analysis board to explore different lines in this position")+"\"/>";
if(!this.g){
_2e2+="<img class=\"ct-forward\" id=\""+this.boardName+"-showfen\" src=\""+this.boardImagePath+"/images/copy_fen"+this.getVersString()+".gif\" alt=\""+_js("Copy FEN")+"\" title=\""+_js("Show FEN for current position")+"\"/>";
}
}
if(this.canPasteFen){
_2e2+="<img class=\"ct-forward\" id=\""+this.boardName+"-pastefen\" src=\""+this.boardImagePath+"/images/paste_fen"+this.getVersString()+".gif\" alt=\""+_js("Input FEN")+"\" title=\""+_js("Setup position from user supplied FEN or move list")+"\"/>";
}
if(this.g2){
_2e2+="<img class=\"ct-forward\" id=\""+this.boardName+"-playcomp\" src=\""+this.boardImagePath+"/images/computer"+this.getVersString()+".gif\" alt=\""+_js("Play Current Position vs Computer")+"\" title=\""+_js("Play current position against computer")+"\"/>";
}
_2e2+="</span>";
_2e2+="</div>";
if(this.puzzle){
var _2e4="";
var _2e5="";
var _2e6="";
var _2e7="";
if(this.pieceSize>=29){
_2e4=_js("Easy");
_2e5=_js("Medium");
_2e6=_js("Hard");
_2e7=_js("Help");
}else{
_2e4=_js("D1");
_2e5=_js("D2");
_2e6=_js("D3");
_2e7=_js("?");
}
_2e2+="<div><form action=\"\"><button type=\"button\" id=\""+this.boardName+"-puzzleSolution\" class=\"asolution-button\">"+_js("Show")+"</button><button id=\""+this.boardName+"-easyPuzzle\" type=\"button\" class=\"puzzle-difficulty\">"+_2e4+"</button>"+"<button id=\""+this.boardName+"-mediumPuzzle\" type=\"button\" class=\"puzzle-difficulty\">"+_2e5+"</button>"+"<button id=\""+this.boardName+"-hardPuzzle\" type=\"button\" class=\"puzzle-difficulty\">"+_2e6+"</button>"+"<button id=\""+this.boardName+"-puzzleHelp\" type=\"button\" class=\"puzzle-difficulty\">"+_2e7+"</button>"+"<img alt=\"\" class=\"ct-forward\" id=\""+this.boardName+"-problemState\"></img><span id=\""+this.boardName+"-puzzleResult\"></span></form></div>";
_2e2+="<div class=\"initially_hidden initially_invisible\" id=\""+this.boardName+"-moves\"></div>";
_2e2+="<div class=\"initially_hidden initially_invisible\" id=\""+this.boardName+"-moves\"></div>";
}
_2e0.innerHTML=_2e2;
}
if(!_2df){
_2cd.appendChild(_2e0);
}
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_2cf)+300+200+120)+"px");
}
}
};
Board.prototype.getPieceDiv=function(){
var _2e9=this.getBoardDiv();
var _2ea=document.createElement("div");
this.availPieceDivs[this.uptoId]=_2ea;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_2ea);
YAHOO.util.Dom.setStyle(_2ea,"visibility","hidden");
YAHOO.util.Dom.addClass(_2ea,"board-piece-start-style");
_2e9.appendChild(_2ea);
this.uptoId++;
return _2ea;
};
Board.prototype.flipToMove=function(_2eb){
return (_2eb=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_2ec){
var _2ed;
switch(_2ec){
case "K":
_2ed=ChessPiece.KING;
break;
case "Q":
_2ed=ChessPiece.QUEEN;
break;
case "R":
_2ed=ChessPiece.ROOK;
break;
case "B":
_2ed=ChessPiece.BISHOP;
break;
case "N":
_2ed=ChessPiece.KNIGHT;
break;
case "P":
_2ed=ChessPiece.PAWN;
break;
}
return _2ed;
};
Board.prototype.pieceTypeToChar=function(_2ee){
switch(_2ee){
case ChessPiece.KING:
return "K";
case ChessPiece.QUEEN:
return "Q";
case ChessPiece.ROOK:
return "R";
case ChessPiece.BISHOP:
return "B";
case ChessPiece.KNIGHT:
return "N";
case ChessPiece.PAWN:
return "P";
}
return "?";
};
Board.prototype.canMoveKnight=function(_2ef,_2f0,_2f1,_2f2){
if(_2ef+2==_2f1&&_2f0+1==_2f2){
return true;
}
if(_2ef+2==_2f1&&_2f0-1==_2f2){
return true;
}
if(_2ef-2==_2f1&&_2f0+1==_2f2){
return true;
}
if(_2ef-2==_2f1&&_2f0-1==_2f2){
return true;
}
if(_2ef+1==_2f1&&_2f0+2==_2f2){
return true;
}
if(_2ef-1==_2f1&&_2f0+2==_2f2){
return true;
}
if(_2ef+1==_2f1&&_2f0-2==_2f2){
return true;
}
if(_2ef-1==_2f1&&_2f0-2==_2f2){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_2f3,_2f4,_2f5,_2f6,_2f7){
var _2f8=this.boardPieces[_2f5][_2f6];
var _2f9=this.boardPieces[_2f3][_2f4];
if(_2f7){
var _2fa=this.boardPieces[_2f7.toColumn][_2f7.toRow];
if(_2fa&&_2fa.piece==ChessPiece.PAWN){
if(_2fa.colour==ChessPiece.WHITE){
if(_2f7.fromRow==1&&_2f7.toRow==3){
if(_2f5==_2f7.fromColumn&&_2f4==3&&_2f6==2&&(_2f3==_2f5+1||_2f3==_2f5-1)){
return true;
}
}
}else{
if(_2f7.fromRow==6&&_2f7.toRow==4){
if(_2f5==_2f7.fromColumn&&_2f4==4&&_2f6==5&&(_2f3==_2f5+1||_2f3==_2f5-1)){
return true;
}
}
}
}
}
if(_2f8){
if(_2f9.colour==ChessPiece.WHITE){
if((_2f3==_2f5+1||_2f3==_2f5-1)&&(_2f4==_2f6-1)){
return true;
}
}else{
if((_2f3==_2f5+1||_2f3==_2f5-1)&&(_2f4==_2f6+1)){
return true;
}
}
}else{
if(_2f3==_2f5){
if(_2f9.colour==ChessPiece.WHITE){
if(_2f4==1){
if(_2f6==2){
return true;
}else{
if(_2f6==3&&this.boardPieces[_2f5][2]==null){
return true;
}
}
}else{
if(_2f4+1==_2f6){
return true;
}
}
}else{
if(_2f4==6){
if(_2f6==5){
return true;
}else{
if(_2f6==4&&this.boardPieces[_2f5][5]==null){
return true;
}
}
}else{
if(_2f4-1==_2f6){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_2fb,_2fc,_2fd,_2fe,_2ff,_300){
var _301=_2fb;
var _302=_2fc;
var _303=0;
var _304=0;
if(_2fd>_2fb){
_303=1;
}else{
if(_2fd<_2fb){
_303=-1;
}
}
if(_2fe>_2fc){
_304=1;
}else{
if(_2fe<_2fc){
_304=-1;
}
}
if(clog){
console.log("deltaRow:"+_304+" deltaCol:"+_303+" fromCol:"+_2fb+" fromRow:"+_2fc+" toCol:"+_2fd+" toRow:"+_2fe);
}
if(_2ff==ChessPiece.ROOK&&(_303!=0&&_304!=0)){
return false;
}
if(_2ff==ChessPiece.BISHOP&&(_303==0||_304==0)){
return false;
}
var _305=0;
while(true){
_305++;
_2fb+=_303;
_2fc+=_304;
if(_2ff==ChessPiece.KING&&_305>1){
if(clog){
console.log("king count:"+_305+" toCol:"+_2fd+" toRow:"+_2fe);
}
if(_305!=2){
return false;
}
if(_304!=0){
return false;
}
if(!(_2fd==6||_2fd==2)){
return false;
}
if(_2fd==2){
if(this.boardPieces[1][_2fc]||this.boardPieces[2][_2fc]||this.boardPieces[3][_2fc]){
return false;
}
if(!this.canCastleQueenSide[_300.colour]){
return false;
}
}else{
if(_2fd==6){
if(this.boardPieces[5][_2fc]||this.boardPieces[6][_2fc]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_300.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_300.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _306="";
_306+=Move.columnToChar(_301);
_306+=String.fromCharCode("1".charCodeAt(0)+_302);
_306+=Move.columnToChar((_301+_303));
_306+=String.fromCharCode("1".charCodeAt(0)+(_302+_304));
var move=this.createMoveFromString(_306);
var _308=this.cloneBoard();
_308.makeMove(move,_308.boardPieces[_301][_302],false,this.moveAnimationLength,false,false);
kingSafe=_308.isKingSafe(_300.colour,move);
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _306="";
_306+=Move.columnToChar(_301);
_306+=String.fromCharCode("1".charCodeAt(0)+_302);
_306+=Move.columnToChar(_301);
_306+=String.fromCharCode("1".charCodeAt(0)+_302);
var move=this.createMoveFromString(_306);
var _308=this.cloneBoard();
_308.makeMove(move,_308.boardPieces[_301][_302],false,this.moveAnimationLength,false,false);
kingSafe=_308.isKingSafe(_300.colour,move);
var _308=this.cloneBoard();
_308.makeMove(move,_308.boardPieces[_301][_302],false,this.moveAnimationLength,false,false);
kingSafe=this.isKingSafe(_300.colour,move);
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_2fb==_2fd&&_2fc==_2fe){
return true;
}
if(_2fb<0||_2fb>7||_2fc<0||_2fc>7){
return false;
}
if(this.boardPieces[_2fb][_2fc]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_309,_30a,_30b,_30c,_30d){
var _30e=_309.column;
var _30f=_309.row;
if(_30a>7||_30a<0||_30b>7||_30b<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _310=this.boardPieces[_30a][_30b];
var _311=this.boardPieces[_30e][_30f];
if(_311==null){
return false;
}
if(_310&&_310.colour==_311.colour){
return false;
}
var _312=false;
if(_309.piece==ChessPiece.PAWN){
_312=this.canMovePawn(_30e,_30f,_30a,_30b,_30c);
}else{
if(_309.piece==ChessPiece.KNIGHT){
_312=this.canMoveKnight(_30e,_30f,_30a,_30b);
}else{
_312=this.canMoveStraight(_30e,_30f,_30a,_30b,_309.piece,_309);
}
}
if(clog){
console.log("moveOk:"+_312);
}
var _313=true;
if(_312&&_30d){
var _314="";
_314+=Move.columnToChar(_30e);
_314+=String.fromCharCode("1".charCodeAt(0)+_30f);
_314+=Move.columnToChar(_30a);
_314+=String.fromCharCode("1".charCodeAt(0)+_30b);
var move=this.createMoveFromString(_314);
var _316=this.cloneBoard();
_316.makeMove(move,_316.boardPieces[_30e][_30f],false,this.moveAnimationLength,false,false);
_313=_316.isKingSafe(_309.colour,move);
}
return _312&&_313;
};
Board.prototype.is50MoveRule=function(){
return (this.halfMoveNumber>=100);
};
Board.prototype.isCheckmate=function(_317){
return (!this.isKingSafe(this.toMove,_317)&&this.isKingMated(this.toMove,_317));
};
Board.prototype.isStalemate=function(_318){
return (this.isKingSafe(this.toMove,_318)&&(this.getCandidateMoves(this.toMove,_318,true)).length==0);
};
Board.prototype.isKingMated=function(_319,_31a){
var _31b=null;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.piece==ChessPiece.KING&&bp.colour==_319){
_31b=bp;
break;
}
}
}
var _31f=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_31b;
for(var k=0;k<_31f.length;k++){
if(this.canMove(bp,bp.column+_31f[k][0],bp.row+_31f[k][1],_31a,true)){
return false;
}
}
var _321=this.getCandidateMoves(_319,_31a,true,true);
if(_321.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_322,_323,_324,_325){
var _326=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _32a=[];
if(!bp||bp.colour!=_322){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_325){
continue;
}
_32a=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_32a=[[2,1],[2,-1],[-2,1],[-2,-1],[1,2],[1,-2],[-1,2],[-1,-2]];
break;
case ChessPiece.BISHOP:
for(var k=0;k<8;k++){
_32a.push([1+k,1+k]);
_32a.push([1+k,-1-k]);
_32a.push([-1-k,1+k]);
_32a.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_32a.push([1+k,0]);
_32a.push([1+k,1+k]);
_32a.push([1+k,-1-k]);
_32a.push([-1-k,0]);
_32a.push([-1-k,1+k]);
_32a.push([-1-k,-1-k]);
_32a.push([0,-1-k]);
_32a.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_32a.push([1+k,0]);
_32a.push([-1-k,0]);
_32a.push([0,-1-k]);
_32a.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
if(_322==ChessPiece.BLACK){
_32a=[[0,-1],[1,-1],[-1,-1]];
if(j==6){
_32a.push([0,-2]);
}
}else{
_32a=[[0,1],[1,1],[-1,1]];
if(j==1){
_32a.push([0,2]);
}
}
break;
}
for(var k=0;k<_32a.length;k++){
if(this.canMove(bp,bp.column+_32a[k][0],bp.row+_32a[k][1],_323,true)){
_326.push(new Move(bp.column,bp.row,bp.column+_32a[k][0],bp.row+_32a[k][1]));
if(_324){
return _326;
}
}
}
}
}
return _326;
};
Board.prototype.isKingSafe=function(_32c,_32d){
var _32e=null;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.piece==ChessPiece.KING&&bp.colour==_32c){
_32e=bp;
break;
}
}
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.colour!=_32c){
if(this.canMove(bp,_32e.column,_32e.row,_32d,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.freeBoardPieces=function(_332){
if(this.boardPieces){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
this.boardPieces[i][j].free();
this.boardPieces[i][j]=null;
}
}
if(_332){
this.boardPieces[i]=null;
}
}
}
if(_332){
this.boardPieces=null;
}
};
Board.prototype.freeBoard=function(){
this.freeBoardPieces(true);
this.freeMoveArray();
};
Board.prototype.freeMoveArray=function(){
if(this.moveArray){
for(var i=0;i<this.moveArray.length;i++){
var m=this.moveArray[i];
if(m){
m.freeMove();
this.moveArray[i]=null;
}
}
}
};
Board.prototype.cloneBoard=function(){
var _337=new Board();
_337.boardName=this.boardName;
_337.cloned=true;
_337.boardPieces=this.copyBoardPieces(true);
_337.moveArray=this.copyMoveArray(false);
_337.canCastleQueenSide=this.copyCastleQueenSide();
_337.canCastleKingSide=this.copyCastleKingSide();
_337.toMove=this.toMove;
_337.restrictedColourMovement=-1;
_337.opponentColour=this.opponentColour;
_337.isFlipped=this.isFlipped;
_337.isUserFlipped=this.isUserFlipped;
_337.ignoreFlipping=this.ignoreFlipping;
_337.reverseFlip=this.reverseFlip;
_337.moveAnimationLength=this.moveAnimationLength;
_337.moveNumber=this.moveNumber;
_337.halfMoveNumber=this.halfMoveNumber;
_337.startFen=this.startFen;
_337.boardImagePath=this.boardImagePath;
if(this.prev_move){
_337.prev_move=this.prev_move.clone();
}else{
_337.prev_move=null;
}
return _337;
};
Board.prototype.copyCastleQueenSide=function(){
return [this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
};
Board.prototype.copyCastleKingSide=function(){
return [this.canCastleKingSide[0],this.canCastleKingSide[1]];
};
Board.prototype.copyMoveArray=function(_338){
var _339=new Array();
if(!_338){
if(this.moveArray.length>0){
_339=this.moveArray.slice(0);
}
return _339;
}else{
for(var i=0;i<this.moveArray.length;i++){
var m=_339[i];
if(m){
var newM=m.clone(true);
_339[i]=newM;
}
}
return _339;
}
};
Board.prototype.copyBoardPieces=function(_33d){
var _33e=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_33d){
_33e[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_33e[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_33e[i][j]=null;
}
}
}
return _33e;
};
Board.prototype.createPiece=function(_341,_342,_343){
if(_343){
return new LightweightChessPiece(null,_341,_342,this);
}else{
return new ChessPiece(this.getPieceDiv(),_341,_342,this);
}
};
Board.prototype.restoreCastling=function(_344){
this.canCastleKingSide=_344.kingSide;
this.canCastleQueenSide=_344.queenSide;
};
Board.prototype.saveCastling=function(){
var _345=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _346=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_345,kingSide:_346};
};
var firstLightProf=true;
var firstHeavyProf=true;
Board.prototype.setupFromFenLightweight=function(fen,_348,flip,_34a,_34b){
var _34c=false&&firstLightProf;
if(_34c){
console.profile("setupFromFenLight");
}
this.setupFromFenGeneric(fen,_348,flip,true,_34a,_34b);
if(_34c){
console.profileEnd();
}
};
Board.prototype.setupFromFenHeavyWeight=function(fen,_34e,flip,_350,_351){
var _352=false&&firstHeavyProf;
if(_352){
console.profile("setupFromFenHeavy");
}
this.setupFromFenGeneric(fen,_34e,flip,false,_350,_351);
if(_352){
console.profileEnd();
}
};
Board.prototype.setupFromFen=function(fen,_354,flip,_356,_357,_358){
this.positionsSeen=[];
if(_356){
this.setupFromFenLightweight(fen,_354,flip,_357,_358);
}else{
this.setupFromFenHeavyWeight(fen,_354,flip,_357,_358);
}
};
Board.prototype.setupFromFenGeneric=function(fen,_35a,flip,_35c,_35d,_35e){
if(ctime){
console.time("setupFromFen"+_35c);
}
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
}
this.oldSelectedSquare=null;
this.oldSelectedPiece=null;
this.settingUpPosition=true;
var _35f=fen.split(" ");
var _360=_35f[0].split("/");
this.halfMoveNumber=parseInt(_35f[4]);
this.moveNumber=parseInt(_35f[5])*2;
var _361=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _363=_35f[2];
var _364=null;
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_363!="-"){
if(_363.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_363.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_363.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_363.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_35e){
this.startMoveNum=this.moveNumber;
}
if(_35f[1]=="w"){
if(_35e){
this.startMoveNum--;
}
this.toMove=ChessPiece.WHITE;
this.opponentColour=ChessPiece.WHITE;
this.isFlipped=false;
this.moveNumber--;
}else{
this.toMove=ChessPiece.BLACK;
this.opponentColour=ChessPiece.BLACK;
this.isFlipped=true;
}
if(_35d){
var _365=_35f[3];
if(_365!="-"&&_365.length==2){
var _366=_365[0];
var _367=parseInt(_365[1]);
if(_367==3){
_364=this.createMoveFromString(_366+"2"+_366+"4");
}else{
_364=this.createMoveFromString(_366+"7"+_366+"5");
}
_364.prevMoveEnpassant=true;
this.prev_move=_364;
}
}
if(_35a){
this.toMove=(ChessPiece.BLACK==this.toMove)?ChessPiece.WHITE:ChessPiece.BLACK;
this.isFlipped=!this.isFlipped;
}
if(flip){
this.isFlipped=true;
}
if(this.reverseFlip){
this.isFlipped=!this.isFlipped;
}
if(this.ignoreFlipping){
this.isFlipped=false;
}
if(this.isUserFlipped){
this.isFlipped=!this.isFlipped;
}
this.updateToPlay();
this.setupPieceDivs();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
this.boardPieces[i][j]=null;
}
}
for(var i=0;i<8;i++){
var line=_360[i];
row--;
_361=0;
for(var j=0;j<line.length;j++){
var c=line.charAt(j);
var code=line.charCodeAt(j);
var num=code-"0".charCodeAt(0);
if(num>0&&num<9){
while(num--){
var _36e=this.boardPieces[_361][row];
this.boardPieces[_361][row]=null;
_361++;
}
}else{
var _36f=(c+"").toLowerCase().charAt(0);
var _370=ChessPiece.WHITE;
if(_36f==c){
_370=ChessPiece.BLACK;
}
var cp;
switch(_36f){
case "k":
cp=this.createPiece(_370,ChessPiece.KING,_35c);
break;
case "q":
cp=this.createPiece(_370,ChessPiece.QUEEN,_35c);
break;
case "r":
cp=this.createPiece(_370,ChessPiece.ROOK,_35c);
break;
case "b":
cp=this.createPiece(_370,ChessPiece.BISHOP,_35c);
break;
case "n":
cp=this.createPiece(_370,ChessPiece.KNIGHT,_35c);
break;
case "p":
cp=this.createPiece(_370,ChessPiece.PAWN,_35c);
break;
default:
alert("unknown piece letter:"+_36f+" for fen:"+fen);
}
if(isGecko||isOpera){
cp.setPosition(_361,row,false,null,this.moveAnimationLength);
cp.setVisible(true);
}
this.boardPieces[_361][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_361;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_361++;
}
}
}
if(!isGecko){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setPosition(this.pieces[i].column,this.pieces[i].row,false,null,0);
}
}
if(!_35c){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
if(!_35c){
this.createBoardCoords();
}
this.settingUpPosition=false;
if(ctime){
console.timeEnd("setupFromFen"+_35c);
}
};
Board.prototype.resetMoveListScrollPosition=function(){
var _372=this.movesDisplay.getMovesDisplay();
if(_372){
var _373=new YAHOO.util.Scroll(_372,{scroll:{to:[0,0]}},0);
_373.animate();
}
};
Board.prototype.changePieceSet=function(_374,_375){
if(!this.showedIE6Warning){
var str=_js("Depending on your browser you may need to reload the<br/> page for piece size changes to properly take effect.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
if(check_bad_msie()){
if(!this.showedIE6Warning){
var str=_js("Internet Explorer version 6 does not support dynamic piece size changes.<br/> Please reload page to view new settings.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
return;
}
var _377=this.pieceSize;
this.pieceSet=_374;
this.pieceSize=_375;
var _378=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _379=0;
if(this.showCoordinates){
_379=15;
}
_378.className="";
YAHOO.util.Dom.addClass(_378,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_378,"width",(this.pieceSize*8+_379)+"px");
YAHOO.util.Dom.setStyle(_378,"height",(this.pieceSize*8+_379)+"px");
var _37a=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_37a,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_37a,"height",(this.pieceSize*8)+"px");
var _37b="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _37e=this.getBoardDivFromId(this.boardName+"-s"+j+""+i);
_37e.className="";
YAHOO.util.Dom.addClass(_37e,_37b);
YAHOO.util.Dom.setStyle(_37e,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_37e,"height",this.pieceSize+"px");
var _37f=(((j+1)*(i+1))%19/19*100);
var _380=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_37e,"background-position",_37f+"% "+_380+"%");
_37b=(_37b=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_37b=(_37b=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var cp=this.boardPieces[i][j];
if(cp){
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize,cp.board.addVersion);
if(YAHOO.util.Event.isIE||isOpera){
var _382=cp.div;
_382.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_382.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
}
if(this.moveArray){
var move=this.moveArray[0];
while(move!=null){
if(move.taken){
var cp=move.taken;
if(cp.getNewXYPosition){
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize,cp.board.addVersion);
if(YAHOO.util.Event.isIE||isOpera){
var _382=cp.div;
_382.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_382.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
move=move.next;
}
}
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_379)+300+200+120)+"px");
}
}
this.createBoardCoords();
};
Board.prototype.forwardMove=function(e){
if(this.disableNavigation){
return;
}
if(this.blockFowardBack||this.deferredBlockForwardBack){
if(clog){
console.log("returning early from forward due to block forward on");
}
return;
}
var _388=false;
if(this.tactics&&this.tactics.problemActive){
if(clog){
console.log("not forwarding, tactic is active");
}
return;
}
this.blockForwardBack=true;
if(this.currentMove&&!this.currentMove.atEnd){
move=this.currentMove;
if(move){
if(clog){
console.log("forward move:"+move.output());
}
}else{
if(clog){
console.log("forward move with currentmove null");
}
}
if(move.endNode){
if(clog){
console.log("calling processendgame from forward move");
}
if(!_388){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _389=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_389=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_389,true);
this.toggleToMove();
this.updateToPlay();
var _38a=this.currentMove;
if(clog){
if(_38a){
console.log("after forward curmove:"+_38a.output());
}else{
console.log("after forward cur move null");
}
}
for(var i=0;i<this.registeredForwardMovePostUpdateListeners.length;i++){
var _38c=this.registeredForwardMovePostUpdateListeners[i].forwardMovePostUpdateCallback(move);
}
}
}else{
if(clog){
console.log("already at end");
}
for(var i=0;i<this.registeredForwardAtEndListeners.length;i++){
var _38c=this.registeredForwardAtEndListeners[i].forwardAtEndCallback();
}
}
this.blockForwardBack=false;
};
Board.prototype.setupEventHandlers=function(){
this.timesLostFocus=0;
YAHOO.util.Event.addListener(document,"blur",this.lostFocus,this,true);
if(!this.avoidMouseoverActive){
YAHOO.util.Event.addListener(this.boardName+"-container","mouseover",function(e){
activeBoard=this;
},this,true);
}
if(true||this.clickAndClick){
YAHOO.util.Event.addListener(this.boardName+"-container","click",this.selectDestSquare,this,true);
}
var _38e="keydown";
if(isGecko){
_38e="keypress";
}
YAHOO.util.Event.addListener(document,_38e,function(e){
var _390=(e.target)?e.target:e.srcElement;
if(_390.form){
return true;
}
if(activeBoard!=this){
return true;
}
switch(YAHOO.util.Event.getCharCode(e)){
case 37:
this.backMove();
break;
case 39:
this.forwardMove();
break;
default:
}
return true;
},this,true);
YAHOO.util.Event.addListener(this.boardName+"-forward","click",this.forwardMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-back","click",this.backMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-start","click",this.gotoStart,this,true);
YAHOO.util.Event.addListener(this.boardName+"-end","click",this.gotoEnd,this,true);
YAHOO.util.Event.addListener(this.boardName+"-play","click",this.playMoves,this,true);
YAHOO.util.Event.addListener(this.boardName+"-stop","click",this.stopPlayingMoves,this,true);
if(this.r){
YAHOO.util.Event.addListener(this.boardName+"-analyse","click",this.analysePosition,this,true);
YAHOO.util.Event.addListener(this.boardName+"-showfen","click",this.showBoardFen,this,true);
}
if(this.canPasteFen){
YAHOO.util.Event.addListener(this.boardName+"-pastefen","click",this.pasteFen,this,true);
}
if(this.g2){
YAHOO.util.Event.addListener(this.boardName+"-playcomp","click",this.playComp,this,true);
}
};
Board.prototype.addFlipListener=function(_391){
this.registeredFlipListeners.push(_391);
};
Board.prototype.flipBoard=function(){
this.isUserFlipped=!this.isUserFlipped;
this.isFlipped=!this.isFlipped;
this.redrawBoard();
this.updateToPlay();
for(var i=0;i<this.registeredFlipListeners.length;i++){
this.registeredFlipListeners[i].boardFlipped(this);
}
};
Board.prototype.lostFocus=function(){
this.timesLostFocus++;
};
Board.prototype.redrawBoard=function(){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var cp=this.boardPieces[i][j];
if(cp){
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
}
if(this.moveArray){
var move=this.moveArray[0];
while(move!=null){
if(move.taken){
var cp=move.taken;
if(cp.getNewXYPosition){
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
move=move.next;
}
}
this.createBoardCoords();
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
}
this.oldSelectedSquare=null;
this.oldSelectedPiece=null;
if(this.highlightFromTo){
if(!this.isFlipped){
var _398=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _399=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _398=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _399=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_398,_399,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.fenPositionOnly=function(fen){
var _39b=fen.split(" ");
return _39b[0]+" "+_39b[1];
};
Board.fenStripMoveClock=function(fen){
var _39d=fen.split(" ");
return _39d[0]+" "+_39d[1]+" "+_39d[2]+" "+_39d[3];
};
Board.fenSamePosition=function(fen1,fen2,_3a0){
if(!fen1||!fen2){
return false;
}
var f1=null;
var f2=null;
if(_3a0){
f1=Board.fenPositionOnly(fen1);
f2=Board.fenPositionOnly(fen2);
}else{
f1=Board.fenStripMoveClock(fen1);
f2=Board.fenStripMoveClock(fen2);
}
return (f1==f2);
};
Board.prototype.findFen=function(mv,brd,fen,_3a6){
var res=this.findFen2(mv,brd,fen,true);
if(res.move){
return res.move;
}else{
if(_3a6){
if(res.clockStrip){
return res.clockStrip;
}else{
if(res.fullStrip){
return res.fullStrip;
}
}
}
}
return null;
};
Board.prototype.findFen2=function(mv,brd,fen,_3ab){
var _3ac=brd.cloneBoard();
var res=Object();
var _3ae=null;
var _3af=null;
res.move=null;
if(_3ab){
_3ac.gotoMoveIndex(-1,true,true,true,true);
}
var _3b0=null;
while(mv){
var _3b1=_3ac.boardToFen();
if(_3b1==fen){
res.move=_3b0;
res.clockStrip=null;
res.fullStrip=null;
return res;
}else{
if(Board.fenSamePosition(fen,_3b1)){
_3ae=_3b0;
}else{
if(Board.fenSamePosition(fen,_3b1,true)){
_3af=_3b0;
}
}
}
if(mv.atEnd){
break;
}
if(mv.vars&&mv.vars.length>0){
for(var i=0;i<mv.vars.length;i++){
var _3b3=findFen(mv.vars[i],_3ac,fen,false);
if(_3b3.move){
return _3b3;
}else{
if(_3b3.clockStrip){
_3ae=_3b3.clockStrip;
}else{
if(_3b3.fullStrip){
_3af=_3b3.fullStrip;
}
}
}
}
}
if(clog){
console.log("about to make mv:"+mv.output());
}
_3ac.makeMove(mv,_3ac.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("finished making mv");
}
_3b0=mv;
mv=mv.next;
if(clog){
console.log("toMove:"+_3ac.toMove);
}
_3ac.setCurrentMove(mv);
_3ac.toggleToMove();
}
if(_3ae){
res.clockStrip=_3ae;
}
if(_3af){
res.fullStrip=_3af;
}
return res;
};
Board.prototype.gotoFen=function(fen,_3b5){
if(clog){
console.log("about to find fen for:"+fen);
}
var _3b6=this.findFen(this.moveArray[0],this,fen,_3b5);
if(_3b6){
if(clog){
console.log("found move:"+_3b6.output()+" for fen:"+fen);
}
this.gotoMoveIndex(_3b6.index);
}else{
if(clog){
console.log("didn't find move for fen:"+fen);
}
}
};
Board.prototype.getMaxMoveIndex=function(){
return this.moveArray.length-1;
};
Board.prototype.gotoMoveIndex=function(_3b7,_3b8,_3b9,_3ba,_3bb){
if(clog){
console.log("going to move index:"+_3b7);
}
var _3bc=!_3b9;
if(!this.moveArray||this.moveArray.length<=_3b7||(_3b7==-1&&this.moveArray.length==0)){
return;
}
var _3bd=this.boardName+"-piecestaken";
var _3be=YAHOO.util.Dom.get(_3bd);
if(_3be){
_3be.innerHTML="";
}
if(_3b7==-1){
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,_3bb);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],!_3b9,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_3b8);
}else{
this.setCurrentMove(this.firstMove,_3b8);
}
if(!_3b8){
this.setForwardBack();
}
if(!_3ba){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _3c1=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_3b7);
}
}
return;
}
var _3c2=new Array();
var move=this.moveArray[_3b7];
if(clog&&move){
console.log("gotomoveindex move:"+move.output());
if(move.next){
console.log("gotomoveindex move.next:"+move.next.output());
}
if(move.prev){
console.log("gotomoveindex move.prev:"+move.prev.output());
}
}
var _3c4=0;
if(move.next!=null){
this.setCurrentMove(move.next,_3b8);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null&&!move.dummy){
_3c2[_3c4++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
if(clog){
console.log("gotomoveindex prev_move:"+this.prev_move.output());
}
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,this.moveAnimationLength,true,true);
this.updateToPlay();
}
for(var i=_3c4-1;i>=1;i--){
var move=_3c2[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,false);
this.toggleToMove();
}
if(!_3b8){
this.convertPiecesFromLightWeight(_3b7);
}
var move=_3c2[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],_3bc,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_3b8){
this.setForwardBack();
}
if(!_3ba){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _3c1=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_3b7);
}
}
};
Board.prototype.gotoStart=function(e){
if(this.disableNavigation){
return;
}
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.gotoMoveIndex(-1);
if(this.problem){
if(this.currentMove&&this.currentMove.bestMoves){
this.problem.showBestMoves(this.currentMove,this.currentMove.bestMoves,this.currentMove.correctMove,this.currentMove.wrongMove);
}else{
this.problem.clearBestMoves();
}
}
};
Board.prototype.gotoEnd=function(e){
if(this.disableNavigation){
return;
}
if(clog){
console.log("goto end called");
}
if(this.tactics&&this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
if(clog){
console.log("jumping to start");
}
this.gotoMoveIndex(-1,true,true,true);
var _3c7=0;
while(this.currentMove&&this.currentMove.next!=null){
var move=this.currentMove;
if(clog){
console.log("going to end move:"+move.output());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
_3c7=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
}
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _3ca=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_3c7);
}
};
Board.prototype.gotoPly=function(_3cb,_3cc){
if(clog){
console.log("goto ply called");
}
this.gotoMoveIndex(-1,true,true,true);
var cnt=1;
var _3ce=0;
while(cnt<=_3cb&&this.currentMove&&this.currentMove.next!=null){
var move=this.currentMove;
if(clog){
console.log("going to end move:"+move.output());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
_3ce=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
cnt++;
}
if(_3cc){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _3d1=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_3ce);
}
}
};
Board.prototype.playMove=function(self){
if(!self.keepPlayingMoves||!self.currentMove||!self.currentMove.next){
var play=YAHOO.util.Dom.get(this.boardName+"-play");
play.src=this.boardImagePath+"/images/control_play_blue"+this.getVersString()+".gif";
self.keepPlayingMoves=false;
return;
}
self.forwardMove();
setTimeout(function(){
self.playMove(self);
},self.pauseBetweenMoves);
};
Board.prototype.getVersString=function(){
var _3d4=".vers"+SITE_VERSION;
if(!this.addVersion){
_3d4="";
}
return _3d4;
};
Board.prototype.playMoves=function(e){
if(this.disableNavigation){
return;
}
this.keepPlayingMoves=true;
var play=YAHOO.util.Dom.get(this.boardName+"-play");
play.src=this.boardImagePath+"/images/disabled_control_play_blue"+this.getVersString()+".gif";
this.playMove(this);
};
Board.prototype.stopPlayingMoves=function(e){
this.keepPlayingMoves=false;
};
Board.prototype.pasteFen=function(e){
for(var i=0;i<this.registeredPasteFenClickedListeners.length;i++){
var _3da=this.registeredPasteFenClickedListeners[i].pasteFenClickedCallback();
}
};
Board.prototype.playComp=function(e){
window.open("/play-computer/"+this.boardToFen());
};
Board.prototype.showBoardFen=function(e){
var fen=this.boardToFen();
var _3de=new YAHOO.widget.SimpleDialog("fenDialog",{fixedcenter:false,visible:true,draggable:true,constraintoviewport:false,buttons:[{id:"linkbutton4",text:"Test"},{text:_js("Ok"),handler:function(){
_3de.hide();
},isDefault:true}]});
_3de.setHeader(_js("Position FEN"));
_3de.setBody("<textarea class=\"showPgn\" id=\"fenText\" rows=\"1\" readonly=\"true\" cols=\""+(fen.length+9)+"\">"+fen+"</textarea>");
_3de.render(document.body);
_3de.setFooter("<span id=\"copyToComment\"></span><span id=\"fenok\"></span>");
_3de.center();
var _3df=this;
if(this.problem&&this.problem.comments){
var _3e0=new YAHOO.widget.Button({type:"button",label:_js("Copy To Comment"),container:"fenok",onclick:{fn:function(){
_3df.copyFenToComment(fen,Board.COPY_COMMENT_PROBLEM);
_3de.hide();
}}});
}
if(this.gameComments){
var _3e1=new YAHOO.widget.Button({type:"button",label:_js("Copy To Game Comment"),container:"fenok",onclick:{fn:function(){
_3df.copyFenToComment(fen,Board.COPY_COMMENT_GAME);
_3de.hide();
}}});
}
if(this.playerComments){
var _3e2=new YAHOO.widget.Button({type:"button",label:_js("Copy To Player Comment"),container:"fenok",onclick:{fn:function(){
_3df.copyFenToComment(fen,Board.COPY_COMMENT_PLAYER);
_3de.hide();
}}});
}
if(this.openingComments){
var _3e3=new YAHOO.widget.Button({type:"button",label:_js("Copy To Opening Comment"),container:"fenok",onclick:{fn:function(){
_3df.copyFenToComment(fen,Board.COPY_COMMENT_OPENING);
_3de.hide();
}}});
}
var _3e4=new YAHOO.widget.Button({type:"button",label:_js("Ok"),container:"fenok",onclick:{fn:function(){
_3de.hide();
}}});
};
Board.prototype.copyFenToComment=function(fen,_3e6){
switch(_3e6){
case (Board.COPY_COMMENT_PROBLEM):
if(this.problem){
var flip=false;
var col=fen.split(" ")[1];
var col2=this.startFen.split(" ")[1];
if(col==col2){
flip=true;
}
this.problem.comments.copyFenToComment(fen,flip);
}
break;
case (Board.COPY_COMMENT_GAME):
this.gameComments.copyFenToComment(fen);
break;
case (Board.COPY_COMMENT_PLAYER):
this.playerComments.copyFenToComment(fen);
break;
case (Board.COPY_COMMENT_OPENING):
this.openingComments.copyFenToComment(fen);
break;
}
};
Board.COPY_COMMENT_PROBLEM=0;
Board.COPY_COMMENT_PLAYER=1;
Board.COPY_COMMENT_GAME=2;
Board.COPY_COMMENT_OPENING=3;
Board.prototype.copyAnalysisToComment=function(_3ea,fen,flip,_3ed){
switch(_3ed){
case (Board.COPY_COMMENT_PROBLEM):
if(this.problem){
this.problem.comments.copyAnalysisToComment(_3ea,fen,flip);
}
break;
case (Board.COPY_COMMENT_GAME):
this.gameComments.copyAnalysisToComment(_3ea,fen,flip);
break;
case (Board.COPY_COMMENT_PLAYER):
this.playerComments.copyAnalysisToComment(_3ea,fen,flip);
break;
case (Board.COPY_COMMENT_OPENING):
this.openingComments.copyAnalysisToComment(_3ea,fen,flip);
break;
}
};
Board.squareColours=new Array(8);
var pCol=ChessPiece.BLACK;
for(var i=0;i<8;i++){
Board.squareColours[i]=new Array(8);
for(var j=0;j<8;j++){
Board.squareColours[i][j]=pCol;
pCol=Board.invertToMove(pCol);
}
pCol=Board.invertToMove(pCol);
}
Board.getSquareColour=function(i,j){
return Board.squareColours[i][j];
};
Board.prototype.isInsufficientMaterial=function(_3f0){
var _3f1=0;
var _3f2=0;
var _3f3=0;
var _3f4=0;
var _3f5=0;
var _3f6=0;
var _3f7=0;
var _3f8=0;
var _3f9=0;
var _3fa=0;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var p=this.boardPieces[i][j];
if(p){
if(p.piece==ChessPiece.PAWN){
if(p.colour==ChessPiece.WHITE){
_3f1++;
}else{
_3f2++;
}
}else{
if(p.piece!=ChessPiece.KING){
if(p.colour==ChessPiece.WHITE){
_3f3++;
if(p.piece==ChessPiece.KNIGHT){
_3f5++;
}else{
if(p.piece==ChessPiece.BISHOP){
if(Board.getSquareColour(i,j)==ChessPiece.WHITE){
_3f7++;
}else{
_3f8++;
}
}
}
}else{
_3f4++;
if(p.piece==ChessPiece.KNIGHT){
_3f6++;
}else{
if(p.piece==ChessPiece.BISHOP){
if(Board.getSquareColour(i,j)==ChessPiece.WHITE){
_3f9++;
}else{
_3fa++;
}
}
}
}
}
}
}
}
}
function checkBothPieces(){
if(_3f1>0||_3f2>0){
return false;
}
if(_3f3==_3f4==0){
return true;
}else{
if(_3f3==_3f5&&_3f4==0){
return true;
}else{
if(_3f4==_3f6&&_3f3==0){
return true;
}else{
if(_3f3==_3f7&&_3f4==_3f9){
return true;
}else{
if(_3f3==_3f8&&_3f4==_3fa){
return true;
}else{
if(_3f4==_3f9&&_3f3==_3f7){
return true;
}else{
if(_3f3==_3fa&&_3f3==_3f8){
return true;
}
}
}
}
}
}
}
return false;
}
if(_3f0==-1){
return checkBothPieces();
}else{
if(_3f0==ChessPiece.WHITE){
if(checkBothPieces()){
return true;
}
if(_3f1==0&&_3f3==0){
return true;
}else{
if(_3f3==_3f7&&_3f4==_3f9){
return true;
}else{
if(_3f3==_3f8&&_3f4==_3fa){
return true;
}else{
if(_3f3==_3f5&&(_3f4==0&&_3f2==0)){
return true;
}
}
}
}
return false;
}else{
if(checkBothPieces()){
return true;
}
if(_3f2==0&&_3f4==0){
return true;
}else{
if(_3f4==_3f9&&_3f3==_3f7){
return true;
}else{
if(_3f4==_3fa&&_3f3==_3f8){
return true;
}else{
if(_3f4==_3f6&&(_3f3==0&&_3f1==0)){
return true;
}
}
}
}
return false;
}
}
};
Board.prototype.analysePosition=function(e){
window.parentBoard=this;
var _3ff=(this.pieceSize*8)+450+50;
var _400=(this.pieceSize*8)+250;
var _401=window.open("/windows/analyse.html","analysis_window","width="+_3ff+",height="+_400+",resizable=1,scrollbars=1,location=0,copyhistory=0,status=0,toolbar=0,menubar=0");
_401.focus();
};
Board.prototype.backMove=function(e){
if(this.disableNavigation){
return;
}
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
var _403=this.currentMove;
if(this.tactics){
if(this.tactics.problemActive){
return;
}
}
this.blockForwardBack=true;
if(this.currentMove&&this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
this.lastFromRow=null;
var col=this.toMove;
if(col==ChessPiece.WHITE){
col=ChessPiece.BLACK;
}else{
col=ChessPiece.WHITE;
}
var _405=this.boardToUniqueFen(col);
if(this.positionsSeen[_405]){
this.positionsSeen[_405]--;
}
this.toggleToMove();
this.updateToPlay();
move=this.currentMove.prev;
if(move){
if(clog){
console.log("backwards moving to prev move:"+move.output()+" from current move:"+this.currentMove.output());
}
}
this.setCurrentMove(move);
piece=this.boardPieces[move.toColumn][move.toRow];
if(!piece){
if(clog){
console.log("got empty piece in backMove");
}
}
takenPiece=move.taken;
this.board_xy=null;
piece.setPosition(move.fromColumn,move.fromRow,true,null,this.moveAnimationLength);
this.boardPieces[move.fromColumn][move.fromRow]=piece;
if(move.promotion){
piece.changePiece("p");
}
piece.setVisible(true);
this.canCastleQueenSide[0]=move.preCastleQueenSide[0];
this.canCastleQueenSide[1]=move.preCastleQueenSide[1];
this.canCastleKingSide[0]=move.preCastleKingSide[0];
this.canCastleKingSide[1]=move.preCastleKingSide[1];
this.halfMoveNumber=move.preHalfMoveNumber;
var _406=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_406=true;
}
this.moveNumber--;
if(this.moveNumber<=0){
this.moveNumber=1;
}
if(takenPiece&&!_406){
this.board_xy=null;
var _407=move.toColumn;
var _408=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_408=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_407,_408,false,null,this.moveAnimationLength);
this.boardPieces[_407][_408]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_406){
var _409=move.toRow;
var _40a;
var _40b;
if(move.fromColumn>move.toColumn){
_40a=0;
_40b=3;
}else{
_40a=7;
_40b=5;
}
var _40c=this.boardPieces[_40b][_409];
_40c.setPosition(_40a,_409,true,null,this.moveAnimationLength);
this.boardPieces[_40a][_409]=_40c;
this.boardPieces[_40b][_409]=null;
}
if(move!=null&&move.prev!=null&&move.prev.next!=move){
move=move.prev.next;
if(clog){
if(move){
console.log("moving backwards out of variation moving to:"+move.output());
}else{
console.log("jumping out of variation to null move");
}
}
}
for(var i=0;i<this.registeredBackMovePreCurrentListeners.length;i++){
var _40e=this.registeredBackMovePreCurrentListeners[i].backMovePreCurrentCallback(move,_403);
}
this.setCurrentMove(move);
this.setForwardBack();
}
this.blockForwardBack=false;
};
Board.prototype.getMovesToCurrent=function(){
var mvs=[];
var res=[];
var mv=this.currentMove;
if(!mv||!mv.prev){
return res;
}
mv=mv.prev;
while(mv){
mvs.push(mv);
mv=mv.prev;
}
for(var i=mvs.length-1;i>=0;i--){
res.push(mvs[i].toMoveString());
}
return res;
};
Board.prototype.getAllMoves=function(){
var mv=null;
if(this.moveArray&&this.moveArray.length>0){
mv=this.moveArray[0];
}else{
mv=this.firstMove;
}
if(!mv){
return [];
}
var mvs=[];
var res=[];
while(mv&&!mv.atEnd){
res.push(mv.toMoveString());
mv=mv.next;
}
return res;
};
Board.prototype.countPly=function(){
var mv=null;
if(this.moveArray&&this.moveArray.length>0){
mv=this.moveArray[0];
}else{
mv=this.firstMove;
}
var _417=0;
while(mv&&!mv.atEnd){
_417++;
mv=mv.next;
}
return _417;
};
Board.prototype.processTaken=function(_418,_419){
var _41a=this.boardName+"-piecestaken";
var _41b=YAHOO.util.Dom.get(_41a);
if(_41b){
if(_419){
var _41c=get_image_str(ChessPiece.pieceIconNames[_418.colour][_418.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_41b.innerHTML=_41b.innerHTML+"<img src=\""+_41c+"\"/>";
}else{
var _41d=_41b.innerHTML.split("<");
_41b.innerHTML="";
for(var i=1;i<_41d.length-1;i++){
_41b.innerHTML=_41b.innerHTML+"<"+_41d[i];
}
}
}
};
Pool=function(){
this.pool=new Array();
this.count=-1;
this.numGot=0;
this.numPut=0;
};
Pool.prototype.getObject=function(){
var o=null;
if(this.count>=0){
this.numGot++;
o=this.pool[this.count--];
}
return o;
};
Pool.prototype.putObject=function(o){
if(o!=null){
this.numPut++;
this.pool[++this.count]=o;
}
};
var boardPool=new Pool();
function touchHandler(_421){
var _422=_421.changedTouches,_423=_422[0],type="";
switch(_421.type){
case "touchstart":
type="mousedown";
break;
case "touchmove":
type="mousemove";
break;
case "touchend":
type="mouseup";
break;
default:
return;
}
var _425=document.createEvent("MouseEvent");
_425.initMouseEvent(type,true,true,window,1,_423.screenX,_423.screenY,_423.clientX,_423.clientY,false,false,false,false,0,null);
_423.target.dispatchEvent(_425);
_421.preventDefault();
}
function initIphone(_426){
_426.addEventListener("touchstart",touchHandler,true);
_426.addEventListener("touchmove",touchHandler,true);
_426.addEventListener("touchend",touchHandler,true);
_426.addEventListener("touchcancel",touchHandler,true);
}
FenBoard=function(fen,_428){
if(typeof _428.pieceSize=="undefined"){
_428.pieceSize=24;
}
_428.fenBoard=true;
_428.dontOutputNavButtons=true;
_428.avoidMouseoverActive=true;
this.chessapp=new ChessApp(_428);
this.chessapp.init();
this.chessapp.board.disableUpdateToPlay=true;
this.chessapp.board.setupFromFen(fen,false,false,false);
this.board=this.chessapp.board;
this.board.startFen=fen;
};


