/* Copyright 2007-2009 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+")");
};

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();
this.board=this.chessapp.board;
this.board.addUpdatePieceListener(this);
}else{
YAHOO.util.Event.addListener(window,"load",this.setup,this,true);
}
};
PgnViewer.prototype.setup=function(){
this.chessapp.init();
this.board=this.chessapp.board;
this.board.addUpdatePieceListener(this);
};
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){
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;
};
PGN=function(_24){
this.board=_24;
this.pgnGames=new Array();
this.lastShownGame=0;
};
PGN.prototype.pollPGNFromURL=function(url,_26,_27){
var _28=this;
this.getPGNFromURL(url,_26);
setTimeout(function(){
_28.pollPGNFromURL(url,_26,_27);
},_27);
};
PGN.prototype.getPGNFromURL=function(url,_2a){
YAHOO.util.Connect.asyncRequest("GET",url,{success:function(o){
this.setupFromPGN(o.responseText,_2a);
},failure:function(o){
YAHOO.log("pgn load failed:"+o.statusText+" for file:"+url);
alert("pgn load failed:"+o.statusText+" for file:"+url);
},scope:this},"emptyText");
};
PGN.prototype.getMoveFromPGNMove=function(_2d,_2e,_2f){
var _30=false;
var _31=false;
var _32=false;
var _33;
var _34=null;
var _35=false;
var _36=null;
if(_2d.charAt(_2d.length-1)=="#"){
_31=true;
_30=true;
_2d=_2d.substr(0,_2d.length-1);
}else{
if(_2d.charAt(_2d.length-1)=="+"){
_31=true;
if(_2d.length>1&&_2d.charAt(_2d.length-2)=="+"){
_30=true;
_2d=_2d.substr(0,_2d.length-2);
}else{
_2d=_2d.substr(0,_2d.length-1);
}
}
}
if(_2d=="O-O-O"){
if(_2e=="w"){
return this.board.createMoveFromString("e1c1");
}else{
return this.board.createMoveFromString("e8c8");
}
}else{
if(_2d=="O-O"){
if(_2e=="w"){
return this.board.createMoveFromString("e1g1");
}else{
return this.board.createMoveFromString("e8g8");
}
}
}
var _37=_2d.indexOf("=");
if(_37>=0){
var _38;
_34=_2d.substr(_37+1,1);
_38=_34.charAt(0);
_33=this.board.pieceCharToPieceNum(_38);
_32=true;
_2d=_2d.substr(0,_37);
}
var _39=_2d.substr(_2d.length-2,2);
var _3a=_39.charCodeAt(0)-"a".charCodeAt(0);
var _3b=_39.charCodeAt(1)-"1".charCodeAt(0);
if(_3a>7||_3a<0||_3b>7||_3b<0){
this.lastMoveFromError=__js("Error processing to Square:{TO_SQUARE} on move:{MOVE}",[["TO_SQUARE",_39],["MOVE",_2d]]);
return null;
}
if(_2d.length>2){
if(_2d.charAt(_2d.length-3)=="x"){
_35=true;
_36=_2d.substr(0,_2d.length-3);
}else{
_36=_2d.substr(0,_2d.length-2);
}
}
var _3c=new Array();
var _3d=0;
var _3e=null;
var _3f=(_2e=="w")?ChessPiece.WHITE:ChessPiece.BLACK;
switch(_2d.charAt(0)){
case "K":
case "k":
_3e=ChessPiece.KING;
break;
case "Q":
case "q":
_3e=ChessPiece.QUEEN;
break;
case "R":
case "r":
_3e=ChessPiece.ROOK;
break;
case "B":
_3e=ChessPiece.BISHOP;
break;
case "N":
case "n":
_3e=ChessPiece.KNIGHT;
break;
case "P":
case "p":
_3e=ChessPiece.PAWN;
break;
default:
_3e=ChessPiece.PAWN;
}
var _40=null;
var _41=null;
if(_36){
var _42=_36.toLowerCase().charAt(0);
if(_42==_36.charAt(0)&&_42>="a"&&_42<="h"){
_41=_42;
if(_36.length==2){
_40=_36.charAt(1);
}
}else{
if(_36.length>1){
if(_36.length==2){
var c=_36.charAt(1);
if(c>="1"&&c<="8"){
_40=c;
}else{
_41=c;
}
}else{
if(_36.length==3){
_41=_36.charAt(1);
_40=_36.charAt(2);
if(_41>="1"&&_41<="9"){
var tmp=_41;
_41=_40;
_40=tmp;
}
}else{
this.lastMoveFromError=__js("Error: unhandled fromChars:{FROM_CHARS}",[["FROM_CHARS",_36]]);
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==_3f&&bp.piece==_3e){
if(this.board.canMove(bp,_3a,_3b,_2f,true)){
var _48=String.fromCharCode("a".charCodeAt(0)+i).charAt(0);
var _49=String.fromCharCode("1".charCodeAt(0)+j).charAt(0);
if((_41==null||_41==_48)&&(_40==null||_40==_49)){
_3c[_3d++]=bp;
}else{
}
}
}
}
}
if(_3d==0){
this.lastMoveFromError=__js("no candidate pieces for:{MOVE}",[["MOVE",_2d]]);
return null;
}
if(_3d>1){
this.lastMoveFromError=__js("Ambiguous:{MOVE} with fromChars:{FROM_CHARS} disambigRow:{DISAMBIG_ROW} disambigCol:{DISAMBIG_COL}",[["MOVE",_2d],["FROM_CHARS",_36],["DISAMBIG_ROW",_40],["DISAMBIG_COL",_41]]);
return null;
}
var _4a=_3c[0];
var _4b="";
_4b+=String.fromCharCode("a".charCodeAt(0)+_4a.column);
_4b+=String.fromCharCode("1".charCodeAt(0)+_4a.row);
if(_35){
_4b+="x";
}
_4b+=_39;
if(_34){
_4b+=_34;
}
var _4c=this.board.createMoveFromString(_4b);
return _4c;
};
PGN.prototype.parseTag=function(_4d,pgn,_4f){
if(pgn.substr(_4f,_4d.length+3)=="["+_4d+" \""){
var _50=pgn.indexOf("\"",_4f+_4d.length+3);
if(_50>=0){
return pgn.substring(_4f+_4d.length+3,_50);
}
}
return null;
};
PGN.prototype.parsePGN=function(pgn,_52,_53){
if(ctime){
console.time("parsePGN");
}
pgn=pgn.replace(/^\s+|\s+$/g,"");
var _54=0;
this.pgn=pgn;
var _55=new Array();
var _56=1;
var _57=0;
this.pgnGames=new Array();
this.finishedParseCallback=_52;
this.startParseTime=new Date().getTime();
var ret=this.parsePGN_cont(_55,_56,_57,_54,_53);
var _59=new Object();
if(!ret){
_59.parsedOk=true;
_59.pgnGames=this.pgnGames;
}else{
_59.parsedOk=false;
_59.errorString=ret;
_59.pgnGames=null;
}
if(ctime){
console.timeEnd("parsePGN");
}
return _59;
};
PGN.prototype.parsePGN_cont=function(_5a,_5b,_5c,_5d,_5e){
var pgn=this.pgn;
var _60=this.board.boardName+"-progress";
var _61=YAHOO.util.Dom.get(_60);
while(_5d<pgn.length){
var _62="";
var _63="";
var _64="";
var _65="";
var _66="";
var _67="";
var _68="";
var _69="w";
var _6a=0;
var _6b=0;
var _6c=new Array();
var _6d=0;
var _6e="";
var _6f=null;
var _70=null;
var _71=new Array();
var _72=new Array();
var _73=new Array();
var _74=new Array();
var _75=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=_5d;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!="?"){
_68=tag;
}else{
tag=this.parseTag("Black",pgn,i);
if(tag&&tag!="?"){
_63=tag;
}else{
tag=this.parseTag("Result",pgn,i);
if(tag&&tag!="?"){
_62=tag;
}else{
tag=this.parseTag("Event",pgn,i);
if(tag&&tag!="?"){
_64=tag;
}else{
tag=this.parseTag("Site",pgn,i);
if(tag&&tag!="?"){
_65=tag;
}else{
tag=this.parseTag("Date",pgn,i);
if(tag&&tag!="?"){
_66=tag;
}else{
tag=this.parseTag("Round",pgn,i);
if(tag&&tag!="?"){
_67=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(_5e,err);
}
return err;
}
i=j-1;
continue;
}
if(pgn.charAt(i)=="{"){
var _7a=pgn.indexOf("}",i+1);
if(_7a>=0){
var _7b=pgn.substring(i+1,_7a);
i=_7a;
_6e+="{ "+_7b+" } ";
}else{
var err=_js("PgnViewer: Error parsing PGN. Found unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,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"){
_5b=parseInt(pgn.substring(j,i));
}
break;
}
}
if(pgn.substr(i,1)!="."){
}
this.board.setupFromFen(this.board.startFen,false,false,true,true);
_6f=this.board.prev_move;
var _7c=i;
var _7d=null;
for(i=i;i<pgn.length;i++){
var _7e=-1;
if(pgn.substr(i,3)=="1-0"||pgn.substr(i,3)=="0-1"){
_7e=3;
}else{
if(pgn.substr(i,7)=="1/2-1/2"){
_7e=7;
}else{
if(pgn.substr(i,1)=="*"){
_7e=1;
}
}
}
if(_7e>0){
_7d=pgn.substr(i,_7e);
_5d=i+_7e;
break;
}
if(pgn.charAt(i)=="["){
_5d=i;
break;
}
if(pgn.charAt(i)==" "||pgn.charAt(i)=="\t"||pgn.charAt(i)=="\n"||pgn.charAt(i)=="\r"){
_7c=i+1;
continue;
}
if(pgn.charAt(i)>="0"&&pgn.charAt(i)<="9"){
continue;
}
if(pgn.charAt(i)=="."){
var _7f=pgn.substring(_7c,i).replace(/^\s+|\s+$/g,"");
_7c=i;
while(i+1<pgn.length&&pgn.charAt(i+1)=="."){
i++;
}
if(_7c!=i){
_69="b";
}else{
_69="w";
}
_7c=i+1;
}else{
if(pgn.charAt(i)=="{"){
var _7a=pgn.indexOf("}",i+1);
if(_7a>=0){
var _7b=pgn.substring(i+1,_7a);
i=_7a;
_6e+="{ "+_7b+" } ";
}
_7c=i+1;
}else{
if(pgn.charAt(i)=="("){
_71[_6a]=this.board.boardPieces;
_72[_6a]=_69;
_74[_6a]=_6f;
_75[_6a]=_70;
this.board.boardPieces=_73[_6a];
this.board.boardPieces=this.board.copyBoardPieces(false);
_6f=_70;
_6a++;
_7c=i+1;
_6e+="( ";
}else{
if(pgn.charAt(i)==")"){
boardPool.putObject(_71[_6a]);
_6a--;
this.board.boardPieces=_71[_6a];
_69=_72[_6a];
_6f=_74[_6a];
_70=_75[_6a];
_7c=i+1;
_6e+=") ";
}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 _80=parseInt(pgn.substr(i+1,j+1));
if(_80<=9){
switch(_80){
case 1:
_6e=_6e.substr(0,_6e.length-1)+"! ";
break;
case 2:
_6e=_6e.substr(0,_6e.length-1)+"? ";
break;
case 3:
_6e=_6e.substr(0,_6e.length-1)+"!! ";
break;
case 4:
_6e=_6e.substr(0,_6e.length-1)+"?? ";
break;
case 5:
_6e=_6e.substr(0,_6e.length-1)+"!? ";
break;
case 6:
_6e=_6e.substr(0,_6e.length-1)+"?! ";
break;
case 7:
case 8:
case 9:
case 0:
default:
}
}else{
_6e+=pgn.substring(i,j+1)+" ";
}
i=j;
}
continue;
}else{
var _81=-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"){
_81=j;
break;
}
}
if(_81==-1){
_81=pgn.length;
}
var _82=_7c;
var _83=pgn.substring(_7c,_81).replace(/^\s+|\s+$/g,"");
_7c=_81;
i=_7c-1;
if(_83.length>=4&&_83.substring(0,4)=="e.p."){
continue;
}
if(_83.length==0){
var err=__js("PgnViewer: Error: got empty move endMoveInd:{ENDMOVE_INDEX} upto:{UPTO} from:{FROM}",[["ENDMOVE_INDEX",_81],["UPTO",_82],["FROM",pgn.substr(_82)]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
var _84=_83.length-1;
while(_84>=0){
if(_83.charAt(_84)=="?"){
_84--;
}else{
if(_83.charAt(_84)=="!"){
_84--;
}else{
break;
}
}
}
var _85=_83.substring(0,_84+1);
var _86=this.getMoveFromPGNMove(_85,_69,_6f);
if(_86==null){
_6e+="unknown ";
var err=__js("PgnViewer: Error parsing:{MOVE}, {ERROR_REASON}",[["MOVE",_83],["ERROR_REASON",this.lastMoveFromError]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
_70=_6f;
_6f=_86;
var _87=this.board.boardPieces[_86.fromColumn][_86.fromRow];
boardPool.putObject(_73[_6a]);
_73[_6a]=this.board.copyBoardPieces(false);
if(_87){
this.board.makeMove(_86,_87,false,0.5,false,false);
}
_6b=_6a;
_6d++;
_69=this.board.flipToMove(_69);
_6e+=_86.moveString+"|"+_83+" ";
}
}
}
}
}
}
if(_5d<i){
_5d=i;
}
var _88=pgn.indexOf("{",_5d);
var _89=pgn.indexOf("[",_5d);
if(_88>=0){
if(_89==-1||_88<_89){
var _8a=pgn.indexOf("}",_88+1);
if(_8a>=0){
var _7b=pgn.substring(_88+1,_8a);
_5d=_8a+1;
_6e+="{ "+_7b+" } ";
}else{
var err=_js("PgnViewer: Error: Unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
}
}
_6e=_6e.replace(/^\s+|\s+$/g,"");
this.board.pieceMoveDisabled=false;
if(_7d!=null){
if(_62.length==0||_62=="?"){
_62=_7d;
}
}
this.pgnGames[_5c++]=new PGNGame(_6e,this.board.startFen,_63,_68,_62,_64,_65,_66,_67,_5b);
if(_61){
_61.innerHTML="Loaded "+_5c+" 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(\""+_5a+"\",\""+_5b+"\",\""+_5c+"\",\""+_5d+"\",\""+_5e+"\");",0);
return;
}
}
if(this.finishedParseCallback){
this.finishedParseCallback(_5e);
}
return false;
};
PGN.prototype.setupFromPGN=function(pgn,_8c){
this.parsePGN(pgn,this.setupFromPGNCallback,_8c);
};
PGN.prototype.setupFromPGNCallback=function(_8d,err){
var _8f=this.board.boardName+"-progress";
var _90=YAHOO.util.Dom.get(_8f);
if(err){
alert(err);
return false;
}
if(this.pgnGames.length==0){
alert("PgnViewer: Error: Unable to find any pgn games in:"+pgn);
return false;
}
if(this.pgnGames.length==1){
var _91=0;
if(_8d){
_91=-1;
}
this.showGame(0,_91);
}else{
var _92=this.board.boardName+"-container";
var _93=YAHOO.util.Dom.get(_92);
var _94=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
var _95=document.createElement("div");
var _96="<form id=\""+this.board.boardName+"-problemSelectorForm\" action=\"\" method=\"\">";
var _97="<select id=\""+this.board.boardName+"-problemSelector\" name=\""+this.board.boardName+"-problemSelector\" style=\"width: "+this.board.pieceSize*8+"px;\">";
var _98="";
for(i=0;i<this.pgnGames.length;i++){
var _99=this.pgnGames[i];
var _9a=this.board.boardName+"-game-"+i;
var _9b=(i+1)+". "+_99.whitePlayer+" vs "+_99.blackPlayer;
if(_99.pgn_result.length>0&&_99.pgn_result!="?"&&this.board.showResult==1){
_9b+=" "+_99.pgn_result;
}
if(_99.event.length>0&&_99.event!="?"&&this.board.showEvent==1){
_9b+=" "+_99.event;
}
if(_99.round.length>0&&_99.round!="?"&&this.board.showRound==1){
_9b+=" Rnd:"+_99.round;
}
if(_99.site.length>0&&_99.site!="?"&&this.board.showSite==1){
_9b+=" "+_99.site;
}
if(_99.date.length>0&&_99.date!="?"&&this.board.showDate==1){
_9b+=" "+_99.date;
}
var sel="";
if(i==this.lastShownGame){
sel="selected=\"\"";
}
_98+="<option "+sel+" id=\""+_9a+"\" value=\""+i+"\">"+_9b+"</option>";
}
if(_94){
if(this.board.selectorBody!=_98){
_94.innerHTML=_98;
this.board.selectorBody=_98;
}
}else{
_96+=_97+_98+"</select></form>";
_95.innerHTML=_96;
_93.insertBefore(_95,_93.firstChild);
this.board.selectorBody=_98;
}
var _94=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
YAHOO.util.Event.addListener(_94,"change",this.selectGame,this,true);
var _91=0;
var _9d=0;
if(_8d){
_91=-1;
_9d=this.lastShownGame;
}
this.showGame(_9d,_91);
}
if(_90){
YAHOO.util.Dom.setStyle(_90,"visibility","hidden");
}
if(window._pvObject[this.board.boardName].finishedCallback){
window._pvObject[this.board.boardName].finishedCallback();
}
return;
};
PGN.prototype.selectGame=function(e){
var _9f=YAHOO.util.Event.getTarget(e).selectedIndex;
var _a0=0;
if(this.board.gotoEndOnRefresh){
_a0=-1;
}
this.showGame(_9f,_a0);
var _a1=this.board.boardName+"-piecestaken";
var _a2=YAHOO.util.Dom.get(_a1);
if(_a2){
_a2.innerHTML="";
}
this.board.resetMoveListScrollPosition();
};
PGN.prototype.showGame=function(_a3,_a4){
_a4=(typeof _a4=="undefined")?0:_a4;
var _a5=this.lastShownGame;
this.lastShownGame=_a3;
var _a6=this.board.moveArray;
var _a7=this.board.currentMove;
var _a8=false;
if(_a7&&_a7.atEnd){
_a8=true;
}
this.board.startFen=this.pgnGames[_a3].startFen;
this.board.setupFromFen(this.pgnGames[_a3].startFen,false,false,false);
this.board.setMoveSequence(this.pgnGames[_a3].movesseq,"NA",this.pgnGames[_a3].start_movenum,this.pgnGames[_a3].pgn_result);
var _a9=true;
var _aa=-1;
if(_a3==_a5&&_a8){
_aa=this.board.moveArray.length-1;
}
if(!Move.moveArraysEqual(_a6,this.board.moveArray)){
_a9=false;
}else{
var _ab=Move.findMoveInNewArray(_a6,this.board.moveArray,_a7);
if(_ab&&_ab.prev){
_aa=_ab.prev.index;
}
}
this.board.displayPendingMoveList();
if(this.board.moveArray.length>0){
this.board.setCurrentMove(this.board.moveArray[0]);
}
if(_a9){
if(_aa>0&&_aa<this.board.moveArray.length){
if(clog){
console.log("going to currMoveIndex:"+_aa);
}
this.board.gotoMoveIndex(_aa,false,true);
}else{
}
}else{
if(_a4==-1){
var _ac=this.board.moveArray.length-1;
if(_ac>=0){
this.board.gotoMoveIndex(_ac,false,true);
}
}else{
if(_a4!=0){
this.board.gotoMoveIndex(_a4);
}
}
if(_a4!=-1&&this.board.autoplayFirst){
this.board.forwardMove();
}
}
this.board.displayMode=true;
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;
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.scrollVariations=false;
this.pgnString=null;
this.pgnFile=null;
this.pollPGNMilliseconds=0;
this.gotoEndOnRefresh=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.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.showNPS=false;
this.squareColorClass="";
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=false;
this.previewMode=false;
this.movesFormat="default";
this.boardImagePath="http://chesstempo.com";
this.showCoordinates=false;
this.highlightFromTo=false;
this.highlightValidSquares=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;
};
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(us){
ChessPiece.init();
this.board=new Board(this.config.boardName);
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;
if(this.problem){
this.problem.autoPlayOpponent=1;
}
this.pgn=(this.config.pgnMode)?new PGN(this.board):null;
var _17=MovesDisplay.DEFAULT_DISPLAY_TYPE;
if(this.config.movesFormat=="main_on_own_line"){
_17=MovesDisplay.MAIN_ON_OWN_LINE;
}
this.movesDisplay=new MovesDisplay(this.board,_17);
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.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.pieceSize=this.config.pieceSize;
this.board.pollPGNMilliseconds=this.config.pollPGNMilliseconds;
this.board.gotoEndOnRefresh=this.config.gotoEndOnRefresh;
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.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.avoidMouseoverActive=this.config.avoidMouseoverActive;
this.board.dontCheckLeavingPage=this.config.dontCheckLeavingPage;
if(this.config.makeActive){
activeBoard=this.board;
}
if(this.problem){
this.problem.isEndgame=this.config.isEndgame;
}
if(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.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){
var _18=this;
setTimeout(function(){
_18.pgn.pollPGNFromURL(_18.config.pgnFile,_18.config.gotoEndOnRefresh,_18.config.pollPGNMilliseconds);
},_18.config.pollPGNMilliseconds);
}
}else{
if(this.config.pgnString){
this.pgn.setupFromPGN(this.config.pgnString);
}
}
}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 _19=this;
var _1a="";
if(loggedIn){
if(this.config.isEndgame){
_1a=_js("Endgame Problem Set")+": <span id=\"startProblemSetStr\">"+_js(startEndgameSetName)+"</span>";
}else{
_1a=_js("Tactics Problem Set")+": <span id=\"startProblemSetStr\">"+_js(startTacticsSetName)+"</span>";
}
}
var _1b=new YAHOO.widget.SimpleDialog("starttacticdialog1",{width:"300px",fixedcenter:true,modal:false,visible:true,draggable:true,close:false,text:"<div style=\"color:black\">"+_1a+"</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(){
this.hide();
_19.problem.getProblem();
},isDefault:true}]});
var _1c=YAHOO.util.Dom.get("ctb-"+this.board.boardName);
_1b.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]);
}
};
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 _20=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_20[prop]=o[prop];
}else{
_20[prop]=o[prop];
}
}
return _20;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_22,_23,_24,_25,_26){
var _27=".vers"+SITE_VERSION;
if(!_26){
_27="";
}
if(check_bad_msie()){
return _23+"/images/"+_24+"/"+_22+_25+_27+".png";
}else{
return _23+"/images/"+_24+"/"+_22+_25+_27+".png";
}
};
check_bad_msie=function(){
var _28=(window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
return _28;
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _2a=(img.id)?"id='"+img.id+"' ":"";
var _2b=(img.className)?"class='"+img.className+"' ":"";
var _2c=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _2d="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_2d="float:left;"+_2d;
}
if(img.align=="right"){
_2d="float:right;"+_2d;
}
if(img.parentElement.href){
_2d="cursor:hand;"+_2d;
}
var _2e="<span "+_2a+_2b+_2c+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_2d+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_2e;
};
Move=function(_2f,_30,_31,_32,_33,_34,_35){
this.fromColumn=_2f;
this.fromRow=_30;
this.toColumn=_31;
this.toRow=_32;
this.take=_33;
this.promotion=_34;
this.moveString=_35;
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(_37){
var _38=this.take;
if(_37&&_38){
_38=_38.makeLightWeight();
}
var _39=new Move(this.fromColumn,this.fromRow,this.toColumn,this.toRow,_38,this.promotion,this.moveString);
_39.moveNum=this.moveNum;
_39.atEnd=this.atEnd;
_39.beforeComment=this.beforeComment;
_39.afterComment=this.afterComment;
_39.prevMoveEnpassant=this.prevMoveEnpassant;
if(this.vars){
_39.vars=[];
var cnt=0;
for(var i=0;i<this.vars.length;i++){
_39.vars[i]=this.vars[i].clone(_37);
cnt++;
}
_39.numVars=cnt;
}
return _39;
};
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,_44){
if(a1==a2){
return _44;
}
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]==_44){
return a2[i];
}
}
return null;
};
Move.prototype.toMoveString=function(){
var _46="";
if(this.promotion){
_46=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_46;
};
function getTagValue(_47,_48){
var _49=_47.getElementsByTagName(_48);
if(_49==null){
YAHOO.log("got null node for tag:"+_48);
return null;
}
if(_49.length==0){
YAHOO.log("got empty array node for tag:"+_48);
return null;
}
if(_49[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_48);
return null;
}
if(_49[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_48);
return null;
}
if(typeof (_49[0].textContent)!="undefined"){
return _49[0].textContent;
}
return _49[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,_4d,_4e,_4f){
var id=div.id;
this.board=_4f;
this.icon=get_image_str(ChessPiece.pieceIconNames[_4d][_4e],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_4d;
this.piece=_4e;
this.id=id;
this.div=div;
var _51=_4f.getPieceDragDiv();
var _52=false;
var _53="";
if(_51==null){
_51=document.createElement("div");
_51.id="pieceDragDiv";
_52=true;
YAHOO.util.Dom.setStyle(_51,"visibility","hidden");
YAHOO.util.Dom.setStyle(_51,"border","0px");
YAHOO.util.Dom.setStyle(_51,"position","absolute");
}
this.pieceDragEl=_51;
this.pieceDragElId="pieceDragDiv";
if(_52){
var _54=this.board.getDocBody();
if(_54){
_54.appendChild(_51);
}
}
if(YAHOO.util.Event.isIE){
var _55=this.div;
_55.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_55.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){
initIphone(this.div);
}
YAHOO.util.Dom.setStyle([this.div],"position","relative");
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:true,centerFrame:true,isTarget:false});
this.initFrame();
};
ChessPiece.prototype=new YAHOO.util.DDProxy();
ChessPiece.init=function(){
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.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(_57){
switch(_57){
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.oldIsValidHandleChild=ChessPiece.prototype.isValidHandleChild;
ChessPiece.prototype.oldStartDrag=ChessPiece.prototype.startDrag;
ChessPiece.prototype.free=function(){
this.unreg();
};
ChessPiece.prototype.isValidHandleChild=function(_58){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
return this.oldIsValidHandleChild(_58);
};
ChessPiece.prototype.onDragOut=function(e,id){
this.insideBoard=false;
};
ChessPiece.prototype.onDragEnter=function(e,id){
this.insideBoard=true;
};
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.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);
}
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","visible");
};
ChessPiece.prototype.startDrag=function(x,y){
this.insideBoard=true;
var _61=null;
if(this.board.currentMove){
if(this.board.currentMove.prev){
_61=this.board.currentMove.prev;
}else{
_61=this.board.prev_move;
}
}else{
_61=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 _65=7-i;
var _66=j;
if(this.board.isFlipped){
_65=7-_65;
_66=7-_66;
}
if((_65==this.row&&_66==this.column)||this.board.canMove(this.makeLightWeight(),_66,_65,_61,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 _6b=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _6c=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_6b)/this.board.pieceSize);
var r=parseInt((y-_6c)/this.board.pieceSize);
var _6f=this.board.boardName+"-s"+c+""+(7-r);
var _70=YAHOO.util.Dom.get(_6f);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_70){
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(_70,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_70,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_70;
}
};
ChessPiece.prototype.onDragDrop=function(e,id){
if(this.board.blockFowardBack||this.board.deferredBlockForwardBack){
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 _75=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _76=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_75)/this.board.pieceSize);
var r=parseInt((y-_76)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _79=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_79=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_79&&this.board.currentMove&&!this.board.allowingFreeMovement&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
ChessPiece.prototype.removeFromParent=function(){
var _7a=this.div;
if(_7a.parentNode){
_7a.parentNode.removeChild(_7a);
}
};
ChessPiece.prototype.setVisible=function(_7b){
var _7c;
var _7d;
if(_7b){
_7d="block";
_7c="visible";
}else{
_7d="none";
_7c="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_7c);
};
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(_80){
var _81=(_80+"").toLowerCase().charAt(0);
switch(_81){
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(_82){
this.changePieceKeepImage(_82);
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){
var _83=this.div;
_83.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_83.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(_85,row){
var _87=this.board.getBoardDiv();
var _88=this.board.getXY();
var _89=_88[0];
var _8a=_88[1];
var _8b=[0,0];
if(this.board.isFlipped){
_8b[0]=_89+((7-_85)*this.board.pieceSize);
_8b[1]=_8a+((row)*this.board.pieceSize);
}else{
_8b[0]=_89+((_85)*this.board.pieceSize);
_8b[1]=_8a+((7-row)*this.board.pieceSize);
}
return _8b;
};
ChessPiece.prototype.setPosition=function(_8c,row,_8e,_8f,_90){
this.column=_8c;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _91=this.div;
var _92=null;
if(this.board.isFlipped){
_92=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_92=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _93=this.board.getBoardDivFromId(_92);
if(!_8e){
if(!this.board.settingUpPosition){
var _94=this.getNewXYPosition(_8c,row);
YAHOO.util.Dom.setXY(_91,_94,false);
}else{
if(_91.parentNode){
_91.parentNode.removeChild(_91);
}
_93.appendChild(_91);
}
this.setVisible(true);
if(_8f){
_8f();
}
}else{
var _94=this.getNewXYPosition(_8c,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 _95=new YAHOO.util.Motion(_91,{points:{to:_94}});
this.board.oldAnim=_95;
this.board.oldAnimPieceDiv=_91;
this.board.old_new_xy=_94;
_95.duration=_90;
var _96=this;
_95.onComplete.subscribe(function(){
});
if(_8f){
_95.onComplete.subscribe(_8f);
}
_95.animate();
}
};
ChessPiece.prototype.getFenLetter=function(){
var _97=ChessPiece.pieceTypeToChar(this.piece)+"";
if(this.colour!=ChessPiece.WHITE){
_97=_97.toLowerCase();
}
return _97;
};
ChessPiece.pieceTypeToChar=function(_98){
switch(_98){
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,_9a,_9b,_9c){
this.board=_9c;
this.colour=_9a;
this.piece=_9b;
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(_9e){
};
LightweightChessPiece.prototype.free=function(){
};
LightweightChessPiece.prototype.setPosition=function(_9f,row,_a1,_a2,_a3){
this.column=_9f;
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(_a5){
this.changePieceKeepImage(_a5);
};
LightweightChessPiece.prototype.changePieceKeepImage=function(_a6){
var _a7=(_a6+"").toLowerCase().charAt(0);
switch(_a7){
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(_a8,_a9){
this.board=_a8;
this.displayType=_a9;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_aa){
this.boardName=_aa;
if(_aa){
this.initTarget("ctb-"+_aa,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.currentMove=null;
this.moveIndex=-1;
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
this.isUserFlipped=false;
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(_ab){
if(_ab==ChessPiece.WHITE){
return ChessPiece.BLACK;
}else{
return ChessPiece.WHITE;
}
};
Board.boardStyleToClassName=function(_ac){
var _ad="";
switch(_ac){
case 0:
_ad="-lightgrey";
break;
case 1:
_ad="-grey";
break;
case 2:
_ad="-brown";
break;
case 3:
_ad="-green";
break;
case 4:
_ad="-woodlight";
break;
case 5:
_ad="-wooddark";
break;
case 6:
_ad="-metal";
break;
case 7:
_ad="-marblebrown";
break;
case 8:
_ad="-stucco";
break;
case 9:
_ad="-goldsilver";
break;
case 10:
_ad="-sandsnow";
break;
case 11:
_ad="-crackedstone";
break;
case 12:
_ad="-granite";
break;
case 13:
_ad="-marblegreen";
break;
case 14:
_ad="-greenwhite";
break;
default:
}
return _ad;
};
Board.createBoardArray=function(){
var _ae=boardPool.getObject();
if(_ae==null){
_ae=new Array(8);
for(var i=0;i<8;i++){
_ae[i]=new Array(8);
}
}
return _ae;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _b0=this.getBoardDiv();
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]);
}
}
}
}
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;
}
}
}
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(_b2,_b3,_b4,_b5,_b6,_b7){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_b4==null){
return;
}
this.lastFromSquare=_b2;
this.lastToSquare=_b3;
this.lastFromRow=_b4;
this.lastFromColumn=_b5;
this.lastToRow=_b6;
this.lastToColumn=_b7;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_b2,"ct-from-square");
YAHOO.util.Dom.addClass(_b3,"ct-to-square");
}
};
Board.prototype.makeMove=function(_b8,_b9,_ba,_bb,_bc,_bd,_be,_bf){
var _c0;
var _c1;
if(!this.isFlipped){
_c0=YAHOO.util.Dom.get(this.boardName+"-s"+_b8.fromColumn+""+_b8.fromRow);
_c1=YAHOO.util.Dom.get(this.boardName+"-s"+_b8.toColumn+""+_b8.toRow);
}else{
_c0=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b8.fromColumn)+""+(7-_b8.fromRow));
_c1=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b8.toColumn)+""+(7-_b8.toRow));
}
if(_bd){
this.updateFromTo(_c0,_c1,_b8.fromRow,_b8.fromColumn,_b8.toRow,_b8.toColumn);
}
var _c2=this.boardPieces[_b8.toColumn][_b8.toRow];
if(_c2!=null){
_c2.enPassant=false;
_c2.castled=false;
}
if(_b9.piece==ChessPiece.PAWN&&_b8.toColumn!=_b8.fromColumn&&this.boardPieces[_b8.toColumn][_b8.toRow]==null){
_c2=this.boardPieces[_b8.toColumn][_b8.fromRow];
this.boardPieces[_b8.toColumn][_b8.fromRow]=null;
if(_c2!=null){
_c2.enPassant=true;
}
}
var _c3=null;
if(_b9.piece==ChessPiece.KING&&Math.abs(_b8.toColumn-_b8.fromColumn)>1){
var _c4;
var _c5;
if(_b8.toColumn>_b8.fromColumn){
_c3=this.boardPieces[7][_b8.fromRow];
_c4=_b8.fromRow;
_c5=5;
this.boardPieces[7][_b8.toRow]=null;
}else{
_c3=this.boardPieces[0][_b8.fromRow];
_c4=_b8.fromRow;
_c5=3;
this.boardPieces[0][_b8.toRow]=null;
}
if(!_c3){
alert("No castle piece");
}else{
_c3.setPosition(_c5,_c4,_ba,null,_bb);
this.boardPieces[_c3.column][_c3.row]=_c3;
_c3.castled=true;
}
}
_b8.taken=_c2;
if(_c2&&_bc){
this.processTaken(_c2,true);
}
this.moveNumber++;
this.board_xy=null;
if(_b8.promotion!=null){
_b9.changePieceKeepImage(_b8.promotion);
}
_b9.setPosition(_b8.toColumn,_b8.toRow,_ba,function(){
var tp=_c2;
if(tp){
tp.setVisible(false);
}
if(_b8.promotion!=null){
_b9.changePiece(_b8.promotion);
}
if(_be){
_be.call(_bf);
}
},_bb);
if(!_ba){
if(_b8.promotion!=null){
_b9.changePiece(_b8.promotion);
}
}
this.boardPieces[_b8.fromColumn][_b8.fromRow]=null;
this.boardPieces[_b8.toColumn][_b8.toRow]=_b9;
if(_c3!=null){
_b8.taken=_c3;
}
_b8.preCastleQueenSide=new Array(2);
_b8.preCastleKingSide=new Array(2);
_b8.preCastleQueenSide[0]=this.canCastleQueenSide[0];
_b8.preCastleQueenSide[1]=this.canCastleQueenSide[1];
_b8.preCastleKingSide[0]=this.canCastleKingSide[0];
_b8.preCastleKingSide[1]=this.canCastleKingSide[1];
if(_b9.piece==ChessPiece.ROOK){
if(_b8.fromColumn==0){
this.canCastleQueenSide[_b9.colour]=false;
}else{
if(_b8.fromColumn==7){
this.canCastleKingSide[_b9.colour]=false;
}
}
}else{
if(_b9.piece==ChessPiece.KING){
this.canCastleQueenSide[_b9.colour]=false;
this.canCastleKingSide[_b9.colour]=false;
}
}
};
Board.prototype.promptPromotion=function(_c7,col,row,_ca,_cb){
_c7.prePromotionColumn=_c7.column;
_c7.prePromotionRow=_c7.row;
_c7.setPosition(col,row,false,null,this.moveAnimationLength);
var _cc=this;
var _cd=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_cd.hide();
_cc.updatePiece(_c7,col,row,_ca,_cb,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_cd.hide();
_cc.updatePiece(_c7,col,row,_ca,_cb,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_cd.hide();
_cc.updatePiece(_c7,col,row,_ca,_cb,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_cd.hide();
_cc.updatePiece(_c7,col,row,_ca,_cb,false,"n");
},isDefault:false}]});
_cd.setHeader(_js("Select Promotion Piece"));
_cd.setBody("<div></div>");
_cd.render(document.body);
};
Board.moveToLocale=function(_ce){
if(!_ce||_ce==""){
return _ce;
}
var _cf="";
for(var i=0;i<_ce.length;i++){
var _d1=_ce.charAt(i);
switch(_d1){
case "K":
_d1=_js("K");
break;
case "Q":
_d1=_js("Q");
break;
case "R":
_d1=_js("R");
break;
case "N":
_d1=_js("N");
break;
case "B":
_d1=_js("B");
break;
case "P":
_d1=_js("P");
break;
case "a":
_d1=_js("a");
break;
case "b":
_d1=_js("b");
break;
case "c":
_d1=_js("c");
break;
case "d":
_d1=_js("d");
break;
case "e":
_d1=_js("e");
break;
case "f":
_d1=_js("f");
break;
case "g":
_d1=_js("g");
break;
case "h":
_d1=_js("h");
break;
case "x":
_d1=_js("x");
break;
case "#":
_d1=_js("#");
break;
}
_cf+=_d1;
}
return _cf;
};
Board.prototype.updatePiece=function(_d2,col,row,_d5,_d6,_d7,_d8,_d9){
if(_d8){
this.board_xy=null;
if(_d2.prePromotionRow){
_d2.row=_d2.prePromotionRow;
_d2.column=_d2.prePromotionColumn;
}
}
if(_d8==null&&_d2.column==col&&_d2.row==row){
this.board_xy=null;
_d2.setPosition(_d2.column,_d2.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _da=null;
if(this.currentMove){
if(this.currentMove.prev){
_da=this.currentMove.prev;
}else{
_da=this.prev_move;
}
}else{
_da=this.prev_move;
}
if(clog){
if(this.currentMove){
console.log("updatepiece currentMove:"+this.currentMove.output());
}else{
console.log("updatepiece currentmove null");
}
}
if(!_d5&&!this.canMove(_d2.makeLightWeight(),col,row,_da,true)){
this.board_xy=null;
_d2.setPosition(_d2.column,_d2.row,false,null,0.5);
if(clog){
console.log("move not legal , move back to orig:"+this.toMove);
if(_da){
console.log("prevMove was:"+_da.output());
}else{
console.log("prevMove was null");
}
}
return;
}
var _db="";
if(_d7&&_d2.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_d2,col,row,_d5,_d6);
return;
}else{
if(_d8!=null){
_db=_d8;
}
}
var _dc=true;
var _dd="";
_dd+=Move.columnToChar(_d2.column);
_dd+=String.fromCharCode("1".charCodeAt(0)+_d2.row);
_dd+=Move.columnToChar(col);
_dd+=String.fromCharCode("1".charCodeAt(0)+(row));
if(_db){
_dd+=_db;
}
var _de=this.createMoveFromString(_dd);
var _df=this.currentMove;
if(_df){
_de.moveNum=_df.moveNum;
}
var res=null;
for(var i=0;i<this.registeredUpdateListeners.length;i++){
_e2=this.registeredUpdateListeners[i].updatePieceCallback(_db,_d2,col,row,_d5,_d6,_d7,_d8,_d9,_da,this.currentMove,_de);
if(!_e2){
return false;
}
if(!_e2.ignoreRetVal){
res=_e2;
}
}
if(!res){
return false;
}
if(res.allowMove){
var _df=res.move;
for(var i=0;i<this.registeredUpdateAllowMoveListeners.length;i++){
var _e3=this.registeredUpdateAllowMoveListeners[i].updateAllowMoveCallback(_db,_d2,col,row,_d5,_d6,_d7,_d8,_d9,_df);
}
YAHOO.log("Made correct move");
this.makeMove(_df,_d2,_d6,this.moveAnimationLength,true,true);
var _e4=!res.dontMakeOpponentMove&&!_d5&&(this.currentMove&&this.currentMove.next&&!this.currentMove.next.atEnd);
if(clog){
if(_df.next){
console.log("setting current move in updatepiece to:"+_df.next.output());
}else{
console.log("in updatepiece, current move being set to null");
}
}
this.setCurrentMove(_df.next,false,_e4);
if(this.currentMove.atEnd){
for(var i=0;i<this.registeredUpdateEndOfMovesListeners.length;i++){
var res=this.registeredUpdateEndOfMovesListeners[i].updateEndOfMovesCallback(_db,_d2,col,row,_d5,_d6,_d7,_d8,_d9);
}
}
if(_e4){
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 _df=res.move;
var _e5=_d2.column;
var _e6=_d2.row;
this.board_xy=null;
_d2.setPosition(_d2.column,_d2.row,false,null,this.moveAnimationLength);
for(var i=0;i<this.registeredUpdateWrongMoveListeners.length;i++){
var res=this.registeredUpdateWrongMoveListeners[i].updateWrongMoveCallback(_db,_d2,col,row,_d5,_d6,_d7,_d8,_d9,_df);
}
}
for(var i=0;i<this.registeredUpdatePieceFinishedListeners.length;i++){
var _e2=this.registeredUpdatePieceFinishedListeners[i].updatePieceFinishedCallback(_db,_d2,col,row,_d5,_d6,_d7,_d8,_d9,_da,this.currentMove,_de);
}
};
Board.prototype.addGotoMoveIndexListener=function(_e7){
this.registeredGotoMoveIndexListeners.push(_e7);
};
Board.prototype.addPasteFenClickedListener=function(_e8){
this.registeredPasteFenClickedListeners.push(_e8);
};
Board.prototype.addBackMovePreCurrentListener=function(_e9){
this.registeredBackMovePreCurrentListeners.push(_e9);
};
Board.prototype.addForwardMovePostUpdateListener=function(_ea){
this.registeredForwardMovePostUpdateListeners.push(_ea);
};
Board.prototype.addForwardAtEndListener=function(_eb){
this.registeredForwardAtEndListeners.push(_eb);
};
Board.prototype.addUpdatePieceListener=function(_ec){
this.registeredUpdateListeners.push(_ec);
};
Board.prototype.addUpdatePieceFinishedListener=function(_ed){
this.registeredUpdatePieceFinishedListeners.push(_ed);
};
Board.prototype.addUpdatePieceEndOfMovesListener=function(_ee){
this.registeredUpdateEndOfMovesListeners.push(_ee);
};
Board.prototype.addUpdatePieceHaveAltListener=function(_ef){
this.registeredUpdateHaveAltListeners.push(_ef);
};
Board.prototype.addUpdatePieceAllowMoveListener=function(_f0){
this.registeredUpdateAllowMoveListeners.push(_f0);
};
Board.prototype.addUpdatePieceWrongMoveListener=function(_f1){
this.registeredUpdateWrongMoveListeners.push(_f1);
};
Board.prototype.scoreToShortString=function(_f2){
if(_f2=="draw"){
return "D";
}
if(_f2>=0){
return "M"+_f2;
}else{
return "L"+(-1*_f2);
}
};
Board.prototype.scoreToLongString=function(_f3){
if(_f3=="draw"){
return _js("Draw");
}
if(_f3==0){
return _js("Mate");
}else{
if(_f3>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_f3]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_f3)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_f4){
var _f5=_f4.score;
var _f6=_f4.optimal_score;
var s=this.scoreToShortString(_f5);
var opt=this.scoreToShortString(_f6);
var _f9=this.scoreToLongString(_f5);
var _fa=this.scoreToLongString(_f6);
if(_f5==_f6){
return ["",_f9];
}else{
var _fb="ct-subopt-move-score";
if(_f5=="draw"||_f5<0){
_fb="ct-bad-move-score";
}
return ["<span class=\""+_fb+"\">"+s+"("+opt+")</span>",_f9+"("+_fa+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_fc,_fd,_fe,_ff,_100){
if(clog){
console.log("fromCol:"+_fc+" fromRow:"+_fd+" toCol:"+_fe+" toRow:"+_ff);
}
var _101=this.boardPieces[_fc][_fd];
var _102=_101.piece;
var _103=ChessPiece.pieceTypeToChar(_102);
var move="";
if(_102==ChessPiece.PAWN){
if(_fc==_fe){
move=Move.columnToChar(_fc)+""+(_ff+1);
}else{
move=Move.columnToChar(_fc)+"x"+Move.columnToChar(_fe)+""+(_ff+1);
if(!this.boardPieces[_fe][_ff]){
move+=" e.p.";
}
}
}else{
if(_102==ChessPiece.KING){
var _105=Math.abs(_fc-_fe);
if(_105==1||_105==0){
move=_103;
if(this.boardPieces[_fe][_ff]){
move+="x";
}
move+=Move.columnToChar(_fe)+""+(_ff+1);
}else{
if(_fe==6){
move="O-O";
}else{
move="O-O-O";
}
}
}else{
var _106=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_101.colour&&cp.piece==_102&&!(_101.column==cp.column&&_101.row==cp.row)){
var prev=null;
if(this.currentMove){
prev=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_fe,_ff,prev,true)){
_106.push(cp);
}
}
}
}
move=_103;
if(_106.length>0){
var _10b=false;
var _10c=false;
for(var i=0;i<_106.length;i++){
if(_106[i].row==_fd){
_10c=true;
}
if(_106[i].column==_fc){
_10b=true;
}
}
if(_10c||!(_10c||_10b)){
move+=Move.columnToChar(_fc);
}
if(_10b){
move+=""+(_fd+1);
}
}
if(this.boardPieces[_fe][_ff]){
move+="x";
}
move+=Move.columnToChar(_fe)+""+(_ff+1);
}
}
var _10e="";
var _10f="";
if(_100){
var _110=this.cloneBoard();
var _111=ChessPiece.WHITE;
if(_110.boardPieces[_100.fromColumn][_100.fromRow].colour==ChessPiece.WHITE){
_111=ChessPiece.BLACK;
}
_110.makeMove(_100,_110.boardPieces[_100.fromColumn][_100.fromRow],false,_110.moveAnimationLength,false,false);
if(!_110.isKingSafe(_111,_100)){
_10e="+";
if(_110.isKingMated(_111,_100)){
_10e="#";
}
}
if(_100.promotion){
_10f="="+((_100.promotion+"").toUpperCase());
}
}
move+=_10f+_10e;
return move;
};
Board.getVarMove=function(move,row,col,_115,_116){
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _118=move.vars[i];
if(_118.fromColumn==_115.column&&_118.fromRow==_115.row&&_118.toRow==row&&_118.toColumn==col&&(_116==""||(_116==_118.promotion))){
return _118;
}
}
}
};
Board.prototype.createMoveFromString=function(_119){
var _11a=0;
var take=false;
var _11c=null;
var _11d=_119.charCodeAt(_11a++);
var _11e=_119.charCodeAt(_11a++);
var _11f=_119.split("|");
var pgn=null;
if(_11f.length>1){
pgn=_11f[1];
_119=_11f[0];
}else{
_119=_11f[0];
}
if(_119.charAt(_11a)=="x"){
_11a++;
take=true;
}
var _121=_119.charCodeAt(_11a++);
var _122=_119.charCodeAt(_11a++);
if(_11a<_119.length){
_11c=_119.charAt(_11a);
}
var move=new Move(_11d-("a".charCodeAt(0)),_11e-("1".charCodeAt(0)),_121-("a".charCodeAt(0)),_122-("1".charCodeAt(0)),take,_11c,_119);
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 _125=this.getForwardButton();
var end=this.getEndButton();
var _127=this.getStartButton();
if(!this.currentMove){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_127){
_127.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
if(_125){
_125.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(_127){
_127.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
}else{
if(back){
back.src=this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif";
}
if(_127){
_127.src=this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif";
}
}
if(this.currentMove.atEnd){
if(_125){
_125.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(_125){
_125.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(_128){
var _129=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 _12c=this.boardPieces[i][j];
var p=_12c.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var move=this.moveArray[_128];
while(move!=null){
if(move.taken){
move.taken=move.taken.makeHeavyWeight();
}
move=move.prev;
}
this.settingUpPosition=_129;
};
MovesDisplay.prototype.setToMove=function(_12f){
this.toMove=_12f;
};
MovesDisplay.prototype.gotoMove=function(e){
if(this.board.tactics&&this.board.tactics.problemActive){
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 _132=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_132);
}
this.board.gotoMoveIndex(_132,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){
this.cachedMovesDisplay=YAHOO.util.Dom.get(this.board.boardName+"-moves");
this.allreadyCachedMovesDisplay=true;
}
return this.cachedMovesDisplay;
};
MovesDisplay.prototype.outputVariationStart=function(_133,_134,_135,_136){
var _137="";
if(_134>this.board.ml){
return _137;
}
if(this.board.ml==1&&_136>1){
return _137;
}
var _138=this.getMovesDisplay();
if(_138){
if(_133==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_137+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
_137+="<br/>";
}
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_133>0)){
_137+="<span>"+this.board.variationStartString+"</span>";
}
}
this.firstNonMove=false;
return _137;
};
MovesDisplay.prototype.outputVariationEnd=function(_139,_13a,_13b,_13c){
var _13d=this.getMovesDisplay();
var _13e="";
if(this.board.ml==1&&_13a>0&&this.board.outputFirstVar){
return _13e;
}
this.board.outputFirstVar=true;
if(_13d){
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_139>1)){
_13e+="<span>"+this.board.variationEndString+"</span>";
}
}
if(_139==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _13e;
};
MovesDisplay.prototype.outputComment=function(_13f,_140,_141){
if(this.board.ignoreCommentRegex){
var _142=new RegExp(this.board.ignoreCommentRegex);
if(_142.test(_13f)){
return "";
}
}
var _143="";
if(this.board.ml==1){
return _143;
}
var _144=this.getMovesDisplay();
if(_144){
if(_140==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_143+="<br/>";
}
_143+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _145="ct-board-move-comment";
if(_141){
_145="ct-board-move-alt-comment";
}
_143+="<span class=\""+_145+"\"> "+_13f+" </span>";
if(_140==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _143;
};
MovesDisplay.prototype.outputNag=function(_146){
var _147="";
var _148=this.getMovesDisplay();
if(_148){
var _149=null;
switch(_146){
case 11:
_149="=";
break;
case 14:
_149="+=";
break;
case 15:
_149="=+";
break;
case 16:
_149="+/-";
break;
case 17:
_149="-/+";
break;
case 18:
_149="+-";
break;
case 19:
_149="-+";
break;
case 20:
_149="+--";
break;
case 21:
_149="--+";
break;
default:
}
if(_149){
_147+="<span> "+_149+" </span>";
}
}
return _147;
};
MovesDisplay.prototype.outputResult=function(_14a){
return "<span class=\"ct-result\">"+_14a+"</span>";
};
MovesDisplay.prototype.outputMove=function(_14b,_14c,_14d,_14e,_14f,_150,_151,move,_153,_154){
if(clog){
console.log("outputMove:"+_14e+" hideScore:"+_153);
}
var _155="";
var _156=this.getMovesDisplay();
if(this.board.tr&&_14c>0&&(_150>1||_151>3)&&!_14f){
return _155;
}
if(this.board.ml==1&&_150>0&&this.board.outputFirstVar){
return _155;
}
if(_156){
var _157=""+Math.round(_14d/2)+". ";
if(_14d%2!=1){
if(clog){
console.log("firstRav:"+_14f+" firstNonMove:"+this.firstNonMove);
}
if(_14f||!this.firstNonMove){
_157=Math.round(_14d/2)+"... ";
}else{
_157="";
}
}
if(clog){
console.log("moveNum:"+_14d+" moveNumOut:"+_157);
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_14c==0&&(!this.firstNonMove||_14d%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_155+="</div>";
}
if(this.board.newlineForEachMainMove){
_155+="<br/>";
}
}
var _158="";
var _159="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_158=res[0];
_159=res[1];
}
var _15b="";
if(_153){
_15b="initially_hidden";
}
if(_158!=""){
_158=" "+_158;
}
var _15c="title";
if(_153){
_15c="alt";
}
var _15d="";
if(_154){
_15d=" rel=\""+_14e+"\" ";
_14e="___";
}
_155+="<span "+_15d+_15c+"=\""+_159+"\" id=\""+this.board.boardName+"-m"+_14b+"\" class=\""+((_14c==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_157+_14e+"<span id=\""+this.board.boardName+"-msc"+_14b+"\" class=\""+_15b+"\">"+_158+"</span></span>";
}
this.firstNonMove=true;
return _155;
};
Board.prototype.setMoveSeqLalg=function(_15e,_15f,_160,_161){
var _162=new Array();
if(_15e&&_15e.length>0){
_162=_15e.replace(/\s+$/g,"").split(" ");
}
this.setupFromLalgArray(_162,_161,_160,_15f);
};
Board.prototype.setupFromLalgArray=function(_163,_164,_165,_166){
this.outputFirstVar=false;
if(this.movesDisplay){
var md=this.movesDisplay.getMovesDisplay();
if(md){
YAHOO.util.Event.purgeElement(md,true);
}
}
if(!_166){
_166=new Array();
}
var _168=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _169=new Array();
var _16a=new Array();
if(this.prev_move){
_168.makeMove(this.prev_move,_168.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_168.moveAnimationLength,false,false);
}
var _16b=_168.cloneBoard();
var _16c=null;
var _16d=0;
var _16e="";
var _16f=false;
var _170=false;
var _171=0;
var _172=false;
var _173=new Array();
var _174=new Array();
_174[0]=0;
var _175=new Array();
var _176=new Array();
var _177=_165*2-1;
var _178=_165*2-1;
var _179=new Array();
var _17a=ChessPiece.WHITE;
var _17b=0;
var eval="";
var _17d="";
var _17e="";
var time="";
var _180=-1;
var _181=0;
for(var i=0;i<_163.length;i++){
var _183=0;
if(_163[i]=="ALT"){
_170=true;
continue;
}
if(_163[i].indexOf("EVAL")==0){
eval=_163[i].split(":")[1];
if(parseInt(eval)>=175&&_171>0&&_174[_171]>1){
_170=true;
}
continue;
}
if(_163[i].indexOf("DEPTH")==0){
_17d=_163[i].split(":")[1];
continue;
}
if(_163[i].indexOf("NODES")==0){
_17e=_163[i].split(":")[1];
continue;
}
if(_163[i].indexOf("TIME")==0){
time=_163[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 _185=e.split(" ");
_183=parseInt(_185[1]);
e=_js("mate")+" "+_185[1];
if(_174[_171]==1){
_180=_183;
}
}
_181=_183;
if(_183<0){
_170=false;
}else{
if(_183>0&&_183<8&&_171>0&&_174[_171]>1){
_170=true;
}
}
var _186="";
if(_170){
_186=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_17e)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_171>0&&_174[_171]>this.ml)){
_163[i]=_186+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_17d]])+nps+")";
}else{
_163[i]="";
}
}
if(_163[i]=="}"){
_16f=false;
if(this.movesDisplay){
_16e=_16e.replace(/\s+$/g,"");
_179.push(this.movesDisplay.outputComment(_16e,_171,_170));
}
continue;
}else{
if(_16f){
_16e+=_163[i]+" ";
continue;
}else{
if(_163[i]=="{"){
_16e="";
_16f=true;
continue;
}else{
if(_163[i]=="("){
if(!_174[_171+1]){
_174[_171+1]=0;
}
_174[_171+1]++;
if(this.movesDisplay){
_179.push(this.movesDisplay.outputVariationStart(_171,_174[_171+1],_177,_173[0]));
}
_173[_171]=_177;
_175[_171]=_16c;
_176[_171]=_17a;
_169[_171]=_168;
_16a[_171]=_16b;
_168=_16b.cloneBoard();
_171++;
_177--;
_172=true;
continue;
}else{
if(_163[i]==")"){
if(this.movesDisplay){
_179.push(this.movesDisplay.outputVariationEnd(_171,_174[_171],_177,_173[0]));
}
var _189=new Move();
_189.atEnd=true;
_16c.next=_189;
_189.prev=_16c;
_171--;
_177=_173[_171];
_16c=_175[_171];
_17a=_176[_171];
_168=_169[_171];
_16b=_16a[_171];
_170=false;
continue;
}else{
if(_163[i].charAt(0)=="$"){
if(this.movesDisplay){
_179.push(this.movesDisplay.outputNag(parseInt(_163[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_163[i]);
var _18b=false;
if(_177==_178&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_177++;
_18b=true;
_17a=ChessPiece.BLACK;
}
move.index=_16d;
var _18c=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_18c=move.pgn;
}else{
_18c=_168.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_18c;
}
_18c=Board.moveToLocale(_18c);
if(this.movesDisplay){
this.movesDisplay.setToMove(_17a);
_179.push(this.movesDisplay.outputMove(_16d,_171,_177,_18c+" ",_172,_174[_171],_173[0]));
}
_17a=(_17a==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_177;
_177++;
if(_171>0){
if(_172){
var _18d=_16c;
if(_18d==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_18d.numVars==0){
_18d.vars=new Array();
}
move.isAlt=_170;
move.mateInMoves=_181;
_18d.vars[_18d.numVars++]=move;
move.prev=_18d.prev;
_172=false;
}else{
move.prev=_16c;
if(_16c!=null){
_16c.next=move;
}
}
}else{
move.prev=_16c;
if(_16c!=null){
_16c.next=move;
}
}
_174[_171+1]=0;
if(_171==0){
_17b=_16d;
}
_166[_16d++]=move;
_168.moveArray[_16d-1]=move;
_16c=move;
_16b=_168.cloneBoard();
_168.makeMove(move,_168.boardPieces[move.fromColumn][move.fromRow],false,_168.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _18e=this.movesDisplay.getMovesDisplay();
_179.push(this.movesDisplay.outputResult(_164));
this.pendingMovesOutput=_179.join("");
this.pendingMovesOutputCount=_16d;
}
this.lastMoveIndex=_17b;
if(_16c!=null){
var _189=new Move();
_189.atEnd=true;
_16c.next=_189;
_189.prev=_16c;
}
this.lastCount=_16d;
};
Board.prototype.getMaterialCount=function(){
var _18f=0;
var _190=0;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _193=this.boardPieces[i][j];
if(_193){
if(_193.colour==ChessPiece.WHITE){
_18f+=ChessPiece.materialValue(_193.piece);
}else{
_190+=ChessPiece.materialValue(_193.piece);
}
}
}
}
return [_18f,_190];
};
Board.prototype.getMaterialBalance=function(){
var cnt=this.getMaterialCount();
return cnt[0]-cnt[1];
};
Board.prototype.getMaterialBalances=function(){
var _195=this.cloneBoard();
var mv=this.moveArray[0];
_195.gotoMoveIndex(-1,true,true,true,true);
var _197=[];
while(mv&&!mv.atEnd){
_195.makeMove(mv,_195.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
_197.push(_195.getMaterialBalance());
mv=mv.next;
_195.toggleToMove();
}
return _197;
};
Board.prototype.lalgToMoveList=function(_198,_199,_19a,_19b,_19c){
if(ctime){
console.time("lalgToMoveList");
}
if(clog){
console.log("startMoveNum:"+_19a);
}
if(!_19b){
_19b=new Array();
}
var _19d=this.cloneBoard();
var _19e=new Array();
var _19f=new Array();
if(!_19c&&this.prev_move){
_19d.makeMove(this.prev_move,_19d.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_19d.moveAnimationLength,false,false);
}
var _1a0=_19d.cloneBoard();
var nags=[];
var _1a2=null;
var _1a3=0;
var _1a4="";
var _1a5=false;
var _1a6=0;
var _1a7=false;
var _1a8=new Array();
var _1a9=new Array();
_1a9[0]=0;
var _1aa=new Array();
var _1ab=new Array();
var _1ac=_19a*2-1;
var _1ad=new Array();
var _1ae=ChessPiece.WHITE;
var _1af=0;
var _1b0=true;
for(var i=0;i<_198.length;i++){
if(_198[i]=="}"){
_1a5=false;
_1a4=_1a4.replace(/\s+$/g,"");
continue;
}else{
if(_1a5){
_1a4+=_198[i]+" ";
continue;
}else{
if(_198[i]=="{"){
if(_1a4){
if(_1a2){
_1a2.afterComment=trimStr(_1a4);
}
}
_1a4="";
_1a5=true;
continue;
}else{
if(_198[i]=="("){
if(clog){
console.log("var start comment:"+_1a4);
}
if(_1a2){
_1a2.afterComment=trimStr(_1a4);
_1a4="";
}
if(clog){
if(_1a2){
console.log("old:"+_1a2.output());
}else{
console.log("no old move");
}
}
if(!_1a9[_1a6+1]){
_1a9[_1a6+1]=0;
}
_1a9[_1a6+1]++;
_1a8[_1a6]=_1ac;
_1aa[_1a6]=_1a2;
_1ab[_1a6]=_1ae;
_19e[_1a6]=_19d;
_19f[_1a6]=_1a0;
_19d=_1a0.cloneBoard();
_1a6++;
_1ac--;
_1a7=true;
continue;
}else{
if(_198[i]==")"){
if(_1a2){
if(clog){
console.log("var end comment:"+_1a4);
console.log("var end comment:"+_1a2.output());
}
_1a2.afterComment=trimStr(_1a4);
_1a4="";
}
var _1b2=new Move();
_1b2.atEnd=true;
_1a2.next=_1b2;
_1b2.prev=_1a2;
_1a6--;
_1ac=_1a8[_1a6];
_1a2=_1aa[_1a6];
_1ae=_1ab[_1a6];
_19d=_19e[_1a6];
_1a0=_19f[_1a6];
continue;
}else{
if(_198[i].charAt(0)=="$"){
nags.push(parseInt(_198[i].substring(1)));
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_198[i]);
move.nags=nags;
move.beforeComment=trimStr(_1a4);
_1a4=null;
nags=[];
if(_1b0){
if(this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1ac++;
_1ae=ChessPiece.BLACK;
if(clog){
console.log("first move black new movenum:"+_1ac);
}
}
_1b0=false;
}
move.index=_1a3;
var _1b4=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1b4=move.pgn;
move.SAN=move.pgn;
}else{
_1b4=_19d.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1b4;
}
_1ae=(_1ae==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_1ac;
_1ac++;
if(_1a6>0){
if(_1a7){
var _1b5=_1a2;
if(_1b5==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1b5.numVars==0){
_1b5.vars=new Array();
}
_1b5.vars[_1b5.numVars++]=move;
move.prev=_1b5.prev;
_1a7=false;
}else{
move.prev=_1a2;
if(_1a2!=null){
_1a2.next=move;
}
}
}else{
move.prev=_1a2;
if(_1a2!=null){
_1a2.next=move;
}
}
_1a9[_1a6+1]=0;
if(_1a6==0){
_1af=_1a3;
}
_19b[_1a3++]=move;
_19d.moveArray[_1a3-1]=move;
_1a2=move;
_1a0=_19d.cloneBoard();
_19d.makeMove(move,_19d.boardPieces[move.fromColumn][move.fromRow],false,_19d.moveAnimationLength,false,false);
}
if(_1a2!=null){
var _1b2=new Move();
_1b2.atEnd=true;
_1a2.next=_1b2;
_1b2.prev=_1a2;
if(_1a4){
_1a2.afterComment=trimStr(_1a4);
}
}
if(ctime){
console.timeEnd("lalgToMoveList");
}
return _19b;
};
Board.prototype.reset=function(fen){
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,false,true);
}else{
this.startFen=Board.INITIAL_FEN;
this.setupFromFen(Board.INITIAL_FEN,false,this.isFlipped,false,false,true);
}
this.setForwardBack();
};
Board.prototype.clearMoveList=function(_1b7){
this.movesDisplay.firstNonMove=false;
var _1b8=this.movesDisplay.getMovesDisplay();
if(_1b8){
YAHOO.util.Event.purgeElement(_1b8,true);
_1b8.innerHTML="";
}
this.currentMove=null;
this.moveIndex=-1;
this.moveArray=new Array();
if(_1b7){
_1b7.prev=null;
this.startMoveNum=_1b7.moveNum;
}else{
this.startMoveNum=1;
}
};
Board.prototype.insertMovesFromMoveList=function(_1b9,_1ba,_1bb){
var _1bc=!_1ba;
if(ctime&&_1bc){
console.time("insertMovesFromMoveList");
}
if(!this.movesDisplay){
return;
}
if(_1bc){
this.clearMoveList(_1b9);
}
var _1bd=0;
var _1be=_1b9.moveNum;
var move=_1b9;
while(move!=null&&!move.atEnd){
if(clog){
console.log("move:"+move.output());
}
var _1c0=move.next;
if(clog){
if(this.currentMove){
console.log("current move:"+this.currentMove.output());
}else{
console.log("no current move");
}
if(_1c0){
console.log("next move:"+_1c0.output());
}else{
console.log("no next move");
}
}
if(_1bc||_1b9!=move||_1bb==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:"+_1bb.output()+" with move:"+move.output()+" and board:"+this.boardToFen());
}
this.replaceMove(_1bb,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 _1c1=move.index;
var bm=move.prev;
var _1c3=-1;
if(bm){
_1c3=bm.index;
}
var _1c4=move.numVars;
var vars=move.vars;
move.numVars=0;
move.vars=[];
for(var i=0;i<_1c4;i++){
this.gotoMoveIndex(_1c3,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:"+_1c1);
}
}
this.gotoMoveIndex(_1c1,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=_1c0;
}
if(_1bc){
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&&_1bc){
console.timeEnd("insertMovesFromMoveList");
}
};
Board.prototype.setupFromLalgArrayIncremental=function(_1c9,_1ca,_1cb,_1cc){
this.outputFirstVar=false;
if(this.movesDisplay&&this.lastCount){
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 _1cf=0;
var _1d0=_1cb*2-1;
var _1d1="";
var _1d2=false;
var _1d3=false;
var _1d4=ChessPiece.WHITE;
var _1d5=false;
var _1d6=true;
this.currentMove=null;
for(var i=0;i<_1c9.length;i++){
if(_1c9[i]=="}"){
_1d5=false;
if(this.movesDisplay){
_1d1=_1d1.replace(/\s+$/g,"");
}
continue;
}else{
if(_1d5){
_1d1+=_1c9[i]+" ";
continue;
}else{
if(_1c9[i]=="{"){
_1d1="";
_1d5=true;
continue;
}else{
if(_1c9[i]=="("){
_1d2=true;
continue;
}else{
if(_1c9[i]==")"){
_1d3=true;
continue;
}else{
if(_1c9[i].charAt(0)=="$"){
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1c9[i]);
var _1d8=false;
if(_1d6&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1d0++;
_1d8=true;
_1d4=ChessPiece.BLACK;
}
this.startMoveNum=_1d0;
_1d6=false;
move.index=_1cf++;
var _1d9=move.moveString;
_1d9=Board.moveToLocale(_1d9);
_1d4=(_1d4==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 _1da=this.movesDisplay.getMovesDisplay();
if(_1da){
_1da.innerHTML=this.pendingMovesOutput;
var _1db=new YAHOO.util.Scroll(_1da,{scroll:{to:[0,0]}},0);
_1db.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);
}
}
}
}
};
Board.prototype.setMoveSequence=function(_1de,_1df,_1e0,_1e1){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_1de,this.tacticMoveArray,_1e0,_1e1);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_1df!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_1df,this.fullmoveArray,_1e0,_1e1);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_1e2,_1e3){
if(_1e2.numVars>0){
for(var i=0;i<_1e2.numVars;i++){
_1e2.vars[i].prev=_1e3;
this.resetVariationsPreviousNodes(_1e2.vars[i],_1e3);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_1e5,_1e6){
if(!_1e6){
return;
}
if(_1e6.numVars>0){
for(var i=0;i<_1e6.numVars;i++){
_1e6.vars[i].prev=_1e5;
this.reconnectNextNodeVariations(_1e5,_1e6.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 _1ec=this.moveArray[0];
if(m!=_1ec){
return m;
}
}
return null;
}
};
Board.prototype.liftVariation=function(_1ed){
if(!_1ed){
return;
}
var _1ee=null;
var _1ef=null;
if(_1ed.prev){
_1ee=_1ed.prev.next;
}else{
_1ee=this.moveArray[0];
_1ef=_1ed;
}
var _1f0=null;
if(this.currentMove&&this.currentMove.prev){
_1f0=this.currentMove.prev;
}
if(_1ee){
var _1f1=_1ee.numVars;
var vars=_1ee.vars;
_1ee.numVars=0;
_1ee.vars=[];
if(_1ed.numVars==0){
_1ed.vars=[];
}
for(var i=0;i<_1f1;i++){
var _1f4=vars[i];
if(clog){
console.log("processing var:"+_1f4.output());
}
if(_1f4==_1ed){
if(clog){
console.log("inserted parent var");
}
_1ed.vars.push(_1ee);
_1ed.numVars++;
}else{
_1ed.vars.push(_1f4);
_1ed.numVars++;
}
}
if(_1ed.prev){
_1ed.prev.next=_1ed;
}
if(clog){
console.log("finished moving variations");
}
if(!_1ef){
_1ef=this.findFirstMoveFromList(_1ed);
}
this.moveArray[0]=_1ef;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1ef.output());
}
this.insertMovesFromMoveList(_1ef);
}
if(_1f0){
this.gotoMoveIndex(_1f0.index);
}
};
Board.prototype.deleteMoveAndLine=function(move){
var m=move;
var oldM=m;
var _1f8=false;
var _1f9=null;
var _1fa=this.moveArray[0];
var _1fb=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");
}
_1f8=true;
_1f9=move.prev.next;
}else{
if(move&&!move.prev&&move!=this.moveArray[0]){
if(clog){
console.log("var is head and front of move list");
}
_1f8=true;
_1f9=this.moveArray[0];
}
}
if(clog){
console.log("isVariationHead:"+_1f8);
}
if(clog){
console.log("fm:"+_1fa.output());
}
var _1fc=m.prev;
if(_1f8){
_1fb=_1f9;
if(_1f9){
if(clog){
console.log("delete variation from parent:"+_1f9.output());
}
var _1fd=[];
for(var i=0;i<_1f9.numVars;i++){
if(!(_1f9.vars[i]==oldM)){
if(clog){
console.log("saving var:"+_1f9.vars[i].output());
}
_1fd.push(_1f9.vars[i]);
}else{
if(clog){
console.log("dropping var:"+_1f9.vars[i].output());
}
}
}
_1f9.vars=_1fd;
_1f9.numVars=_1fd.length;
}
}else{
if(_1fc){
_1fc.next=null;
_1fb=_1fc;
}else{
if(clog){
console.log("deleting entire list");
}
if(this.movesDisplay){
this.movesDisplay.firstNonMove=false;
}
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
var _1ff=this.movesDisplay.getMovesDisplay();
if(_1ff){
_1ff.innerHTML="";
}
this.currentMove=null;
this.startMoveNum=_1fa.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]=_1fa;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1fa.output());
}
this.insertMovesFromMoveList(_1fa);
if(_1fb){
this.gotoMoveIndex(_1fb.index);
}
};
Board.prototype.insertMoveAfter=function(_200,_201,_202,_203,_204,_205){
addToMovelist=!_202;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _206="null";
if(_200){
_206=_200.output();
}
if(clog){
console.log("insert newMove:"+_201.output()+" after:"+_206);
}
if(_200==null){
this.currentMove=_201;
_201.atEnd=0;
_201.prev=null;
_201.next=null;
this.firstMove=_201;
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{
_201.atEnd=_200.atEnd;
_201.prev=_200;
_200.atEnd=0;
if(clog){
if(_200.next){
console.log("prevMove.next:"+_200.next.output());
}
}
if(_201.equals(_200.next)||_201.equals(_200)){
if(clog){
console.log("inserting move that already exists in variation:"+_200.next.output());
}
var _207=_200.next;
if(this.firstMove==_207){
this.firstMove=_201;
}
if(_201.equals(_200)){
_207=_200;
}
if(_207.prev&&(_207.prev.next==_207)){
_207.prev.next=_201;
}
if(_207.next){
_207.next.prev=_201;
}
addToMovelist=false;
_201.moveNum=_207.moveNum;
_201.ravLevel=_207.ravLevel;
_201.index=_207.index;
_201.fen=_207.fen;
_201.nextFen=_207.nextFen;
_201.bestMoves=_207.bestMoves;
_201.correctMove=_207.correctMove;
_201.wrongMove=_207.wrongMove;
_201.next=_207.next;
_201.vars=_207.vars;
_201.numVars=_207.numVars;
this.reconnectNextNodeVariations(_201,_207.next);
this.moveArray[_201.index]=_201;
if(this.currentMove==_207){
this.setCurrentMove(_201);
}
}else{
_201.moveNum=_200.moveNum+1;
_201.ravLevel=_200.ravLevel;
_201.next=_200.next;
if(_201.next){
_201.next.prev=_201;
}
}
_200.next=_201;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_200,_201,_203,_204,_205);
}
if(_201.next==null){
var _208=this.createMoveFromString("i1i2");
_201.next=_208;
_208.prev=_201;
_208.moveNum=_201.moveNum+1;
_208.ravLevel=_201.ravLevel;
_208.next=null;
_208.atEnd=1;
_208.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_208.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_201.next.output());
}
_201.next.moveNum=_201.moveNum+1;
}
};
function insertBefore(node,_20a){
if(_20a){
_20a.parentNode.insertBefore(node,_20a);
}
}
function insertAfter(node,_20c){
var _20d=_20c.parentNode;
_20d.insertBefore(node,_20c.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_20e,_20f,_210,_211,_212){
var _213="null";
if(_20e){
_213=_20e.output();
}
if(clog){
console.log("replace display newMove:"+_20f.output()+" after:"+_213+" hideScore:"+_211);
}
if(!_20e){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_20f,false,_211);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _214=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_214){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_20f.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_20f.fromColumn,_20f.fromRow,_20f.toColumn,_20f.toRow,_20f);
if(clog){
console.log("about to made san:"+san);
}
_20f.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_20e.index);
}
var _216=this.boardName+"-ms"+_20e.index;
if(clog){
console.log("oldMoveId:"+_216);
}
var _217=YAHOO.util.Dom.get(_216);
if(_210){
this.moveIndex++;
_20f.index=this.moveIndex;
this.moveArray[this.moveIndex]=_20f;
if(clog){
console.log("replace as variation old:"+_20e.output()+" new:"+_20f.output());
}
var _218=document.createElement("span");
var _219=this.movesDisplay.outputVariationStart(0,0,_20f.moveNum,0);
_20f.ravLevel=_20e.ravlevel+1;
var _213=Board.moveToLocale(san);
if(_20f.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _21a=this.movesDisplay.outputMove(this.moveIndex,_20f.ravLevel,_20f.moveNum,_213,_210,0,_20f.moveNum,_20f,_211,_212);
var _21b=document.createElement("span");
_21b.id=(this.boardName+"-ms"+_20f.index);
_21b.innerHTML=_21a+"&nbsp;";
var _21c=this.movesDisplay.outputVariationEnd(0,0,_20f.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _21d=document.createElement("span");
_21d.innerHTML=_219;
var _21e=document.createElement("span");
_21e.innerHTML=_21c;
_218.appendChild(_21d);
_218.appendChild(_21b);
_218.appendChild(_21e);
_217.appendChild(_218);
}else{
_20f.index=_20e.index;
this.moveArray[_20f.index]=_20f;
var _213=Board.moveToLocale(san);
if(_20f.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _21a=this.movesDisplay.outputMove(_20f.index,_20f.ravLevel,_20f.moveNum,_213,_210,0,_20f.moveNum,_20f,_211,_212);
var _21b=document.createElement("span");
_21b.innerHTML=_21a+"&nbsp;";
_21b.id=(this.boardName+"-ms"+_20f.index);
var _21f=[];
if(_217&&_217.childNodes){
for(var i=1;i<_217.childNodes.length;i++){
_21f[i-1]=_217.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_20e.output()+" new:"+_20f.output());
}
_217.parentNode.replaceChild(_21b,_217);
if(_21f){
for(var i=0;i<_21f.length;i++){
_21b.appendChild(_21f[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_20f.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_20f.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertCommentIntoMoveDisplay=function(move,_222,_223){
var _224=this.movesDisplay.getMovesDisplay();
if(!_224){
return;
}
var _225="b";
if(_223){
_225="a";
}
if(move){
var _226=this.boardName+"-mc"+_225+move.index;
var _227=YAHOO.util.Dom.get(_226);
var _228=false;
if(!_227){
_227=document.createElement("span");
_227.id=_226;
_228=true;
}
_227.innerHTML=this.movesDisplay.outputComment(_222,0);
var _229=YAHOO.util.Dom.get((this.boardName+"-m"+move.index));
if(_229){
if(_223){
move.afterComment=_222;
if(_228){
insertAfter(_227,_229);
}
}else{
move.beforeComment=_222;
if(_228){
insertBefore(_227,_229);
}
}
}
}else{
}
};
Board.prototype.insertIntoMoveDisplay=function(_22a,_22b,_22c,_22d,_22e){
var _22f=this.movesDisplay.getMovesDisplay();
if(!_22f){
return;
}
var _230="null";
if(_22a){
_230=_22a.output();
}
if(clog){
console.log("insert display newMove:"+_22b.output()+" after:"+_230);
}
var san=_22b.SAN;
if(!san){
san=this.makeShortAlgabraic(_22b.fromColumn,_22b.fromRow,_22b.toColumn,_22b.toRow,_22b);
_22b.SAN=san;
}
this.moveIndex++;
_22b.index=this.moveIndex;
this.moveArray[this.moveIndex]=_22b;
var _230=Board.moveToLocale(san);
var _232=this.movesDisplay.outputMove(this.moveIndex,_22b.ravLevel,_22b.moveNum,_230,false,0,_22b.moveNum,_22b,_22d,_22e);
var _233=document.createElement("span");
_233.innerHTML=_232+"&nbsp;";
_233.id=(this.boardName+"-ms"+this.moveIndex);
if(_22c){
YAHOO.util.Dom.setStyle(_233,"visibility","hidden");
}
if(_22a){
if(clog){
console.log("prevMove.index:"+_22a.index+"prevMove:"+_22a.output());
}
var _234=YAHOO.util.Dom.get((this.boardName+"-ms"+_22a.index));
if(_234){
insertAfter(_233,_234);
}else{
_22f.appendChild(_233);
}
}else{
if(_22b.next){
var _235=YAHOO.util.Dom.get((this.boardName+"-ms"+_22b.next.index));
insertBefore(_233,_235);
}else{
_22f.appendChild(_233);
}
}
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(_236,_237,_238,_239,_23a,_23b){
var _23c="null";
if(_236){
_23c=_236.output();
}
if(clog){
console.log("replace newMove:"+_237.output()+" after:"+_23c+" replace as var"+_238+" rep move display:"+_239+" hideScore:"+_23a);
if(_236&&_236.prev){
console.log("replace oldMove.prev:"+_236.prev.output());
}
if(_236&&_236.next){
console.log("replace oldMove.next:"+_236.next.output());
}
}
var _23d=false;
var _23e=null;
var _23f=0;
if(_236.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_236.prev,_237,false,false,_23a,_23b);
_237.fen=_236.fen;
_237.nextFen=_236.nextFen;
return;
}
if(_237.equals(_236)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_238=false;
}else{
if(_236&&_236.numVars>0){
for(var i=0;i<_236.numVars;i++){
var _241=_236.vars[i];
if(_237.equals(_241)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_241.output());
if(_241.next){
console.log("variation next:"+_241.next.output());
}
}
_23d=true;
_23e=_236;
_236=_241;
_23f=i;
break;
}
}
}
}
if(_236==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_237;
_237.atEnd=1;
_237.next=null;
_237.prev=null;
if(this.startPositionAfterOpponentMove){
_237.fen=this.startPositionAfterOpponentMove;
_237.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_237;
}else{
var _242=false;
if(_236&&_236.prev&&_236.prev.next!=_236){
_242=true;
}
if(this.currentMove==_236&&!_238){
this.currentMove=_237;
}else{
if(clog){
console.log("not setting current move in replacemove");
}
}
_237.atEnd=_236.atEnd;
_237.prev=_236.prev;
_237.next=_236.next;
_237.fen=_236.fen;
_237.nextFen=_236.nextFen;
_237.bestMoves=_236.bestMoves;
_237.correctMove=_236.correctMove;
_237.wrongMove=_236.wrongMove;
_237.moveNum=_236.moveNum;
_237.ravLevel=_236.ravLevel;
_237.index=_236.index;
if(clog){
console.log("replacingVariation with var not null:"+_23d);
}
if(_23d){
_23e.vars[_23f]=_237;
_237.vars=_236.vars;
_237.numVars=_236.numVars;
this.reconnectNextNodeVariations(_237,_236.next);
if(_236.next){
_236.next.prev=_237;
}
this.moveArray[_237.index]=_237;
if(clog){
console.log("replacing existing sub variation of main line");
if(_237.next){
console.log("next of replacement variation:"+_237.next.output());
}
}
return;
}
if(!_238){
if(clog){
console.log("not replacing as variation");
}
if(!_242&&_236.prev){
_236.prev.next=_237;
}
if(_236.next){
_236.next.prev=_237;
}
_237.vars=_236.vars;
_237.numVars=_236.numVars;
this.reconnectNextNodeVariations(_237,_236.next);
if(this.firstMove==_236){
this.firstMove=_237;
}
this.moveArray[_237.index]=_237;
}else{
if(clog){
console.log("replacing as variation");
}
if(_236.numVars==0){
_236.vars=new Array();
}
_236.vars[_236.numVars++]=_237;
_236.atEnd=0;
_237.next=null;
var _243=this.createMoveFromString("i1i2");
_237.next=_243;
_243.prev=_237;
_243.next=null;
_243.atEnd=1;
_243.moveNum=_237.moveNum+1;
_243.ravLevel=_237.ravLevel;
_243.endNode=true;
}
}
if(_239){
this.replaceIntoMoveDisplay(_236,_237,_238,_23a,_23b);
}
};
Board.prototype.setCurrentMove=function(move,_245,_246){
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 _247=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_247+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_247);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(!_246&&(this.scrollVariations||cls.indexOf("ct-board-move-variation")==-1)){
var _24a=this.movesDisplay.getMovesDisplay();
if(_24a){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_24a);
var _24c=new YAHOO.util.Scroll(_24a,{scroll:{by:[0,y]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_24c.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_245){
this.setForwardBack();
}
};
Board.INITIAL_FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board.prototype.boardToFen=function(_24d){
var _24e="";
for(var row=7;row>=0;row--){
var _250=0;
var line="";
if(row<7){
line="/";
}
for(var col=0;col<8;col++){
var _253=this.boardPieces[col][row];
if(_253){
var _254="";
if(_250>0){
_254=_250+"";
}
line+=_254+_253.getFenLetter();
_250=0;
}else{
_250++;
}
}
if(_250>0){
line+=_250+"";
}
_24e+=line;
}
var fen=_24e;
var _256=" w ";
if(_24d){
if(this.toMove==ChessPiece.WHITE){
_256=" b ";
}
}else{
if(this.toMove==ChessPiece.BLACK){
_256=" b ";
}
}
fen+=_256;
var _257="";
_257+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.WHITE);
_257+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.WHITE);
_257+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.BLACK);
_257+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.BLACK);
if(_257==""){
fen+="- ";
}else{
fen+=_257+" ";
}
var _258=null;
if(this.currentMove){
if(this.currentMove.prev){
_258=this.currentMove.prev;
}else{
_258=this.prev_move;
}
}else{
_258=this.prev_move;
}
var _259="- ";
if(_258){
if(_258){
var _25a=this.boardPieces[_258.toColumn][_258.toRow];
if(_25a){
if(_25a.piece==ChessPiece.PAWN){
if(_25a.colour==ChessPiece.WHITE){
if(_258.fromRow==1&&_258.toRow==3){
_259=Move.columnToChar(_258.fromColumn)+"3 ";
}
}else{
if(_258.fromRow==6&&_258.toRow==4){
_259=Move.columnToChar(_258.fromColumn)+"6 ";
}
}
}
}
}
}
fen+=_259;
fen+=this.halfMoveNumber+" "+parseInt((this.moveNumber+1)/2);
if(clog){
console.log("moveNumber:"+this.moveNumber+" fen:"+fen);
}
return fen;
};
Board.getFenCastleChar=function(_25b,_25c,_25d){
if(_25b[_25d]){
if(_25d==ChessPiece.WHITE){
return _25c.toUpperCase();
}else{
return _25c.toLowerCase();
}
}
return "";
};
Board.prototype.getCastlingString=function(_25e){
var _25f=_js("None");
if(this.canCastleKingSide[_25e]){
_25f="O-O";
}
if(this.canCastleQueenSide[_25e]){
if(_25f==_js("None")){
_25f="O-O-O";
}else{
_25f+=",O-O-O";
}
}
return _25f;
};
Board.prototype.updateToPlay=function(){
if(this.disableUpdateToPlay){
return;
}
var _260=YAHOO.util.Dom.get("toPlay");
if(_260==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_260.src="/images/whiteknight"+this.getVersString()+".gif";
_260.alt=_js("White to play");
}else{
_260.src="/images/blackknight"+this.getVersString()+".gif";
_260.alt=_js("Black to play");
}
var _261=YAHOO.util.Dom.get("fenStatus");
if(_261){
var _262=this.getCastlingString(ChessPiece.BLACK);
var _263=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_263+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_262+"</span></div>";
_261.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 _266=document.getElementsByTagName("body");
if(_266==null||_266.length==0){
alert("Could not find body tag");
}else{
this.docBody=_266[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 _267=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _268=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_267||!_268){
return;
}
YAHOO.util.Event.purgeElement(_267,true);
_268.innerHTML="";
_267.innerHTML="";
var _269=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_267,"display","none");
YAHOO.util.Dom.setStyle(_268,"display","none");
var _26a=0;
YAHOO.util.Dom.setStyle(_269,"width",(this.pieceSize*8+_26a)+"px");
YAHOO.util.Dom.setStyle(_269,"height",(this.pieceSize*8+_26a)+"px");
return;
}
YAHOO.util.Dom.setStyle(_267,"display","block");
YAHOO.util.Dom.setStyle(_268,"display","block");
var _26a=15;
var _26b=0;
if(check_bad_msie()){
_26b=this.ie6FixCoordsOffsetSize;
}
if(YAHOO.util.Event.isIE){
_26b+=this.allIeFixCoordsOffsetSize;
}
YAHOO.util.Dom.setStyle(_269,"width",(this.pieceSize*8+_26a+_26b)+"px");
YAHOO.util.Dom.setStyle(_269,"height",(this.pieceSize*8+_26a)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _26d=document.createElement("div");
YAHOO.util.Dom.setStyle(_26d,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_26d,"width","15px");
YAHOO.util.Dom.setStyle(_26d,"text-align","center");
YAHOO.util.Dom.setStyle(_26d,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_26d.innerHTML=""+(i+1);
}else{
_26d.innerHTML=""+9-(i+1);
}
_268.appendChild(_26d);
}
for(var i=0;i<9;i++){
var _26e=document.createElement("span");
YAHOO.util.Dom.setStyle(_26e,"float","left");
YAHOO.util.Dom.setStyle(_26e,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_26e,"width","15px");
YAHOO.util.Dom.setStyle(_26e,"clear","both");
YAHOO.util.Dom.setStyle(_26e,"margin-top","-5px");
if(_26b){
YAHOO.util.Dom.setStyle(_26e,"margin-left","-3px");
}else{
YAHOO.util.Dom.setStyle(_26e,"margin-left","-2px");
}
var _26f="";
if(this.isFlipped){
_26f="whiteblack-flipper"+this.getVersString()+".png";
}else{
_26f="blackwhite-flipper"+this.getVersString()+".png";
}
_26e.innerHTML="<span><img id=\""+this.boardName+"-flipper\" title=\""+_js("Flip Board")+"\" src=\""+this.boardImagePath+"/images/"+_26f+"\"/></span>";
YAHOO.util.Event.addListener(this.boardName+"-flipper","click",this.flipBoard,this,true);
}else{
YAHOO.util.Dom.setStyle(_26e,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_26e,"text-align","center");
if(this.isFlipped){
_26e.innerHTML=_js(Move.columnToChar(8-(i)));
}else{
_26e.innerHTML=_js(Move.columnToChar((i-1)));
}
}
_267.appendChild(_26e);
}
var _270=YAHOO.util.Dom.get(this.boardName+"-flipper");
if(_270){
fix_ie_png(_270);
}
};
Board.prototype.createBoardUI=function(){
var _271=this.boardName+"-container";
var _272=YAHOO.util.Dom.get(_271);
if(_272==null){
alert("Could not find board container:"+_271);
return;
}
YAHOO.util.Dom.addClass(_272,"ct-board-container");
this.boardDiv=null;
var _273=document.createElement("div");
_273.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_273,"ct-board-border"+this.squareColorClass);
var _274=0;
if(this.showCoordinates){
_274=15;
}
YAHOO.util.Dom.setStyle(_273,"width",(this.pieceSize*8+_274)+"px");
YAHOO.util.Dom.setStyle(_273,"height",(this.pieceSize*8+_274)+"px");
var _275=document.createElement("div");
YAHOO.util.Dom.setStyle(_275,"float","left");
_275.id=this.boardName+"-rankLabels";
_273.appendChild(_275);
var _276=document.createElement("div");
YAHOO.util.Dom.addClass(_276,"ct-board");
YAHOO.util.Dom.setStyle(_276,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_276,"height",(this.pieceSize*8)+"px");
_276.id="ctb-"+this.boardName;
var _277="ct-white-square"+this.squareColorClass;
var _278="";
var _279=[];
for(var i=7;i>=0;i--){
var s="<div>";
for(var j=0;j<8;j++){
var _27d=document.createElement("div");
var _27e=this.boardName+"-s"+j+""+i;
var _27f=(((j+1)*(i+1))%19/19*100);
var _280=((65-((j+1)*(i+1)))%19/19*100);
s+="<div id=\""+_27e+"\" class=\""+_277+"\" style=\"width:"+this.pieceSize+"px;height:"+this.pieceSize+"px;background-position:"+_27f+"% "+_280+"%\"></div>";
_279.push(_27e);
_277=(_277=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_277=(_277=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
s+="</div>";
_278+=s;
}
_276.innerHTML=_278;
var _281=document.createElement("div");
_281.id=this.boardName+"-fileLabels";
_273.appendChild(_276);
_273.appendChild(_281);
_272.appendChild(_273);
this.createBoardCoords();
var _282=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_282){
_282=document.createElement("div");
}else{
_282.innerHTML="";
}
_282.id=this.boardName+"-ct-nav-container";
if(!this.dontOutputNavButtons||this.r){
var _283="";
if(!this.dontOutputNavButtons){
if(!this.problem||!this.problem.isEndgame){
_283="<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 _284="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\"><span id=\"nav-buttons-only\">";
if(!this.dontOutputNavButtons){
var size="";
if(isIphone){
size=" width=\"50px\" height=\"34px\" ";
_283="";
}
if(!isIphone){
_284+="<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")+"\"/>";
}
_284+="<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")+"\"/>"+_283;
}
if(this.r){
_284+="<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){
_284+="<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){
_284+="<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")+"\"/>";
}
_284+="</span></div>";
_282.innerHTML=_284;
}
_272.appendChild(_282);
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_274)+300+200+120)+"px");
}
}
};
Board.prototype.getPieceDiv=function(){
var _287=this.getBoardDiv();
var _288=document.createElement("div");
this.availPieceDivs[this.uptoId]=_288;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_288);
YAHOO.util.Dom.setStyle(_288,"visibility","hidden");
YAHOO.util.Dom.addClass(_288,"board-piece-start-style");
_287.appendChild(_288);
this.uptoId++;
return _288;
};
Board.prototype.flipToMove=function(_289){
return (_289=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_28a){
var _28b;
switch(_28a){
case "K":
_28b=ChessPiece.KING;
break;
case "Q":
_28b=ChessPiece.QUEEN;
break;
case "R":
_28b=ChessPiece.ROOK;
break;
case "B":
_28b=ChessPiece.BISHOP;
break;
case "N":
_28b=ChessPiece.KNIGHT;
break;
case "P":
_28b=ChessPiece.PAWN;
break;
}
return _28b;
};
Board.prototype.pieceTypeToChar=function(_28c){
switch(_28c){
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(_28d,_28e,_28f,_290){
if(_28d+2==_28f&&_28e+1==_290){
return true;
}
if(_28d+2==_28f&&_28e-1==_290){
return true;
}
if(_28d-2==_28f&&_28e+1==_290){
return true;
}
if(_28d-2==_28f&&_28e-1==_290){
return true;
}
if(_28d+1==_28f&&_28e+2==_290){
return true;
}
if(_28d-1==_28f&&_28e+2==_290){
return true;
}
if(_28d+1==_28f&&_28e-2==_290){
return true;
}
if(_28d-1==_28f&&_28e-2==_290){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_291,_292,_293,_294,_295){
var _296=this.boardPieces[_293][_294];
var _297=this.boardPieces[_291][_292];
if(_295){
var _298=this.boardPieces[_295.toColumn][_295.toRow];
if(_298.piece==ChessPiece.PAWN){
if(_298.colour==ChessPiece.WHITE){
if(_295.fromRow==1&&_295.toRow==3){
if(_293==_295.fromColumn&&_292==3&&_294==2&&(_291==_293+1||_291==_293-1)){
return true;
}
}
}else{
if(_295.fromRow==6&&_295.toRow==4){
if(_293==_295.fromColumn&&_292==4&&_294==5&&(_291==_293+1||_291==_293-1)){
return true;
}
}
}
}
}
if(_296){
if(_297.colour==ChessPiece.WHITE){
if((_291==_293+1||_291==_293-1)&&(_292==_294-1)){
return true;
}
}else{
if((_291==_293+1||_291==_293-1)&&(_292==_294+1)){
return true;
}
}
}else{
if(_291==_293){
if(_297.colour==ChessPiece.WHITE){
if(_292==1){
if(_294==2){
return true;
}else{
if(_294==3&&this.boardPieces[_293][2]==null){
return true;
}
}
}else{
if(_292+1==_294){
return true;
}
}
}else{
if(_292==6){
if(_294==5){
return true;
}else{
if(_294==4&&this.boardPieces[_293][5]==null){
return true;
}
}
}else{
if(_292-1==_294){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_299,_29a,_29b,_29c,_29d,_29e){
var _29f=_299;
var _2a0=_29a;
var _2a1=0;
var _2a2=0;
if(_29b>_299){
_2a1=1;
}else{
if(_29b<_299){
_2a1=-1;
}
}
if(_29c>_29a){
_2a2=1;
}else{
if(_29c<_29a){
_2a2=-1;
}
}
if(clog){
console.log("deltaRow:"+_2a2+" deltaCol:"+_2a1+" fromCol:"+_299+" fromRow:"+_29a+" toCol:"+_29b+" toRow:"+_29c);
}
if(_29d==ChessPiece.ROOK&&(_2a1!=0&&_2a2!=0)){
return false;
}
if(_29d==ChessPiece.BISHOP&&(_2a1==0||_2a2==0)){
return false;
}
var _2a3=0;
while(true){
_2a3++;
_299+=_2a1;
_29a+=_2a2;
if(_29d==ChessPiece.KING&&_2a3>1){
if(clog){
console.log("king count:"+_2a3+" toCol:"+_29b+" toRow:"+_29c);
}
if(_2a3!=2){
return false;
}
if(_2a2!=0){
return false;
}
if(!(_29b==6||_29b==2)){
return false;
}
if(_29b==2){
if(this.boardPieces[1][_29a]||this.boardPieces[2][_29a]||this.boardPieces[3][_29a]){
return false;
}
if(!this.canCastleQueenSide[_29e.colour]){
return false;
}
}else{
if(_29b==6){
if(this.boardPieces[5][_29a]||this.boardPieces[6][_29a]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_29e.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_29e.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _2a4="";
_2a4+=Move.columnToChar(_29f);
_2a4+=String.fromCharCode("1".charCodeAt(0)+_2a0);
_2a4+=Move.columnToChar((_29f+_2a1));
_2a4+=String.fromCharCode("1".charCodeAt(0)+(_2a0+_2a2));
var move=this.createMoveFromString(_2a4);
var _2a6=this.boardPieces;
var _2a7=this.toMove;
var _2a8=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_29f][_2a0],false,this.moveAnimationLength,false,false);
this.restoreCastling(_2a8);
kingSafe=this.isKingSafe(_29e.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_2a6;
_2a6.count--;
this.toMove=_2a7;
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _2a4="";
_2a4+=Move.columnToChar(_29f);
_2a4+=String.fromCharCode("1".charCodeAt(0)+_2a0);
_2a4+=Move.columnToChar(_29f);
_2a4+=String.fromCharCode("1".charCodeAt(0)+_2a0);
var move=this.createMoveFromString(_2a4);
var _2a6=this.boardPieces;
var _2a7=this.toMove;
var _2a8=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_29f][_2a0],false,this.moveAnimationLength,false,false);
this.restoreCastling(_2a8);
kingSafe=this.isKingSafe(_29e.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_2a6;
_2a6.count--;
this.toMove=_2a7;
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_299==_29b&&_29a==_29c){
return true;
}
if(_299<0||_299>7||_29a<0||_29a>7){
return false;
}
if(this.boardPieces[_299][_29a]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_2a9,_2aa,_2ab,_2ac,_2ad){
var _2ae=_2a9.column;
var _2af=_2a9.row;
if(_2aa>7||_2aa<0||_2ab>7||_2ab<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _2b0=this.boardPieces[_2aa][_2ab];
var _2b1=this.boardPieces[_2ae][_2af];
if(_2b1==null){
return false;
}
if(_2b0&&_2b0.colour==_2b1.colour){
return false;
}
var _2b2=false;
if(_2a9.piece==ChessPiece.PAWN){
_2b2=this.canMovePawn(_2ae,_2af,_2aa,_2ab,_2ac);
}else{
if(_2a9.piece==ChessPiece.KNIGHT){
_2b2=this.canMoveKnight(_2ae,_2af,_2aa,_2ab);
}else{
_2b2=this.canMoveStraight(_2ae,_2af,_2aa,_2ab,_2a9.piece,_2a9);
}
}
if(clog){
console.log("moveOk:"+_2b2);
}
var _2b3=true;
if(_2b2&&_2ad){
var _2b4="";
_2b4+=Move.columnToChar(_2ae);
_2b4+=String.fromCharCode("1".charCodeAt(0)+_2af);
_2b4+=Move.columnToChar(_2aa);
_2b4+=String.fromCharCode("1".charCodeAt(0)+_2ab);
var move=this.createMoveFromString(_2b4);
var _2b6=this.cloneBoard();
_2b6.makeMove(move,_2b6.boardPieces[_2ae][_2af],false,this.moveAnimationLength,false,false);
_2b3=_2b6.isKingSafe(_2a9.colour,move);
}
return _2b2&&_2b3;
};
Board.prototype.isKingMated=function(_2b7,_2b8){
var _2b9=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==_2b7){
_2b9=bp;
break;
}
}
}
var _2bd=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_2b9;
for(var k=0;k<_2bd.length;k++){
if(this.canMove(bp,bp.column+_2bd[k][0],bp.row+_2bd[k][1],_2b8,true)){
return false;
}
}
var _2bf=this.getCandidateMoves(_2b7,_2b8,true,true);
if(_2bf.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_2c0,_2c1,_2c2,_2c3){
var _2c4=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _2c8=[];
if(!bp||bp.colour!=_2c0){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_2c3){
continue;
}
_2c8=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_2c8=[[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++){
_2c8.push([1+k,1+k]);
_2c8.push([1+k,-1-k]);
_2c8.push([-1-k,1+k]);
_2c8.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_2c8.push([1+k,0]);
_2c8.push([1+k,1+k]);
_2c8.push([1+k,-1-k]);
_2c8.push([-1-k,0]);
_2c8.push([-1-k,1+k]);
_2c8.push([-1-k,-1-k]);
_2c8.push([0,-1-k]);
_2c8.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_2c8.push([1+k,0]);
_2c8.push([-1-k,0]);
_2c8.push([0,-1-k]);
_2c8.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
if(_2c0==ChessPiece.BLACK){
_2c8=[[0,-1],[1,-1],[-1,-1]];
if(j==6){
_2c8.push([0,-2]);
}
}else{
_2c8=[[0,1],[1,1],[-1,1]];
if(j==1){
_2c8.push([0,2]);
}
}
break;
}
for(var k=0;k<_2c8.length;k++){
if(this.canMove(bp,bp.column+_2c8[k][0],bp.row+_2c8[k][1],_2c1,true)){
_2c4.push(new Move(bp.column,bp.row,bp.column+_2c8[k][0],bp.row+_2c8[k][1]));
if(_2c2){
return _2c4;
}
}
}
}
}
return _2c4;
};
Board.prototype.isKingSafe=function(_2ca,_2cb){
var _2cc=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==_2ca){
_2cc=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!=_2ca){
if(this.canMove(bp,_2cc.column,_2cc.row,_2cb,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.freeBoardPieces=function(_2d0){
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(_2d0){
this.boardPieces[i]=null;
}
}
}
if(_2d0){
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 _2d5=new Board();
_2d5.boardName=this.boardName;
_2d5.cloned=true;
_2d5.boardPieces=this.copyBoardPieces(true);
_2d5.moveArray=this.copyMoveArray(false);
_2d5.canCastleQueenSide=this.copyCastleQueenSide();
_2d5.canCastleKingSide=this.copyCastleKingSide();
_2d5.toMove=this.toMove;
_2d5.opponentColour=this.opponentColour;
_2d5.isFlipped=this.isFlipped;
_2d5.isUserFlipped=this.isUserFlipped;
_2d5.ignoreFlipping=this.ignoreFlipping;
_2d5.reverseFlip=this.reverseFlip;
_2d5.moveAnimationLength=this.moveAnimationLength;
_2d5.moveNumber=this.moveNumber;
_2d5.halfMoveNumber=this.halfMoveNumber;
_2d5.startFen=this.startFen;
_2d5.boardImagePath=this.boardImagePath;
if(this.prev_move){
_2d5.prev_move=this.prev_move.clone();
}else{
_2d5.prev_move=null;
}
return _2d5;
};
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(_2d6){
var _2d7=new Array();
if(!_2d6){
if(this.moveArray.length>0){
_2d7=this.moveArray.slice(0);
}
return _2d7;
}else{
for(var i=0;i<this.moveArray.length;i++){
var m=_2d7[i];
if(m){
var newM=m.clone(true);
_2d7[i]=newM;
}
}
return _2d7;
}
};
Board.prototype.copyBoardPieces=function(_2db){
var _2dc=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_2db){
_2dc[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_2dc[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_2dc[i][j]=null;
}
}
}
return _2dc;
};
Board.prototype.createPiece=function(_2df,_2e0,_2e1){
if(_2e1){
return new LightweightChessPiece(null,_2df,_2e0,this);
}else{
return new ChessPiece(this.getPieceDiv(),_2df,_2e0,this);
}
};
Board.prototype.restoreCastling=function(_2e2){
this.canCastleKingSide=_2e2.kingSide;
this.canCastleQueenSide=_2e2.queenSide;
};
Board.prototype.saveCastling=function(){
var _2e3=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _2e4=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_2e3,kingSide:_2e4};
};
var firstLightProf=true;
var firstHeavyProf=true;
Board.prototype.setupFromFenLightweight=function(fen,_2e6,flip,_2e8,_2e9){
var _2ea=false&&firstLightProf;
if(_2ea){
console.profile("setupFromFenLight");
}
this.setupFromFenGeneric(fen,_2e6,flip,true,_2e8,_2e9);
if(_2ea){
console.profileEnd();
}
};
Board.prototype.setupFromFenHeavyWeight=function(fen,_2ec,flip,_2ee,_2ef){
var _2f0=false&&firstHeavyProf;
if(_2f0){
console.profile("setupFromFenHeavy");
}
this.setupFromFenGeneric(fen,_2ec,flip,false,_2ee,_2ef);
if(_2f0){
console.profileEnd();
}
};
Board.prototype.setupFromFen=function(fen,_2f2,flip,_2f4,_2f5,_2f6){
if(_2f4){
this.setupFromFenLightweight(fen,_2f2,flip,_2f5,_2f6);
}else{
this.setupFromFenHeavyWeight(fen,_2f2,flip,_2f5,_2f6);
}
};
Board.prototype.setupFromFenGeneric=function(fen,_2f8,flip,_2fa,_2fb,_2fc){
if(ctime){
console.time("setupFromFen"+_2fa);
}
this.settingUpPosition=true;
var _2fd=fen.split(" ");
var _2fe=_2fd[0].split("/");
this.halfMoveNumber=parseInt(_2fd[4]);
this.moveNumber=parseInt(_2fd[5])*2;
var _2ff=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _301=_2fd[2];
var _302=null;
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_301!="-"){
if(_301.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_301.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_301.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_301.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_2fc){
this.startMoveNum=this.moveNumber;
}
if(_2fd[1]=="w"){
if(_2fc){
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(_2fb){
var _303=_2fd[3];
if(_303!="-"&&_303.length==2){
var _304=_303[0];
var _305=parseInt(_303[1]);
if(_305==3){
_302=this.createMoveFromString(_304+"2"+_304+"4");
}else{
_302=this.createMoveFromString(_304+"7"+_304+"5");
}
_302.prevMoveEnpassant=true;
this.prev_move=_302;
}
}
if(_2f8){
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=_2fe[i];
row--;
_2ff=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 _30c=this.boardPieces[_2ff][row];
this.boardPieces[_2ff][row]=null;
_2ff++;
}
}else{
var _30d=(c+"").toLowerCase().charAt(0);
var _30e=ChessPiece.WHITE;
if(_30d==c){
_30e=ChessPiece.BLACK;
}
var cp;
switch(_30d){
case "k":
cp=this.createPiece(_30e,ChessPiece.KING,_2fa);
break;
case "q":
cp=this.createPiece(_30e,ChessPiece.QUEEN,_2fa);
break;
case "r":
cp=this.createPiece(_30e,ChessPiece.ROOK,_2fa);
break;
case "b":
cp=this.createPiece(_30e,ChessPiece.BISHOP,_2fa);
break;
case "n":
cp=this.createPiece(_30e,ChessPiece.KNIGHT,_2fa);
break;
case "p":
cp=this.createPiece(_30e,ChessPiece.PAWN,_2fa);
break;
default:
alert("unknown piece letter:"+_30d+" for fen:"+fen);
}
if(isGecko||isOpera){
cp.setPosition(_2ff,row,false,null,this.moveAnimationLength);
cp.setVisible(true);
}
this.boardPieces[_2ff][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_2ff;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_2ff++;
}
}
}
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(!_2fa){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
if(!_2fa){
this.createBoardCoords();
}
this.settingUpPosition=false;
if(ctime){
console.timeEnd("setupFromFen"+_2fa);
}
};
Board.prototype.resetMoveListScrollPosition=function(){
var _310=this.movesDisplay.getMovesDisplay();
if(_310){
var _311=new YAHOO.util.Scroll(_310,{scroll:{to:[0,0]}},0);
_311.animate();
}
};
Board.prototype.changePieceSet=function(_312,_313){
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 _315=this.pieceSize;
this.pieceSet=_312;
this.pieceSize=_313;
var _316=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _317=0;
if(this.showCoordinates){
_317=15;
}
_316.className="";
YAHOO.util.Dom.addClass(_316,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_316,"width",(this.pieceSize*8+_317)+"px");
YAHOO.util.Dom.setStyle(_316,"height",(this.pieceSize*8+_317)+"px");
var _318=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_318,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_318,"height",(this.pieceSize*8)+"px");
var _319="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _31c=this.getBoardDivFromId(this.boardName+"-s"+j+""+i);
_31c.className="";
YAHOO.util.Dom.addClass(_31c,_319);
YAHOO.util.Dom.setStyle(_31c,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_31c,"height",this.pieceSize+"px");
var _31d=(((j+1)*(i+1))%19/19*100);
var _31e=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_31c,"background-position",_31d+"% "+_31e+"%");
_319=(_319=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_319=(_319=="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){
var _320=cp.div;
_320.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_320.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){
var _320=cp.div;
_320.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_320.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+_317)+300+200+120)+"px");
}
}
this.createBoardCoords();
};
Board.prototype.forwardMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
if(clog){
console.log("returning early from forward due to block forward on");
}
return;
}
var _326=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(!_326){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _327=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_327=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_327,true);
this.toggleToMove();
this.updateToPlay();
var _328=this.currentMove;
if(clog){
if(_328){
console.log("after forward curmove:"+_328.output());
}else{
console.log("after forward cur move null");
}
}
for(var i=0;i<this.registeredForwardMovePostUpdateListeners.length;i++){
var _32a=this.registeredForwardMovePostUpdateListeners[i].forwardMovePostUpdateCallback(move);
}
}
}else{
if(clog){
console.log("already at end");
}
for(var i=0;i<this.registeredForwardAtEndListeners.length;i++){
var _32a=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);
}
var _32c="keydown";
if(isGecko){
_32c="keypress";
}
YAHOO.util.Event.addListener(document,_32c,function(e){
var _32e=(e.target)?e.target:e.srcElement;
if(_32e.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);
}
};
Board.prototype.flipBoard=function(){
this.isUserFlipped=!this.isUserFlipped;
this.isFlipped=!this.isFlipped;
this.redrawBoard();
};
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.highlightFromTo){
if(!this.isFlipped){
var _334=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _335=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _334=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _335=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_334,_335,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.fenPositionOnly=function(fen){
var _337=fen.split(" ");
return _337[0]+" "+_337[1];
};
Board.fenStripMoveClock=function(fen){
var _339=fen.split(" ");
return _339[0]+" "+_339[1]+" "+_339[2]+" "+_339[3];
};
Board.fenSamePosition=function(fen1,fen2,_33c){
if(!fen1||!fen2){
return false;
}
var f1=null;
var f2=null;
if(_33c){
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,_342){
var res=this.findFen2(mv,brd,fen,true);
if(res.move){
return res.move;
}else{
if(_342){
if(res.clockStrip){
return res.clockStrip;
}else{
if(res.fullStrip){
return res.fullStrip;
}
}
}
}
return null;
};
Board.prototype.findFen2=function(mv,brd,fen,_347){
var _348=brd.cloneBoard();
var res=Object();
var _34a=null;
var _34b=null;
res.move=null;
if(_347){
_348.gotoMoveIndex(-1,true,true,true,true);
}
var _34c=null;
while(mv){
var _34d=_348.boardToFen();
if(_34d==fen){
res.move=_34c;
res.clockStrip=null;
res.fullStrip=null;
return res;
}else{
if(Board.fenSamePosition(fen,_34d)){
_34a=_34c;
}else{
if(Board.fenSamePosition(fen,_34d,true)){
_34b=_34c;
}
}
}
if(mv.atEnd){
break;
}
if(mv.vars&&mv.vars.length>0){
for(var i=0;i<mv.vars.length;i++){
var _34f=findFen(mv.vars[i],_348,fen,false);
if(_34f.move){
return _34f;
}else{
if(_34f.clockStrip){
_34a=_34f.clockStrip;
}else{
if(_34f.fullStrip){
_34b=_34f.fullStrip;
}
}
}
}
}
if(clog){
console.log("about to make mv:"+mv.output());
}
_348.makeMove(mv,_348.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("finished making mv");
}
_34c=mv;
mv=mv.next;
if(clog){
console.log("toMove:"+_348.toMove);
}
_348.setCurrentMove(mv);
_348.toggleToMove();
}
if(_34a){
res.clockStrip=_34a;
}
if(_34b){
res.fullStrip=_34b;
}
return res;
};
Board.prototype.gotoFen=function(fen,_351){
if(clog){
console.log("about to find fen for:"+fen);
}
var _352=this.findFen(this.moveArray[0],this,fen,_351);
if(_352){
if(clog){
console.log("found move:"+_352.output()+" for fen:"+fen);
}
this.gotoMoveIndex(_352.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(_353,_354,_355,_356,_357){
if(clog){
console.log("going to move index:"+_353);
}
var _358=!_355;
if(!this.moveArray||this.moveArray.length<=_353||(_353==-1&&this.moveArray.length==0)){
return;
}
var _359=this.boardName+"-piecestaken";
var _35a=YAHOO.util.Dom.get(_359);
if(_35a){
_35a.innerHTML="";
}
if(_353==-1){
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,_357);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],!_355,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_354);
}else{
this.setCurrentMove(this.firstMove,_354);
}
if(!_354){
this.setForwardBack();
}
if(!_356){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _35d=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_353);
}
}
return;
}
var _35e=new Array();
var move=this.moveArray[_353];
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 _360=0;
if(move.next!=null){
this.setCurrentMove(move.next,_354);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null&&!move.dummy){
_35e[_360++]=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=_360-1;i>=1;i--){
var move=_35e[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,false);
this.toggleToMove();
}
if(!_354){
this.convertPiecesFromLightWeight(_353);
}
var move=_35e[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],_358,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_354){
this.setForwardBack();
}
if(!_356){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _35d=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_353);
}
}
};
Board.prototype.gotoStart=function(e){
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(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 _363=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);
_363=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
}
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _366=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_363);
}
};
Board.prototype.gotoPly=function(_367,_368){
if(clog){
console.log("goto ply called");
}
this.gotoMoveIndex(-1,true,true,true);
var cnt=1;
var _36a=0;
while(cnt<=_367&&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);
_36a=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
cnt++;
}
if(_368){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _36d=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_36a);
}
}
};
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 _370=".vers"+SITE_VERSION;
if(!this.addVersion){
_370="";
}
return _370;
};
Board.prototype.playMoves=function(e){
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 _376=this.registeredPasteFenClickedListeners[i].pasteFenClickedCallback();
}
};
Board.prototype.showBoardFen=function(e){
var fen=this.boardToFen();
var _379=new YAHOO.widget.SimpleDialog("fenDialog",{fixedcenter:true,visible:true,draggable:false,constraintoviewport:true,buttons:[{id:"linkbutton4",text:"Test"},{text:_js("Ok"),handler:function(){
_379.hide();
},isDefault:true}]});
_379.setHeader(_js("Position FEN"));
_379.setBody("<textarea class=\"showPgn\" id=\"fenText\" rows=\"1\" readonly=\"true\" cols=\""+(fen.length+9)+"\">"+fen+"</textarea>");
_379.render(document.body);
_379.setFooter("<span id=\"copyToComment\"></span><span id=\"fenok\"></span>");
var _37a=this;
if(this.problem&&this.problem.comments){
var _37b=new YAHOO.widget.Button({type:"button",label:_js("Copy To Comment"),container:"fenok",onclick:{fn:function(){
_37a.copyFenToComment(fen,Board.COPY_COMMENT_PROBLEM);
_379.hide();
}}});
}
if(this.gameComments){
var _37c=new YAHOO.widget.Button({type:"button",label:_js("Copy To Game Comment"),container:"fenok",onclick:{fn:function(){
_37a.copyFenToComment(fen,Board.COPY_COMMENT_GAME);
_379.hide();
}}});
}
if(this.playerComments){
var _37d=new YAHOO.widget.Button({type:"button",label:_js("Copy To Player Comment"),container:"fenok",onclick:{fn:function(){
_37a.copyFenToComment(fen,Board.COPY_COMMENT_PLAYER);
_379.hide();
}}});
}
if(this.openingComments){
var _37e=new YAHOO.widget.Button({type:"button",label:_js("Copy To Opening Comment"),container:"fenok",onclick:{fn:function(){
_37a.copyFenToComment(fen,Board.COPY_COMMENT_OPENING);
_379.hide();
}}});
}
var _37f=new YAHOO.widget.Button({type:"button",label:_js("Ok"),container:"fenok",onclick:{fn:function(){
_379.hide();
}}});
};
Board.prototype.copyFenToComment=function(fen,_381){
switch(_381){
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(_385,fen,flip,_388){
switch(_388){
case (Board.COPY_COMMENT_PROBLEM):
if(this.problem){
this.problem.comments.copyAnalysisToComment(_385,fen,flip);
}
break;
case (Board.COPY_COMMENT_GAME):
this.gameComments.copyAnalysisToComment(_385,fen,flip);
break;
case (Board.COPY_COMMENT_PLAYER):
this.playerComments.copyAnalysisToComment(_385,fen,flip);
break;
case (Board.COPY_COMMENT_OPENING):
this.openingComments.copyAnalysisToComment(_385,fen,flip);
break;
}
};
Board.prototype.analysePosition=function(e){
window.parentBoard=this;
var _38a=(this.pieceSize*8)+450+50;
var _38b=(this.pieceSize*8)+250;
var _38c=window.open("/windows/analyse.html","analysis_window","width="+_38a+",height="+_38b+",resizable=1,scrollbars=1,location=0,copyhistory=0,status=0,toolbar=0,menubar=0");
_38c.focus();
};
Board.prototype.backMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
var _38e=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;
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];
var _38f=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_38f=true;
}
this.moveNumber--;
if(this.moveNumber<=0){
this.moveNumber=1;
}
if(takenPiece&&!_38f){
this.board_xy=null;
var _390=move.toColumn;
var _391=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_391=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_390,_391,false,null,this.moveAnimationLength);
this.boardPieces[_390][_391]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_38f){
var _392=move.toRow;
var _393;
var _394;
if(move.fromColumn>move.toColumn){
_393=0;
_394=3;
}else{
_393=7;
_394=5;
}
var _395=this.boardPieces[_394][_392];
_395.setPosition(_393,_392,true,null,this.moveAnimationLength);
this.boardPieces[_393][_392]=_395;
this.boardPieces[_394][_392]=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 _397=this.registeredBackMovePreCurrentListeners[i].backMovePreCurrentCallback(move,_38e);
}
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.processTaken=function(_39c,_39d){
var _39e=this.boardName+"-piecestaken";
var _39f=YAHOO.util.Dom.get(_39e);
if(_39f){
if(_39d){
var _3a0=get_image_str(ChessPiece.pieceIconNames[_39c.colour][_39c.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_39f.innerHTML=_39f.innerHTML+"<img src=\""+_3a0+"\"/>";
}else{
var _3a1=_39f.innerHTML.split("<");
_39f.innerHTML="";
for(var i=1;i<_3a1.length-1;i++){
_39f.innerHTML=_39f.innerHTML+"<"+_3a1[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(_3a5){
var _3a6=_3a5.changedTouches,_3a7=_3a6[0],type="";
switch(_3a5.type){
case "touchstart":
type="mousedown";
break;
case "touchmove":
type="mousemove";
break;
case "touchend":
type="mouseup";
break;
default:
return;
}
var _3a9=document.createEvent("MouseEvent");
_3a9.initMouseEvent(type,true,true,window,1,_3a7.screenX,_3a7.screenY,_3a7.clientX,_3a7.clientY,false,false,false,false,0,null);
_3a7.target.dispatchEvent(_3a9);
_3a5.preventDefault();
}
function initIphone(_3aa){
_3aa.addEventListener("touchstart",touchHandler,true);
_3aa.addEventListener("touchmove",touchHandler,true);
_3aa.addEventListener("touchend",touchHandler,true);
_3aa.addEventListener("touchcancel",touchHandler,true);
}
FenBoard=function(fen,_3ac){
_3ac.pieceSize=24;
_3ac.fenBoard=true;
_3ac.dontOutputNavButtons=true;
_3ac.avoidMouseoverActive=true;
this.chessapp=new ChessApp(_3ac);
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;
};

