/* Copyright 2007 Richard Jones
This work is licensed under the Creative Commons [insert description] License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.5/au/
*/
PgnViewer=function(_1){
var _2=new BoardConfig();
_2.applyConfig(_1);
if(!window._pvObject){
window._pvObject=new Array();
}
window._pvObject[_2.boardName]=this;
_1=_2;
_1.pgnMode=true;
this.chessapp=new ChessApp(_1);
YAHOO.util.Event.addListener(window,"load",this.chessapp.init,this.chessapp,true);
};
PgnViewer.prototype.setupFromPgn=function(_3){
this.chessapp.pgn.setupFromPGN(_3);
};
PGNGame=function(_4,_5,_6,_7,_8,_9,_a,_b,_c,_d){
this.movesseq=_4;
this.startFen=_5;
this.blackPlayer=_6;
this.whitePlayer=_7;
this.pgn_result=_8;
this.event=_9;
this.site=_a;
this.date=_b;
this.round=_c;
this.start_movenum=_d;
};
PGN=function(_e){
this.board=_e;
this.pgnGames=new Array();
};
PGN.prototype.getPGNFromURL=function(_f){
YAHOO.util.Connect.asyncRequest("POST",_f,{success:function(o){
this.setupFromPGN(o.responseText);
},failure:function(o){
YAHOO.log("pgn load failed:"+o.statusText+" for file:"+_f);
alert("pgn load failed:"+o.statusText+" for file:"+_f);
},scope:this},"emptyText");
};
PGN.prototype.getMoveFromPGNMove=function(_12,_13,_14){
var _15=false;
var _16=false;
var _17=false;
var _18;
var _19=null;
var _1a=false;
var _1b=null;
if(_12.charAt(_12.length-1)=="#"){
_16=true;
_15=true;
_12=_12.substr(0,_12.length-1);
}else{
if(_12.charAt(_12.length-1)=="+"){
_16=true;
if(_12.length>1&&_12.charAt(_12.length-2)=="+"){
_15=true;
_12=_12.substr(0,_12.length-2);
}else{
_12=_12.substr(0,_12.length-1);
}
}
}
if(_12=="O-O-O"){
if(_13=="w"){
return this.board.createMoveFromString("e1c1");
}else{
return this.board.createMoveFromString("e8c8");
}
}else{
if(_12=="O-O"){
if(_13=="w"){
return this.board.createMoveFromString("e1g1");
}else{
return this.board.createMoveFromString("e8g8");
}
}
}
var _1c=_12.indexOf("=");
if(_1c>=0){
var _1d;
_19=_12.substr(_1c+1,1);
_1d=_19.charAt(0);
_18=this.board.pieceCharToPieceNum(_1d);
_17=true;
_12=_12.substr(0,_1c);
}
var _1e=_12.substr(_12.length-2,2);
var _1f=_1e.charCodeAt(0)-"a".charCodeAt(0);
var _20=_1e.charCodeAt(1)-"1".charCodeAt(0);
if(_1f>7||_1f<0||_20>7||_20<0){
alert("PgnViewer: Error processing to Square:"+_1e+" on move:"+_12);
return null;
}
if(_12.length>2){
if(_12.charAt(_12.length-3)=="x"){
_1a=true;
_1b=_12.substr(0,_12.length-3);
}else{
_1b=_12.substr(0,_12.length-2);
}
}
var _21=new Array();
var _22=0;
var _23=null;
var _24=(_13=="w")?ChessPiece.WHITE:ChessPiece.BLACK;
switch(_12.charAt(0)){
case "K":
case "k":
_23=ChessPiece.KING;
break;
case "Q":
case "q":
_23=ChessPiece.QUEEN;
break;
case "R":
case "r":
_23=ChessPiece.ROOK;
break;
case "B":
_23=ChessPiece.BISHOP;
break;
case "N":
case "n":
_23=ChessPiece.KNIGHT;
break;
case "P":
case "p":
_23=ChessPiece.PAWN;
break;
default:
_23=ChessPiece.PAWN;
}
var _25=null;
var _26=null;
if(_1b){
var _27=_1b.toLowerCase().charAt(0);
if(_27==_1b.charAt(0)&&_27>="a"&&_27<="h"){
_26=_27;
if(_1b.length==2){
_25=_1b.charAt(1);
}
}else{
if(_1b.length>1){
if(_1b.length==2){
var c=_1b.charAt(1);
if(c>="1"&&c<="8"){
_25=c;
}else{
_26=c;
}
}else{
if(_1b.length==3){
_26=_1b.charAt(1);
_25=_1b.charAt(2);
if(_26>="1"&&_26<="9"){
var tmp=_26;
_26=_25;
_25=tmp;
}
}else{
alert("PgnViewer: Error: unhandled fromChars:"+_1b);
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==_24&&bp.piece==_23){
if(this.board.canMove(bp,_1f,_20,_14,true)){
var _2d=String.fromCharCode("a".charCodeAt(0)+i).charAt(0);
var _2e=String.fromCharCode("1".charCodeAt(0)+j).charAt(0);
if((_26==null||_26==_2d)&&(_25==null||_25==_2e)){
_21[_22++]=bp;
}else{
}
}
}
}
}
if(_22==0){
alert("PgnViewer: no candidate pieces for:"+_12);
return null;
}
if(_22>1){
alert("PgnViewer: Ambiguous:"+_12+" with fromChars:"+_1b+" disRow:"+_25+" disCol:"+_26);
return null;
}
var _2f=_21[0];
var _30="";
_30+=String.fromCharCode("a".charCodeAt(0)+_2f.column);
_30+=String.fromCharCode("1".charCodeAt(0)+_2f.row);
if(_1a){
_30+="x";
}
_30+=_1e;
if(_19){
_30+=_19;
}
var _31=this.board.createMoveFromString(_30);
return _31;
};
PGN.prototype.parseTag=function(_32,pgn,_34){
if(pgn.substr(_34,_32.length+3)=="["+_32+" \""){
var _35=pgn.indexOf("\"",_34+_32.length+3);
if(_35>=0){
return pgn.substring(_34+_32.length+3,_35);
}
}
return null;
};
PGN.prototype.setupFromPGN=function(pgn){
var _37=new Array();
var _38=new Array();
var _39=0;
this.pgnGames=new Array();
pgn=pgn.replace(/^\s+|\s+$/g,"");
var _3a=0;
this.pgn=pgn;
this.setupFromPGN_cont(_37,_38,_39,_3a);
};
PGN.prototype.setupFromPGN_cont=function(_3b,_3c,_3d,_3e){
var _3f=new Date().getTime();
var pgn=this.pgn;
var _41=this.board.boardName+"-progress";
var _42=YAHOO.util.Dom.get(_41);
while(_3e<pgn.length){
var _43="";
var _44="";
var _45="";
var _46="";
var _47="";
var _48="";
var _49="";
var _4a="w";
var _4b=0;
var _4c=0;
var _4d=new Array();
var _4e=0;
var _4f="";
var _50=null;
var _51=null;
var _52=new Array();
var _53=new Array();
var _54=new Array();
var _55=new Array();
var _56=new Array();
this.board.pieceMoveDisabled=true;
this.board.startFen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
var i=0;
for(i=_3e;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!="?"){
_49=tag;
}else{
tag=this.parseTag("Black",pgn,i);
if(tag&&tag!="?"){
_44=tag;
}else{
tag=this.parseTag("Result",pgn,i);
if(tag&&tag!="?"){
_43=tag;
}else{
tag=this.parseTag("Event",pgn,i);
if(tag&&tag!="?"){
_45=tag;
}else{
tag=this.parseTag("Site",pgn,i);
if(tag&&tag!="?"){
_46=tag;
}else{
tag=this.parseTag("Date",pgn,i);
if(tag&&tag!="?"){
_47=tag;
}else{
tag=this.parseTag("Round",pgn,i);
if(tag&&tag!="?"){
_48=tag;
}
}
}
}
}
}
}
}
if(pgn.charAt(i)=="["){
var j=pgn.indexOf;
for(j=i+1;j<pgn.length&&pgn.charAt(j)!="]";j++){
}
if(j==pgn.length){
alert("PgnViewer: Error parsing PGN. Found unclosed [");
return false;
}
i=j-1;
continue;
}
if(pgn.charAt(i)=="{"){
var _5a=pgn.indexOf("}",i+1);
if(_5a>=0){
var _5b=pgn.substring(i+1,_5a);
i=_5a;
_4f+="{ "+_5b+" } ";
}else{
alert("PgnViewer: Error parsing PGN. Found unclosed {");
return false;
}
continue;
}
var _5c=1;
if(pgn.substr(i,1)=="."){
var j=i-1;
while(j>0&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
j--;
}
if(j>0){
_5c=parseInt(pgn.substring(j+1,i));
}
break;
}
}
if(pgn.substr(i,1)!="."){
//alert("PgnViewer: Error: Could not find movelist:"+pgn.substr(i));
return false;
}
this.board.setupFromFen(this.board.startFen,false,false,true);
var _5d=i;
var _5e=null;
for(i=i;i<pgn.length;i++){
var _5f=-1;
if(pgn.substr(i,3)=="1-0"||pgn.substr(i,3)=="0-1"){
_5f=3;
}else{
if(pgn.substr(i,7)=="1/2-1/2"){
_5f=7;
}else{
if(pgn.substr(i,1)=="*"){
_5f=1;
}
}
}
if(_5f>0){
_5e=pgn.substr(i,_5f);
_3e=i+_5f;
break;
}
if(pgn.charAt(i)=="["){
_3e=i;
break;
}
if(pgn.charAt(i)==" "||pgn.charAt(i)=="\t"||pgn.charAt(i)=="\n"||pgn.charAt(i)=="\r"){
_5d=i+1;
continue;
}
if(pgn.charAt(i)>="0"&&pgn.charAt(i)<="9"){
continue;
}
if(pgn.charAt(i)=="."){
var _60=pgn.substring(_5d,i).replace(/^\s+|\s+$/g,"");
_5d=i;
while(i+1<pgn.length&&pgn.charAt(i+1)=="."){
i++;
}
if(_5d!=i){
_4a="b";
}else{
_4a="w";
}
_5d=i+1;
}else{
if(pgn.charAt(i)=="{"){
var _5a=pgn.indexOf("}",i+1);
if(_5a>=0){
var _5b=pgn.substring(i+1,_5a);
i=_5a;
_4f+="{ "+_5b+" } ";
}
_5d=i+1;
}else{
if(pgn.charAt(i)=="("){
_52[_4b]=this.board.boardPieces;
_53[_4b]=_4a;
_55[_4b]=_50;
_56[_4b]=_51;
this.board.boardPieces=_54[_4b];
this.board.boardPieces=this.board.copyBoardPieces(false);
_50=_51;
_4b++;
_5d=i+1;
_4f+="( ";
}else{
if(pgn.charAt(i)==")"){
boardPool.putObject(_52[_4b]);
_4b--;
this.board.boardPieces=_52[_4b];
_4a=_53[_4b];
_50=_55[_4b];
_51=_56[_4b];
_5d=i+1;
_4f+=") ";
}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 _61=parseInt(pgn.substr(i+1,j+1));
if(_61<=9){
switch(_61){
case 1:
_4f=_4f.substr(0,_4f.length-1)+"! ";
break;
case 2:
_4f=_4f.substr(0,_4f.length-1)+"? ";
break;
case 3:
_4f=_4f.substr(0,_4f.length-1)+"!! ";
break;
case 4:
_4f=_4f.substr(0,_4f.length-1)+"?? ";
break;
case 5:
_4f=_4f.substr(0,_4f.length-1)+"!? ";
break;
case 6:
_4f=_4f.substr(0,_4f.length-1)+"?! ";
break;
case 7:
case 8:
case 9:
case 0:
default:
}
}else{
_4f+=pgn.substring(i,j+1)+" ";
}
i=j;
}
continue;
}else{
var _62=-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"){
_62=j;
break;
}
}
if(_62==-1){
_62=pgn.length;
}
var _63=_5d;
var _64=pgn.substring(_5d,_62).replace(/^\s+|\s+$/g,"");
_5d=_62;
i=_5d-1;
if(_64.length==0){
alert("PgnViewer: Error: got empty move endMoveInd:"+_62+" upto:"+_63+" from:"+pgn.substr(_63)+"#");
return false;
}
var _65=_64.length-1;
while(_65>=0){
if(_64.charAt(_65)=="?"){
_65--;
}else{
if(_64.charAt(_65)=="!"){
_65--;
}else{
break;
}
}
}
var _66=_64.substring(0,_65+1);
var _67=this.getMoveFromPGNMove(_66,_4a,_50);
if(_67==null){
_4f+="unknown ";
alert("PgnViewer: Error parsing:"+_64);
return false;
}
_51=_50;
_50=_67;
var _68=this.board.boardPieces[_67.fromColumn][_67.fromRow];
boardPool.putObject(_54[_4b]);
_54[_4b]=this.board.copyBoardPieces(false);
if(_68){
this.board.makeMove(_67,_68,false,0.5,false,false);
}
_4c=_4b;
_4e++;
_4a=this.board.flipToMove(_4a);
_4f+=_67.moveString+"|"+_64+" ";
}
}
}
}
}
}
if(_3e<i){
_3e=i;
}
var _69=pgn.indexOf("{",_3e);
var _6a=pgn.indexOf("[",_3e);
if(_69>=0){
if(_6a==-1||_69<_6a){
var _6b=pgn.indexOf("}",_69+1);
if(_6b>=0){
var _5b=pgn.substring(_69+1,_6b);
_3e=_6b+1;
_4f+="{ "+_5b+" } ";
}else{
alert("PgnViewer: Error: Unclosed {");
return false;
}
}
}
_4f=_4f.replace(/^\s+|\s+$/g,"");
this.board.pieceMoveDisabled=false;
if(_5e!=null){
if(_43.length==0||_43=="?"){
_43=_5e;
}
}
this.pgnGames[_3d++]=new PGNGame(_4f,this.board.startFen,_44,_49,_43,_45,_46,_47,_48,_5c);
if(_42){
_42.innerHTML="Loaded "+_3d+" games";
}
if(new Date().getTime()-_3f>500){
setTimeout("window._pvObject[\""+this.board.boardName+"\"].chessapp.pgn.setupFromPGN_cont(\""+_3b+"\",\""+_3c+"\",\""+_3d+"\",\""+_3e+"\");",0);
return;
}
}
var _6c=YAHOO.util.Dom.get(this.board.boardName+"-problemSelectorForm");
if(_6c){
_6c.parentNode.removeChild(_6c);
}
if(this.pgnGames.length==0){
alert("PgnViewer: Error: Unable to find any pgn games in:"+pgn);
return false;
}
if(this.pgnGames.length==1){
this.showGame(0);
}else{
var _6d=this.board.boardName+"-container";
var _6e=YAHOO.util.Dom.get(_6d);
var _6f=document.createElement("div");
var _70="<form id=\""+this.board.boardName+"-problemSelectorForm\" action=\"\" method=\"\"><select id=\""+this.board.boardName+"-problemSelector\" name=\""+this.board.boardName+"-problemSelector\" style=\"width: "+this.board.pieceSize*8+"px;\">";
for(i=0;i<this.pgnGames.length;i++){
var _71=this.pgnGames[i];
var _72=this.board.boardName+"-game-"+i;
var _73=(i+1)+". "+_71.whitePlayer+" vs "+_71.blackPlayer;
if(_71.pgn_result.length>0&&_71.pgn_result!="?"&&this.board.showResult==1){
_73+=" "+_71.pgn_result;
}
if(_71.event.length>0&&_71.event!="?"&&this.board.showEvent==1){
_73+=" "+_71.event;
}
if(_71.round.length>0&&_71.round!="?"&&this.board.showRound==1){
_73+=" Rnd:"+_71.round;
}
if(_71.site.length>0&&_71.site!="?"&&this.board.showSite==1){
_73+=" "+_71.site;
}
if(_71.date.length>0&&_71.date!="?"&&this.board.showDate==1){
_73+=" "+_71.date;
}
_70+="<option id=\""+_72+"\" value=\""+i+"\">"+_73+"</option>";
}
_70+="</select></form>";
_6f.innerHTML=_70;
_6e.insertBefore(_6f,_6e.firstChild);
YAHOO.util.Event.addListener(this.board.boardName+"-problemSelector","change",this.selectGame,this,true);
this.showGame(0);
}
if(_42){
YAHOO.util.Dom.setStyle(_42,"visibility","hidden");
_42.appendChild(_42);
}
return;
};
PGN.prototype.selectGame=function(e){
var _75=YAHOO.util.Event.getTarget(e).selectedIndex;
this.showGame(_75);
var _76=this.board.boardName+"-piecestaken";
var _77=YAHOO.util.Dom.get(_76);
if(_77){
_77.innerHTML="";
}
};
PGN.prototype.showGame=function(_78){
this.board.startFen=this.pgnGames[_78].startFen;
this.board.setupFromFen(this.pgnGames[_78].startFen,false,false,false);
this.board.setMoveSequence(this.pgnGames[_78].movesseq,"NA",this.pgnGames[_78].start_movenum,this.pgnGames[_78].pgn_result);
this.board.setCurrentMove(this.board.moveArray[0]);
this.board.displayMode=true;
};

var SITE_VERSION=1;
BoardConfig=function(){
this.boardName="board";
this.pgnString=null;
this.pgnFile=null;
this.pieceSet="merida";
this.pieceSize=46;
this.tr=false;
this.ml=9999;
this.autoScrollMoves=false;
this.showNPS=false;
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=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;
};
BoardConfig.prototype.applyConfig=function(_1){
for(var _2 in _1){
this[_2]=_1[_2];
}
};
ChessApp=function(_3){
this.displayMode=false;
this.config=_3;
this.board=null;
};
ChessApp.prototype.setDisplayMode=function(_4){
this.displayMode=_4;
};
ChessApp.prototype.setProblemNumber=function(_5){
this.problemNumber=_5;
};
ChessApp.prototype.init=function(us){
ChessPiece.init();
this.board=new Board(this.config.boardName);
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)?null:new TacticsUI(this.board);
this.problem=(this.config.pgnMode)?null:new ProblemUI(this.board,this.tactics);
this.board.tactics=this.tactics;
this.pgn=(this.config.pgnMode)?new PGN(this.board):null;
var _7=MovesDisplay.DEFAULT_DISPLAY_TYPE;
if(this.config.movesFormat=="main_on_own_line"){
_7=MovesDisplay.MAIN_ON_OWN_LINE;
}
this.movesDisplay=new MovesDisplay(this.board,_7);
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.tr=this.config.tr;
this.board.ml=this.config.ml;
this.board.autoScrollMoves=this.config.autoScrollMoves;
this.board.pieceSize=this.config.pieceSize;
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;
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.setupEventHandlers();
if(this.problem){
this.problem.setupEventHandlers();
}
if(this.tactics){
this.tactics.setupEventHandlers();
}
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);
}else{
this.pgn.setupFromPGN(this.config.pgnString);
}
}else{
if(this.tactics){
YAHOO.util.Event.addListener(window,"unload",this.tactics.leavingPage,this.tactics,true);
this.tactics.updateSessionDisplay(0,0);
this.problem.getProblem();
}else{
if(this.problem){
if(this.problemNumber!=""){
this.problem.getProblem(this.problemNumber);
}
}
}
}
};
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 _a=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_a[prop]=o[prop];
}else{
_a[prop]=o[prop];
}
}
return _a;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_c,_d,_e,_f){
if(check_bad_msie()){
return _d+"/images/"+_e+"/"+_c+_f+".vers"+SITE_VERSION+".png";
}else{
return _d+"/images/"+_e+"/"+_c+_f+".vers"+SITE_VERSION+".png";
}
};
check_bad_msie=function(){
return (window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _11=(img.id)?"id='"+img.id+"' ":"";
var _12=(img.className)?"class='"+img.className+"' ":"";
var _13=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _14="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_14="float:left;"+_14;
}
if(img.align=="right"){
_14="float:right;"+_14;
}
if(img.parentElement.href){
_14="cursor:hand;"+_14;
}
var _15="<span "+_11+_12+_13+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_14+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_15;
};
Move=function(_16,_17,_18,_19,_1a,_1b,_1c){
this.fromColumn=_16;
this.fromRow=_17;
this.toColumn=_18;
this.toRow=_19;
this.take=_1a;
this.promotion=_1b;
this.moveString=_1c;
this.prev=null;
this.next=null;
this.numVars=0;
this.atEnd=false;
};
function getTagValue(_1d,_1e){
var _1f=_1d.getElementsByTagName(_1e);
if(_1f==null){
YAHOO.log("got null node for tag:"+_1e);
return null;
}
if(_1f.length==0){
YAHOO.log("got empty array node for tag:"+_1e);
return null;
}
if(_1f[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_1e);
return null;
}
if(_1f[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_1e);
return null;
}
if(typeof (_1f[0].textContent)!="undefined"){
return _1f[0].textContent;
}
return _1f[0].firstChild.nodeValue;
}
ChessPiece=function(div,_21,_22,_23){
var id=div.id;
this.board=_23;
this.icon=get_image_str(ChessPiece.pieceIconNames[_21][_22],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize);
this.colour=_21;
this.piece=_22;
this.id=id;
this.div=div;
var _25=_23.getPieceDragDiv();
var _26=false;
if(_25==null){
_25=document.createElement("div");
_25.id="pieceDragDiv";
_26=true;
YAHOO.util.Dom.setStyle(_25,"visibility","hidden");
YAHOO.util.Dom.setStyle(_25,"border","0px");
YAHOO.util.Dom.setStyle(_25,"position","absolute");
}
this.pieceDragEl=_25;
this.pieceDragElId="pieceDragDiv";
if(_26){
var _27=document.getElementsByTagName("body");
if(_27==null||_27.length==0){
alert("Could not find body tag");
}else{
_27[0].appendChild(_25);
}
}
if(YAHOO.util.Event.isIE){
var _28=this.div;
_28.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_28.firstChild;
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");
}
YAHOO.util.Dom.setStyle([this.div],"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"width",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"border","0px");
YAHOO.util.Dom.setStyle([this.div],"padding","0px");
var ua=navigator.userAgent.toLowerCase();
var _2b=(ua.indexOf("opera")>-1);
if(false&&_2b){
YAHOO.util.Dom.setStyle([this.div],"position","absolute");
}else{
YAHOO.util.Dom.setStyle([this.div],"position","relative");
}
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:false,centreFrame: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.prototype.oldIsValidHandleChild=ChessPiece.prototype.isValidHandleChild;
ChessPiece.prototype.oldStartDrag=ChessPiece.prototype.startDrag;
ChessPiece.prototype.isValidHandleChild=function(_2c){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
return this.oldIsValidHandleChild(_2c);
};
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,0.5);
}
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","visible");
};
ChessPiece.prototype.startDrag=function(x,y){
this.insideBoard=true;
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,"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 _38=7-i;
var _39=j;
if(this.board.isFlipped){
_38=7-_38;
_39=7-_39;
}
if((_38==this.row&&_39==this.column)||this.board.canMove(this.makeLightWeight(),_39,_38,this.board.currentMove.prev,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 _3e=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _3f=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_3e)/this.board.pieceSize);
var r=parseInt((y-_3f)/this.board.pieceSize);
var _42=this.board.boardName+"-s"+c+""+(7-r);
var _43=YAHOO.util.Dom.get(_42);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_43){
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&&this.candidates[c][r]){
YAHOO.util.Dom.addClass(_43,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_43,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_43;
}
};
ChessPiece.prototype.onDragDrop=function(e,id){
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 _48=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _49=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_48)/this.board.pieceSize);
var r=parseInt((y-_49)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _4c=false;
if(this.board.currentMove.atEnd){
_4c=true;
}
this.board.updatePiece(this,c,7-r,false,false);
if(!_4c&&this.board.currentMove.atEnd){
if(this.board.toMove==ChessPiece.WHITE){
this.board.toMove=ChessPiece.BLACK;
}else{
this.board.toMove=ChessPiece.WHITE;
}
this.board.updateToPlay();
}
};
ChessPiece.prototype.removeFromParent=function(){
var _4d=this.div;
if(_4d.parentNode){
_4d.parentNode.removeChild(_4d);
}
};
ChessPiece.prototype.setVisible=function(_4e){
var _4f;
if(_4e){
_4f="visible";
}else{
_4f="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_4f);
};
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.changePiece=function(_52){
var _53=(_52+"").toLowerCase().charAt(0);
switch(_53){
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:
}
this.icon=get_image_str(ChessPiece.pieceIconNames[this.colour][this.piece],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize);
if(YAHOO.util.Event.isIE){
var _54=this.div;
_54.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_54.firstChild;
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(_56,row){
var _58=this.board.getBoardDiv();
var _59=this.board.getXY();
var _5a=_59[0];
var _5b=_59[1];
var _5c=[0,0];
if(this.board.isFlipped){
_5c[0]=_5a+((7-_56)*this.board.pieceSize);
_5c[1]=_5b+((row)*this.board.pieceSize);
}else{
_5c[0]=_5a+((_56)*this.board.pieceSize);
_5c[1]=_5b+((7-row)*this.board.pieceSize);
}
return _5c;
};
ChessPiece.prototype.setPosition=function(_5d,row,_5f,_60,_61){
this.column=_5d;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _62=this.div;
if(!_5f){
if(!this.board.settingUpPosition){
var _63=this.getNewXYPosition(_5d,row);
YAHOO.util.Dom.setXY(_62,_63,false);
}else{
var _64=null;
if(this.board.isFlipped){
_64=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_64=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _65=this.board[_64];
if(_62.parentNode){
_62.parentNode.removeChild(_62);
}
_65.appendChild(_62);
}
this.setVisible(true);
if(_60){
_60();
}
}else{
var _63=this.getNewXYPosition(_5d,row);
var _66=new YAHOO.util.Motion(_62,{points:{to:_63}});
_66.duration=_61;
var _67=this;
_66.onComplete.subscribe(function(){
});
if(_60){
_66.onComplete.subscribe(_60);
}
_66.animate();
}
};
LightweightChessPiece=function(div,_69,_6a,_6b){
this.board=_6b;
this.colour=_69;
this.piece=_6a;
this.div=div;
};
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(_6d){
};
LightweightChessPiece.prototype.unreg=function(){
};
LightweightChessPiece.prototype.setPosition=function(_6e,row,_70,_71,_72){
this.column=_6e;
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(_74){
var _75=(_74+"").toLowerCase().charAt(0);
switch(_75){
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(_76,_77){
this.board=_76;
this.displayType=_77;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_78){
this.boardName=_78;
if(_78){
this.initTarget("ctb-"+_78,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
};
Board.prototype=new YAHOO.util.DDTarget();
Board.createBoardArray=function(){
var _79=boardPool.getObject();
if(_79==null){
_79=new Array(8);
for(var i=0;i<8;i++){
_79[i]=new Array(8);
}
}
return _79;
};
Board.prototype.setupPieceDivs=function(){
var _7b=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].unreg();
}
}
}
this.availIds=new Array(32);
this.availPieceDivs=new Array(32);
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.makeMove=function(_7d,_7e,_7f,_80,_81,_82){
var _83;
var _84;
if(!this.isFlipped){
_83=YAHOO.util.Dom.get(this.boardName+"-s"+_7d.fromColumn+""+_7d.fromRow);
_84=YAHOO.util.Dom.get(this.boardName+"-s"+_7d.toColumn+""+_7d.toRow);
}else{
_83=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_7d.fromColumn)+""+(7-_7d.fromRow));
_84=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_7d.toColumn)+""+(7-_7d.toRow));
}
if(_82){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
this.lastFromSquare=_83;
this.lastToSquare=_84;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_83,"ct-from-square");
YAHOO.util.Dom.addClass(_84,"ct-to-square");
}
}
var _85=this.boardPieces[_7d.toColumn][_7d.toRow];
if(_85!=null){
_85.enPassant=false;
_85.castled=false;
}
if(_7e.piece==ChessPiece.PAWN&&_7d.toColumn!=_7d.fromColumn&&this.boardPieces[_7d.toColumn][_7d.toRow]==null){
_85=this.boardPieces[_7d.toColumn][_7d.fromRow];
this.boardPieces[_7d.toColumn][_7d.fromRow]=null;
if(_85!=null){
_85.enPassant=true;
}
}
var _86=null;
if(_7e.piece==ChessPiece.KING&&Math.abs(_7d.toColumn-_7d.fromColumn)>1){
var _87;
var _88;
if(_7d.toColumn>_7d.fromColumn){
_86=this.boardPieces[7][_7d.fromRow];
_87=_7d.fromRow;
_88=5;
this.boardPieces[7][_7d.toRow]=null;
}else{
_86=this.boardPieces[0][_7d.fromRow];
_87=_7d.fromRow;
_88=3;
this.boardPieces[0][_7d.toRow]=null;
}
if(!_86){
alert("No castle piece");
}else{
_86.setPosition(_88,_87,_7f,null,_80);
this.boardPieces[_86.column][_86.row]=_86;
_86.castled=true;
}
}
_7d.taken=_85;
if(_85&&_81){
this.processTaken(_85,true);
}
this.board_xy=null;
_7e.setPosition(_7d.toColumn,_7d.toRow,_7f,function(){
var tp=_85;
if(tp){
tp.setVisible(false);
}
},_80);
if(_7d.promotion!=null){
_7e.changePiece(_7d.promotion);
}
this.boardPieces[_7d.fromColumn][_7d.fromRow]=null;
this.boardPieces[_7d.toColumn][_7d.toRow]=_7e;
if(_86!=null){
_7d.taken=_86;
}
if(_7e.piece==ChessPiece.ROOK){
if(_7d.fromColumn==0){
this.canCastleQueenSide[_7e.colour]=false;
}else{
if(_7d.fromColumn==7){
this.canCastleKingSide[_7e.colour]=false;
}
}
}else{
if(_7e.piece==ChessPiece.KING){
this.canCastleQueenSide[_7e.colour]=false;
this.canCastleKingSide[_7e.colour]=false;
}
}
};
Board.prototype.updatePiece=function(_8a,col,row,_8d,_8e){
if(this.currentMove.atEnd){
this.board_xy=null;
_8a.setPosition(_8a.column,_8a.row,false,null,0.5);
YAHOO.log("already at end of move list");
return;
}
if(_8a.column==col&&_8a.row==row){
this.board_xy=null;
_8a.setPosition(_8a.column,_8a.row,false,null,0.5);
YAHOO.log("moved piece back to its orig position");
return;
}
if(this.tactics&&this.tactics.problemFirstMoveDate==0){
this.tactics.problemFirstMoveDate=new Date();
}
move=this.currentMove;
if(move.fromColumn==_8a.column&&move.fromRow==_8a.row&&move.toRow==row&&move.toColumn==col){
YAHOO.log("Made correct move");
this.makeMove(move,_8a,_8e,0.5,true,true);
this.setCurrentMove(this.currentMove.next);
if(this.currentMove.atEnd){
if(this.tactics&&this.tactics.problemActive){
var _8f=true;
if(this.tactics.session){
_8f=this.tactics.session.continueCorrect;
}
this.tactics.markProblem(true,_8f,"NULL","NULL");
}
}
if(!_8d&&!this.currentMove.atEnd){
opponentMove=this.currentMove;
YAHOO.log("Updating opponent move fromcol:"+opponentMove.fromColumn+" frowRow:"+opponentMove.fromRow);
this.updatePiece(this.boardPieces[opponentMove.fromColumn][opponentMove.fromRow],opponentMove.toColumn,opponentMove.toRow,true,true);
}
}else{
var _90=_8a.column;
var _91=_8a.row;
var _92=false;
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _94=move.vars[i];
if(_94.isAlt&&_94.fromColumn==_90&&_94.fromRow==_91&&_94.toRow==row&&_94.toColumn==col){
_92=true;
break;
}
}
}
if(_92){
var _95="That was a good move, but not the computer's first choice.<br/> Please keep looking for another move.";
var _96="Good Move - Keep Looking";
var _97=YAHOO.widget.SimpleDialog.ICON_INFO;
var _98=new YAHOO.widget.SimpleDialog("responseDialog",{fixedcenter:true,visible:true,draggable:false,icon:_97,modal:true,constraintoviewport:true,buttons:[{text:"Ok",handler:function(){
_98.hide();
},isDefault:true}]});
_98.setHeader(_96);
_98.setBody("<div>"+_95+"</div>");
_98.render(document.body);
}
YAHOO.log("Made wrong move moving back to col:"+_8a.column+" row:"+_8a.row);
this.board_xy=null;
_8a.setPosition(_8a.column,_8a.row,false,null,0.5);
if(!_92&&this.canMove(_8a.makeLightWeight(),col,row,this.currentMove.prev,true)){
if(this.tactics){
this.tactics.autoForward=false;
}
if(this.tactics&&this.tactics.problemActive){
var _99=true;
if(this.tactics.session){
_99=this.tactics.session.continueFailed;
}
var _9a=Math.round(move.moveNum/2);
var _9b=String.fromCharCode("a".charCodeAt(0)+_8a.column)+""+(_8a.row+1)+""+String.fromCharCode("a".charCodeAt(0)+col)+""+(row+1);
_9b+="|"+this.makeShortAlgabraic(_8a.column,_8a.row,col,row);
this.tactics.markProblem(false,_99,_9a,_9b);
}
}
}
};
Board.prototype.makeShortAlgabraic=function(_9c,_9d,_9e,_9f,_a0){
var _a1=this.boardPieces[_9c][_9d];
var _a2=_a1.piece;
var _a3=this.pieceTypeToChar(_a2);
var _a4="";
if(_a2==ChessPiece.PAWN){
if(_9c==_9e){
_a4=String.fromCharCode("a".charCodeAt(0)+_9c)+""+(_9f+1);
}else{
_a4=String.fromCharCode("a".charCodeAt(0)+_9c)+"x"+String.fromCharCode("a".charCodeAt(0)+_9e)+""+(_9f+1);
if(!this.boardPieces[_9e][_9f]){
_a4+=" e.p.";
}
}
}else{
if(_a2==ChessPiece.KING){
var _a5=Math.abs(_9c-_9e);
if(_a5==1||_a5==0){
_a4=_a3;
if(this.boardPieces[_9e][_9f]){
_a4+="x";
}
_a4+=String.fromCharCode("a".charCodeAt(0)+_9e)+""+(_9f+1);
}else{
if(_9e==6){
_a4="O-O";
}else{
_a4="O-O-O";
}
}
}else{
var _a6=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_a1.colour&&cp.piece==_a2&&!(_a1.column==cp.column&&_a1.row==cp.row)){
var _aa=null;
if(this.currentMove){
_aa=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_9e,_9f,_aa,true)){
_a6.push(cp);
}
}
}
}
_a4=_a3;
if(_a6.length>0){
var _ab=false;
var _ac=false;
for(var i=0;i<_a6.length;i++){
if(_a6[i].row==_9d){
_ac=true;
}
if(_a6[i].column==_9c){
_ab=true;
}
}
if(_ac||!(_ac||_ab)){
_a4+=String.fromCharCode("a".charCodeAt(0)+_9c);
}
if(_ab){
_a4+=""+(_9d+1);
}
}
if(this.boardPieces[_9e][_9f]){
_a4+="x";
}
_a4+=String.fromCharCode("a".charCodeAt(0)+_9e)+""+(_9f+1);
}
}
var _ae="";
if(_a0){
var _af=this.cloneBoard();
var _b0=ChessPiece.WHITE;
if(_af.boardPieces[_a0.fromColumn][_a0.fromRow].colour==ChessPiece.WHITE){
_b0=ChessPiece.BLACK;
}
_af.makeMove(_a0,_af.boardPieces[_a0.fromColumn][_a0.fromRow],false,0.5,false,false);
if(!_af.isKingSafe(_b0,_a0)){
_ae="+";
if(_af.isKingMated(_b0,_a0)){
_ae="#";
}
}
}
_a4+=_ae;
return _a4;
};
Board.prototype.createMoveFromString=function(_b1){
var _b2=0;
var _b3=false;
var _b4=null;
var _b5=_b1.charCodeAt(_b2++);
var _b6=_b1.charCodeAt(_b2++);
var _b7=_b1.split("|");
var pgn=null;
if(_b7.length>1){
pgn=_b7[1];
_b1=_b7[0];
}else{
_b1=_b7[0];
}
if(_b1.charAt(_b2)=="x"){
_b2++;
_b3=true;
}
var _b9=_b1.charCodeAt(_b2++);
var _ba=_b1.charCodeAt(_b2++);
if(_b2<_b1.length){
_b4=_b1.charAt(_b2);
}
var _bb=new Move(_b5-("a".charCodeAt(0)),_b6-("1".charCodeAt(0)),_b9-("a".charCodeAt(0)),_ba-("1".charCodeAt(0)),_b3,_b4,_b1);
_bb.pgn=pgn;
return _bb;
};
Board.prototype.setForwardBack=function(){
var _bc=YAHOO.util.Dom.get(this.boardName+"-back");
var _bd=YAHOO.util.Dom.get(this.boardName+"-forward");
var end=YAHOO.util.Dom.get(this.boardName+"-end");
var _bf=YAHOO.util.Dom.get(this.boardName+"-start");
if(this.currentMove.prev==null){
_bc.src=this.boardImagePath+"/images/resultset_previous_disabled.vers"+SITE_VERSION+".gif";
_bf.src=this.boardImagePath+"/images/disabled_resultset_first.vers"+SITE_VERSION+".gif";
}else{
_bc.src=this.boardImagePath+"/images/resultset_previous.vers"+SITE_VERSION+".gif";
_bf.src=this.boardImagePath+"/images/resultset_first.vers"+SITE_VERSION+".gif";
}
if(this.currentMove.atEnd){
_bd.src=this.boardImagePath+"/images/resultset_next_disabled.vers"+SITE_VERSION+".gif";
end.src=this.boardImagePath+"/images/disabled_resultset_last.vers"+SITE_VERSION+".gif";
}else{
_bd.src=this.boardImagePath+"/images/resultset_next.vers"+SITE_VERSION+".gif";
end.src=this.boardImagePath+"/images/resultset_last.vers"+SITE_VERSION+".gif";
}
};
Board.prototype.convertPiecesFromLightWeight=function(_c0){
var _c1=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 _c4=this.boardPieces[i][j];
var p=_c4.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,0.5);
p.setVisible(true);
}
}
}
var _c6=this.moveArray[_c0];
while(_c6!=null){
if(_c6.taken){
_c6.taken=_c6.taken.makeHeavyWeight();
}
_c6=_c6.prev;
}
this.settingUpPosition=_c1;
};
MovesDisplay.prototype.setToMove=function(_c7){
this.toMove=_c7;
};
MovesDisplay.prototype.gotoMove=function(e){
var _c9=parseInt(YAHOO.util.Event.getTarget(e).id.substr((this.board.boardName+"-m").length));
this.board.gotoMoveIndex(_c9);
};
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(_ca,_cb,_cc,_cd){
var _ce="";
if(_cb>this.board.ml){
return _ce;
}
if(this.board.ml==1&&_cd>1){
return _ce;
}
var _cf=this.getMovesDisplay();
if(_cf){
if(_ca==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_ce+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
_ce+="<br/>";
}
_ce+="<span>( </span>";
}
this.firstNonMove=false;
return _ce;
};
MovesDisplay.prototype.outputVariationEnd=function(_d0,_d1,_d2,_d3){
var _d4=this.getMovesDisplay();
var _d5="";
if(_d1>this.board.ml){
return _d5;
}
if(this.board.ml==1&&_d3>3){
return _d5;
}
if(_d4){
_d5+="<span>) </span>";
}
if(_d0==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _d5;
};
MovesDisplay.prototype.outputComment=function(_d6,_d7,_d8){
var _d9="";
if(this.board.ml==1){
return _d9;
}
var _da=this.getMovesDisplay();
if(_da){
if(_d7==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_d9+="<br/>";
}
_d9+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _db="ct-board-move-comment";
if(_d8){
_db="ct-board-move-alt-comment";
}
_d9+="<span class=\""+_db+"\"> "+_d6+" </span>";
if(_d7==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _d9;
};
MovesDisplay.prototype.outputNag=function(_dc){
var _dd="";
var _de=this.getMovesDisplay();
if(_de){
var _df=null;
switch(_dc){
case 11:
_df="=";
break;
case 14:
_df="+=";
break;
case 15:
_df="=+";
break;
case 16:
_df="+/-";
break;
case 17:
_df="-/+";
break;
case 18:
_df="+-";
break;
case 19:
_df="-+";
break;
case 20:
_df="+--";
break;
case 21:
_df="--+";
break;
default:
}
if(_df){
_dd+="<span> "+_df+" </span>";
}
}
return _dd;
};
MovesDisplay.prototype.outputResult=function(_e0){
return "<span class=\"ct-result\">"+_e0+"</span>";
};
MovesDisplay.prototype.outputMove=function(_e1,_e2,_e3,_e4,_e5,_e6,_e7){
var _e8="";
var _e9=this.getMovesDisplay();
if(this.board.tr&&_e2>0&&(_e6>1||_e7>3)&&!_e5){
return _e8;
}
if(_e2>0&&_e6>this.board.ml){
return _e8;
}
if(_e2>0&&_e7>3&&this.board.ml==1){
return _e8;
}
if(_e9){
var _ea=""+Math.round(_e3/2)+". ";
if(_e3%2!=1){
if(_e5||!this.firstNonMove){
_ea=Math.round(_e3/2)+"... ";
}else{
_ea="";
}
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_e2==0&&(!this.firstNonMove||_e3%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_e8+="</div>";
}
_e8+="<br/>";
}
_e8+=_ea+"<span id=\""+this.board.boardName+"-m"+_e1+"\" class=\""+((_e2==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_e4+"</span>";
}
this.firstNonMove=true;
return _e8;
};
Board.prototype.setMoveSeqLalg=function(_eb,_ec,_ed,_ee){
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 _f1=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _f2=new Array();
var _f3=new Array();
if(this.prev_move){
_f1.makeMove(this.prev_move,_f1.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,0.5,false,false);
}
var _f4=_f1.cloneBoard();
var _f5=_eb.replace(/\s+$/g,"").split(" ");
var _f6=null;
var _f7=0;
var _f8="";
var _f9=false;
var _fa=false;
var _fb=0;
var _fc=false;
var _fd=new Array();
var _fe=new Array();
_fe[0]=0;
var _ff=new Array();
var _100=new Array();
var _101=_ed*2-1;
var _102=new Array();
var _103=ChessPiece.WHITE;
var _104=0;
var eval="";
var _106="";
var _107="";
var time="";
var _109=-1;
for(var i=0;i<_f5.length;i++){
var _10a=-1;
if(_f5[i]=="ALT"){
_fa=true;
continue;
}
if(_f5[i].indexOf("EVAL")==0){
eval=_f5[i].split(":")[1];
if(parseInt(eval)>=175&&_fb>0&&_fe[_fb]>1&&_109!=1){
_fa=true;
}
continue;
}
if(_f5[i].indexOf("DEPTH")==0){
_106=_f5[i].split(":")[1];
continue;
}
if(_f5[i].indexOf("NODES")==0){
_107=_f5[i].split(":")[1];
continue;
}
if(_f5[i].indexOf("TIME")==0){
time=_f5[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 _10c=e.split(" ");
_10a=parseInt(_10c[1]);
if(_fe[_fb]==1){
_109=_10a;
}
}
var _10d="";
if(_fa){
_10d="ALT ";
}
var t=parseInt(time);
var nps=" nps:"+Math.round(parseInt(_107)/(parseInt(time)/1000));
if(!this.showNPS){
nps="";
}
if(!(_fb>0&&_fe[_fb]>this.ml)){
_f5[i]=_10d+e+" (depth:"+_106+nps+")";
}else{
_f5[i]="";
}
}
if(_f5[i]=="}"){
_f9=false;
if(this.movesDisplay){
_f8=_f8.replace(/\s+$/g,"");
_102.push(this.movesDisplay.outputComment(_f8,_fb,_fa));
}
continue;
}else{
if(_f9){
_f8+=_f5[i]+" ";
continue;
}else{
if(_f5[i]=="{"){
_f8="";
_f9=true;
continue;
}else{
if(_f5[i]=="("){
if(!_fe[_fb+1]){
_fe[_fb+1]=0;
}
_fe[_fb+1]++;
if(this.movesDisplay){
_102.push(this.movesDisplay.outputVariationStart(_fb,_fe[_fb+1],_101,_fd[0]));
}
_fd[_fb]=_101;
_ff[_fb]=_f6;
_100[_fb]=_103;
_f2[_fb]=_f1;
_f3[_fb]=_f4;
_f1=_f4.cloneBoard();
_fb++;
_101--;
_fc=true;
continue;
}else{
if(_f5[i]==")"){
if(this.movesDisplay){
_102.push(this.movesDisplay.outputVariationEnd(_fb,_fe[_fb],_101,_fd[0]));
}
var _110=new Move();
_110.atEnd=true;
_f6.next=_110;
_110.prev=_f6;
_fb--;
_101=_fd[_fb];
_f6=_ff[_fb];
_103=_100[_fb];
_f1=_f2[_fb];
_f4=_f3[_fb];
_fa=false;
continue;
}else{
if(_f5[i].charAt(0)=="$"){
if(this.movesDisplay){
_102.push(this.movesDisplay.outputNag(parseInt(_f5[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_f5[i]);
var _112=false;
if(_101==1&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_101++;
_112=true;
_103=ChessPiece.BLACK;
}
move.index=_f7;
var _113=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_113=move.pgn;
}else{
_113=_f1.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
}
if(this.movesDisplay){
this.movesDisplay.setToMove(_103);
_102.push(this.movesDisplay.outputMove(_f7,_fb,_101,_113+" ",_fc,_fe[_fb],_fd[0]));
}
_103=(_103==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_101;
_101++;
if(_fb>0){
if(_fc){
var _114=_f6;
if(_114==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_114.numVars==0){
_114.vars=new Array();
}
move.isAlt=_fa;
_114.vars[_114.numVars++]=move;
move.prev=_114.prev;
_fc=false;
}else{
move.prev=_f6;
if(_f6!=null){
_f6.next=move;
}
}
}else{
move.prev=_f6;
if(_f6!=null){
_f6.next=move;
}
}
_fe[_fb+1]=0;
if(_fb==0){
_104=_f7;
}
_ec[_f7++]=move;
_f1.moveArray[_f7-1]=move;
_f6=move;
_f4=_f1.cloneBoard();
_f1.makeMove(move,_f1.boardPieces[move.fromColumn][move.fromRow],false,0.5,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _115=this.movesDisplay.getMovesDisplay();
_102.push(this.movesDisplay.outputResult(_ee));
if(_115){
_115.innerHTML=_102.join("");
}
}
this.lastMoveIndex=_104;
if(_f6!=null){
var _110=new Move();
_110.atEnd=true;
_f6.next=_110;
_110.prev=_f6;
}
if(this.movesDisplay){
for(var i=0;i<_f7;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);
}
}
}
this.lastCount=_f7;
};
Board.prototype.setMoveSequence=function(_117,_118,_119,_11a){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_117,this.tacticMoveArray,_119,_11a);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_118!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_118,this.fullmoveArray,_119,_11a);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.setCurrentMove=function(move,_11c){
if(this.currentMove!=null&&this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.boardName+"-m"+this.currentMove.prev.index,"ct-board-move-current");
}
this.currentMove=move;
if(this.currentMove!=null&&this.currentMove.prev!=null){
var span=YAHOO.util.Dom.get(this.boardName+"-m"+this.currentMove.prev.index);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(cls.indexOf("ct-board-move-variation")==-1){
var _11f=this.movesDisplay.getMovesDisplay();
if(_11f){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_11f);
var _121=new YAHOO.util.Scroll(_11f,{scroll:{by:[0,y]}},0.5,YAHOO.util.Easing.easeOut);
_121.animate();
}
}
}
}
}
if(!_11c){
this.setForwardBack();
}
};
Board.prototype.updateToPlay=function(){
var _122=YAHOO.util.Dom.get("toPlay");
if(_122==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_122.src="/images/whiteknight.vers"+SITE_VERSION+".gif";
_122.alt="White to play";
}else{
_122.src="/images/blackknight.vers"+SITE_VERSION+".gif";
_122.alt="Black to play";
}
};
Board.prototype.getBoardDiv=function(){
if(!this.boardDiv){
this.boardDiv=YAHOO.util.Dom.get("ctb-"+this.boardName);
}
return this.boardDiv;
};
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 _123=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _124=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_123||!_124){
return;
}
_124.innerHTML="";
_123.innerHTML="";
var _125=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_123,"display","none");
YAHOO.util.Dom.setStyle(_124,"display","none");
var _126=0;
YAHOO.util.Dom.setStyle(_125,"width",(this.pieceSize*8+_126)+"px");
YAHOO.util.Dom.setStyle(_125,"height",(this.pieceSize*8+_126)+"px");
return;
}
YAHOO.util.Dom.setStyle(_123,"display","block");
YAHOO.util.Dom.setStyle(_124,"display","block");
var _126=15;
var _127=0;
if(check_bad_msie()){
_127=4;
}
YAHOO.util.Dom.setStyle(_125,"width",(this.pieceSize*8+_126+_127)+"px");
YAHOO.util.Dom.setStyle(_125,"height",(this.pieceSize*8+_126)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _129=document.createElement("div");
YAHOO.util.Dom.setStyle(_129,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_129,"width","15px");
YAHOO.util.Dom.setStyle(_129,"text-align","center");
YAHOO.util.Dom.setStyle(_129,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_129.innerHTML=""+(i+1);
}else{
_129.innerHTML=""+9-(i+1);
}
_124.appendChild(_129);
}
for(var i=0;i<9;i++){
var _12a=document.createElement("span");
YAHOO.util.Dom.setStyle(_12a,"float","left");
YAHOO.util.Dom.setStyle(_12a,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_12a,"width","15px");
YAHOO.util.Dom.setStyle(_12a,"text-align","center");
YAHOO.util.Dom.setStyle(_12a,"clear","both");
}else{
YAHOO.util.Dom.setStyle(_12a,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_12a,"text-align","center");
if(this.isFlipped){
_12a.innerHTML=String.fromCharCode("a".charCodeAt(0)+8-(i));
}else{
_12a.innerHTML=String.fromCharCode("a".charCodeAt(0)+(i-1));
}
}
_123.appendChild(_12a);
}
};
Board.prototype.createBoardUI=function(){
var _12b=this.boardName+"-container";
var _12c=YAHOO.util.Dom.get(_12b);
if(_12c==null){
alert("Could not find board container:"+_12b);
return;
}
YAHOO.util.Dom.addClass(_12c,"ct-board-container");
this.boardDiv=null;
var _12d=document.createElement("div");
_12d.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_12d,"ct-board-border");
var _12e=0;
if(this.showCoordinates){
_12e=15;
}
YAHOO.util.Dom.setStyle(_12d,"width",(this.pieceSize*8+_12e)+"px");
YAHOO.util.Dom.setStyle(_12d,"height",(this.pieceSize*8+_12e)+"px");
YAHOO.util.Dom.setStyle("boardandmoves","width",(350+(this.pieceSize*8+_12e))+"px");
var _12f=document.createElement("div");
YAHOO.util.Dom.setStyle(_12f,"float","left");
_12f.id=this.boardName+"-rankLabels";
_12d.appendChild(_12f);
var _130=document.createElement("div");
YAHOO.util.Dom.addClass(_130,"ct-board");
YAHOO.util.Dom.setStyle(_130,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_130,"height",(this.pieceSize*8)+"px");
_130.id="ctb-"+this.boardName;
var _131="ct-white-square";
for(var i=7;i>=0;i--){
var _12f=document.createElement("div");
for(var j=0;j<8;j++){
var _134=document.createElement("div");
_134.id=this.boardName+"-s"+j+""+i;
this[_134.id]=_134;
YAHOO.util.Dom.addClass(_134,_131);
YAHOO.util.Dom.setStyle(_134,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_134,"height",this.pieceSize+"px");
_12f.appendChild(_134);
_131=(_131=="ct-black-square")?"ct-white-square":"ct-black-square";
}
_131=(_131=="ct-black-square")?"ct-white-square":"ct-black-square";
_130.appendChild(_12f);
}
var _135=document.createElement("div");
_135.id=this.boardName+"-fileLabels";
_12d.appendChild(_130);
_12d.appendChild(_135);
_12c.appendChild(_12d);
this.createBoardCoords();
var _136=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_136){
_136=document.createElement("div");
}else{
_136.innerHTML="";
}
_136.id=this.boardName+"-ct-nav-container";
var _137="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\">";
_137+="<img class=\"ct-start\" id=\""+this.boardName+"-start\" src=\""+this.boardImagePath+"/images/resultset_first.vers"+SITE_VERSION+".gif\" alt=\"Start position\" title=\"Go to starting position\"/>"+"<img class=\"ct-back\" id=\""+this.boardName+"-back\" src=\""+this.boardImagePath+"/images/resultset_previous.vers"+SITE_VERSION+".gif\" alt=\"Previous Move\" title=\"Go back a move\"/>"+"<img class=\"ct-forward\" id=\""+this.boardName+"-forward\" src=\""+this.boardImagePath+"/images/resultset_next.vers"+SITE_VERSION+".gif\" alt=\"Next Move\" title=\"Go forward a move\"/>"+"<img class=\"ct-end\" id=\""+this.boardName+"-end\" src=\""+this.boardImagePath+"/images/resultset_last.vers"+SITE_VERSION+".gif\" alt=\"End position\" title=\"Go to final position\"\"/>"+"<img class=\"ct-play\" id=\""+this.boardName+"-play\" src=\""+this.boardImagePath+"/images/control_play_blue.vers"+SITE_VERSION+".gif\" alt=\"Play moves\" title=\"Play sequence of moves\"/>"+"<img class=\"ct-stop\" id=\""+this.boardName+"-stop\" src=\""+this.boardImagePath+"/images/control_stop_blue.vers"+SITE_VERSION+".gif\" alt=\"Stop playing\" title=\"Stop playing move sequence\"/>";
_137+="</div>";
_136.innerHTML=_137;
_12c.appendChild(_136);
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_12e)+300+250)+"px");
}
};
Board.prototype.getPieceDiv=function(){
var _139=this.getBoardDiv();
var _13a=document.createElement("div");
this.availPieceDivs[this.uptoId]=_13a;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_13a);
YAHOO.util.Dom.setStyle(_13a,"visibility","hidden");
_139.appendChild(_13a);
this.uptoId++;
return _13a;
};
Board.prototype.flipToMove=function(_13b){
return (_13b=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_13c){
var _13d;
switch(_13c){
case "K":
_13d=ChessPiece.KING;
break;
case "Q":
_13d=ChessPiece.QUEEN;
break;
case "R":
_13d=ChessPiece.ROOK;
break;
case "B":
_13d=ChessPiece.BISHOP;
break;
case "N":
_13d=ChessPiece.KNIGHT;
break;
case "P":
_13d=ChessPiece.PAWN;
break;
}
return _13d;
};
Board.prototype.pieceTypeToChar=function(_13e){
switch(_13e){
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(_13f,_140,_141,_142){
if(_13f+2==_141&&_140+1==_142){
return true;
}
if(_13f+2==_141&&_140-1==_142){
return true;
}
if(_13f-2==_141&&_140+1==_142){
return true;
}
if(_13f-2==_141&&_140-1==_142){
return true;
}
if(_13f+1==_141&&_140+2==_142){
return true;
}
if(_13f-1==_141&&_140+2==_142){
return true;
}
if(_13f+1==_141&&_140-2==_142){
return true;
}
if(_13f-1==_141&&_140-2==_142){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_143,_144,_145,_146,_147){
var _148=this.boardPieces[_145][_146];
var _149=this.boardPieces[_143][_144];
if(_147){
var _14a=this.boardPieces[_147.toColumn][_147.toRow];
if(_14a.piece==ChessPiece.PAWN){
if(_14a.colour==ChessPiece.WHITE){
if(_147.fromRow==1&&_147.toRow==3){
if(_145==_147.fromColumn&&_144==3&&_146==2&&(_143==_145+1||_143==_145-1)){
return true;
}
}
}else{
if(_147.fromRow==6&&_147.toRow==4){
if(_145==_147.fromColumn&&_144==4&&_146==5&&(_143==_145+1||_143==_145-1)){
return true;
}
}
}
}
}
if(_148){
if(_149.colour==ChessPiece.WHITE){
if((_143==_145+1||_143==_145-1)&&(_144==_146-1)){
return true;
}
}else{
if((_143==_145+1||_143==_145-1)&&(_144==_146+1)){
return true;
}
}
}else{
if(_143==_145){
if(_149.colour==ChessPiece.WHITE){
if(_144==1){
if(_146==2){
return true;
}else{
if(_146==3&&this.boardPieces[_145][2]==null){
return true;
}
}
}else{
if(_144+1==_146){
return true;
}
}
}else{
if(_144==6){
if(_146==5){
return true;
}else{
if(_146==4&&this.boardPieces[_145][5]==null){
return true;
}
}
}else{
if(_144-1==_146){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_14b,_14c,_14d,_14e,_14f,_150){
var _151=_14b;
var _152=_14c;
var _153=0;
var _154=0;
if(_14d>_14b){
_153=1;
}else{
if(_14d<_14b){
_153=-1;
}
}
if(_14e>_14c){
_154=1;
}else{
if(_14e<_14c){
_154=-1;
}
}
if(_14f==ChessPiece.ROOK&&(_153!=0&&_154!=0)){
return false;
}
if(_14f==ChessPiece.BISHOP&&(_153==0||_154==0)){
return false;
}
var _155=0;
while(true){
_155++;
_14b+=_153;
_14c+=_154;
if(_14f==ChessPiece.KING&&_155>1){
if(_155!=2){
return false;
}
if(_154!=0){
return false;
}
if(!(_14d==6||_14d==2)){
return false;
}
if(_14d==2){
if(this.boardPieces[1][_14c]||this.boardPieces[2][_14c]||this.boardPieces[3][_14c]){
return false;
}
if(!this.canCastleQueenSide[_150.colour]){
return false;
}
}else{
if(_14d==6){
if(this.boardPieces[5][_14c]||this.boardPieces[6][_14c]){
return false;
}
if(!this.canCastleKingSide[_150.colour]){
return false;
}
}else{
return false;
}
}
var _156="";
_156+=String.fromCharCode("a".charCodeAt(0)+_151);
_156+=String.fromCharCode("1".charCodeAt(0)+_152);
_156+=String.fromCharCode("a".charCodeAt(0)+(_151+_153));
_156+=String.fromCharCode("1".charCodeAt(0)+(_152+_154));
var move=this.createMoveFromString(_156);
var _158=this.boardPieces;
var _159=this.toMove;
var _15a=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_151][_152],false,0.5,false,false);
this.restoreCastling(_15a);
kingSafe=this.isKingSafe(_150.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_158;
_158.count--;
this.toMove=_159;
if(!kingSafe){
return false;
}
var _156="";
_156+=String.fromCharCode("a".charCodeAt(0)+_151);
_156+=String.fromCharCode("1".charCodeAt(0)+_152);
_156+=String.fromCharCode("a".charCodeAt(0)+_151);
_156+=String.fromCharCode("1".charCodeAt(0)+_152);
var move=this.createMoveFromString(_156);
var _158=this.boardPieces;
var _159=this.toMove;
var _15a=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_151][_152],false,0.5,false,false);
this.restoreCastling(_15a);
kingSafe=this.isKingSafe(_150.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_158;
_158.count--;
this.toMove=_159;
if(!kingSafe){
return false;
}
}
if(_14b==_14d&&_14c==_14e){
return true;
}
if(_14b<0||_14b>7||_14c<0||_14c>7){
return false;
}
if(this.boardPieces[_14b][_14c]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_15b,_15c,_15d,_15e,_15f){
var _160=_15b.column;
var _161=_15b.row;
if(_15c>7||_15c<0||_15d>7||_15d<0){
return false;
}
var _162=this.boardPieces[_15c][_15d];
var _163=this.boardPieces[_160][_161];
if(_162&&_162.colour==_163.colour){
return false;
}
var _164=false;
if(_15b.piece==ChessPiece.PAWN){
_164=this.canMovePawn(_160,_161,_15c,_15d,_15e);
}else{
if(_15b.piece==ChessPiece.KNIGHT){
_164=this.canMoveKnight(_160,_161,_15c,_15d);
}else{
_164=this.canMoveStraight(_160,_161,_15c,_15d,_15b.piece,_15b);
}
}
var _165=true;
if(_164&&_15f){
var _166="";
_166+=String.fromCharCode("a".charCodeAt(0)+_160);
_166+=String.fromCharCode("1".charCodeAt(0)+_161);
_166+=String.fromCharCode("a".charCodeAt(0)+_15c);
_166+=String.fromCharCode("1".charCodeAt(0)+_15d);
var move=this.createMoveFromString(_166);
var _168=this.boardPieces;
var _169=this.toMove;
var _16a=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_160][_161],false,0.5,false,false);
this.restoreCastling(_16a);
_165=this.isKingSafe(_15b.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_168;
_168.count--;
this.toMove=_169;
}
return _164&&_165;
};
Board.prototype.isKingMated=function(_16b,_16c){
var _16d=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==_16b){
_16d=bp;
break;
}
}
}
var _171=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_16d;
for(var k=0;k<_171.length;k++){
if(this.canMove(bp,bp.column+_171[k][0],bp.row+_171[k][1],_16c,true)){
return false;
}
}
var _173=this.getCandidateMoves(_16b,_16c,true,true);
if(_173.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_174,_175,_176,_177){
var _178=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _17c=[];
if(!bp||bp.colour!=_174){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_177){
continue;
}
_17c=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_17c=[[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++){
_17c.push([1+k,1+k]);
_17c.push([1+k,-1-k]);
_17c.push([-1-k,1+k]);
_17c.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_17c.push([1+k,0]);
_17c.push([1+k,1+k]);
_17c.push([1+k,-1-k]);
_17c.push([-1-k,0]);
_17c.push([-1-k,1+k]);
_17c.push([-1-k,-1-k]);
_17c.push([0,-1-k]);
_17c.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_17c.push([1+k,0]);
_17c.push([-1-k,0]);
_17c.push([0,-1-k]);
_17c.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
_17c=[[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]];
break;
}
for(var k=0;k<_17c.length;k++){
if(this.canMove(bp,bp.column+_17c[k][0],bp.row+_17c[k][1],_175,true)){
_178.push(new Move(bp.column,bp.row,bp.column+_17c[k][0],bp.row+_17c[k][1]));
if(_176){
return _178;
}
}
}
}
}
return _178;
};
Board.prototype.isKingSafe=function(_17e,_17f){
var _180=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==_17e){
_180=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!=_17e){
if(this.canMove(bp,_180.column,_180.row,_17f,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.cloneBoard=function(){
var _184=new Board();
_184.boardPieces=this.copyBoardPieces(true);
_184.moveArray=this.copyMoveArray();
_184.canCastleQueenSide=this.copyCastleQueenSide();
_184.canCastleKingSide=this.copyCastleKingSide();
_184.toMove=this.toMove;
_184.opponentColour=this.opponentColour;
_184.isFlipped=this.isFlipped;
return _184;
};
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(){
var _185=new Array();
if(this.moveArray.length>0){
_185=this.moveArray.slice(0);
}
return _185;
};
Board.prototype.copyBoardPieces=function(_186){
var _187=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_186){
_187[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_187[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_187[i][j]=null;
}
}
}
return _187;
};
Board.prototype.createPiece=function(_18a,_18b,_18c){
if(_18c){
return new LightweightChessPiece(null,_18a,_18b,this);
}else{
return new ChessPiece(this.getPieceDiv(),_18a,_18b,this);
}
};
Board.prototype.restoreCastling=function(_18d){
this.canCastleKingSide=_18d.kingSide;
this.canCastleQueenSide=_18d.queenSide;
};
Board.prototype.saveCastling=function(){
var _18e=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _18f=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_18e,kingSide:_18f};
};
Board.prototype.setupFromFen=function(fen,_191,flip,_193){
this.settingUpPosition=true;
var ua=navigator.userAgent.toLowerCase(),_195=(ua.indexOf("opera")>-1),_196=(ua.indexOf("safari")>-1),_197=(!_195&&!_196&&ua.indexOf("gecko")>-1),isIE=(!_195&&ua.indexOf("msie")>-1);
var _199=fen.split(" ");
var _19a=_199[0].split("/");
var _19b=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _19d=_199[2];
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_19d!="-"){
if(_19d.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_19d.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_19d.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_19d.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_199[1]=="w"){
this.toMove=ChessPiece.WHITE;
this.opponentColour=ChessPiece.WHITE;
this.isFlipped=false;
}else{
this.toMove=ChessPiece.BLACK;
this.opponentColour=ChessPiece.BLACK;
this.isFlipped=true;
}
if(_191){
this.toMove=(ChessPiece.BLACK==this.toMove)?ChessPiece.WHITE:ChessPiece.BLACK;
this.isFlipped=!this.isFlipped;
}
if(flip){
this.isFlipped=true;
}
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=_19a[i];
row--;
_19b=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 _1a4=this.boardPieces[_19b][row];
this.boardPieces[_19b][row]=null;
_19b++;
}
}else{
var _1a5=(c+"").toLowerCase().charAt(0);
var _1a6=ChessPiece.WHITE;
if(_1a5==c){
_1a6=ChessPiece.BLACK;
}
var cp;
switch(_1a5){
case "k":
cp=this.createPiece(_1a6,ChessPiece.KING,_193);
break;
case "q":
cp=this.createPiece(_1a6,ChessPiece.QUEEN,_193);
break;
case "r":
cp=this.createPiece(_1a6,ChessPiece.ROOK,_193);
break;
case "b":
cp=this.createPiece(_1a6,ChessPiece.BISHOP,_193);
break;
case "n":
cp=this.createPiece(_1a6,ChessPiece.KNIGHT,_193);
break;
case "p":
cp=this.createPiece(_1a6,ChessPiece.PAWN,_193);
break;
default:
}
if(_197){
cp.setPosition(_19b,row,false,null,0.5);
cp.setVisible(true);
}
this.boardPieces[_19b][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_19b;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_19b++;
}
}
}
if(!_197){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setPosition(this.pieces[i].column,this.pieces[i].row,false,null,0);
}
}
if(!_193){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
this.createBoardCoords();
this.settingUpPosition=false;
};
Board.prototype.changePieceSet=function(_1a8,_1a9){
if(!this.showedIE6Warning){
alert("Depending on your browser you may need to reload the\n page for piece size changes to properly take effect.");
}
this.showedIE6Warning=true;
if(check_bad_msie()){
if(!this.showedIE6Warning){
alert("Internet Explorer version 6 does not support dynamic piece.\n Please reload page to view new settings.");
}
this.showedIE6Warning=true;
return;
}
var _1aa=this.pieceSize;
this.pieceSet=_1a8;
this.pieceSize=_1a9;
var _1ab=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _1ac=0;
if(this.showCoordinates){
_1ac=15;
}
YAHOO.util.Dom.setStyle(_1ab,"width",(this.pieceSize*8+_1ac)+"px");
YAHOO.util.Dom.setStyle(_1ab,"height",(this.pieceSize*8+_1ac)+"px");
var _1ad=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_1ad,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_1ad,"height",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle("boardandmoves","width",(350+(this.pieceSize*8+_1ac))+"px");
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _1b0=this[this.boardName+"-s"+j+""+i];
YAHOO.util.Dom.setStyle(_1b0,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_1b0,"height",this.pieceSize+"px");
}
}
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);
if(YAHOO.util.Event.isIE){
var _1b2=cp.div;
_1b2.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_1b2.firstChild;
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;
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize);
if(YAHOO.util.Event.isIE){
var _1b2=cp.div;
_1b2.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_1b2.firstChild;
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;
}
}
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_1ac)+300+250)+"px");
}
this.createBoardCoords();
};
Board.prototype.forwardMove=function(e){
if(this.tactics&&this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
if(!this.currentMove.atEnd){
move=this.currentMove;
this.updatePiece(this.boardPieces[move.fromColumn][move.fromRow],move.toColumn,move.toRow,true,true);
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
this.updateToPlay();
}
};
Board.prototype.setupEventHandlers=function(){
this.timesLostFocus=0;
YAHOO.util.Event.addListener(document,"blur",this.lostFocus,this,true);
YAHOO.util.Event.addListener(document,"keydown",function(e){
var _1b9=(e.target)?e.target:e.srcElement;
if(_1b9.form){
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);
};
Board.prototype.lostFocus=function(){
this.timesLostFocus++;
};
Board.prototype.gotoMoveIndex=function(_1ba,_1bb){
var _1bc=this.boardName+"-piecestaken";
var _1bd=YAHOO.util.Dom.get(_1bc);
if(_1bd){
_1bd.innerHTML="";
}
if(_1ba==-1){
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,false);
if(this.prev_move){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],true,1,true,true);
this.updateToPlay();
}
this.setCurrentMove(this.moveArray[0],_1bb);
if(!_1bb){
this.setForwardBack();
}
return;
}
var _1bf=new Array();
var move=this.moveArray[_1ba];
var _1c1=0;
this.setCurrentMove(move.next,_1bb);
if(move.next!=null){
this.setCurrentMove(move.next,_1bb);
}
while(move!=null){
_1bf[_1c1++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],true,1,true,true);
this.updateToPlay();
}
for(var i=_1c1-1;i>=1;i--){
var move=_1bf[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,0.5,true,true);
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
}
if(!_1bb){
this.convertPiecesFromLightWeight(_1ba);
}
var move=_1bf[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],true,0.5,true,true);
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
this.updateToPlay();
if(!_1bb){
this.setForwardBack();
}
};
Board.prototype.gotoStart=function(e){
this.gotoMoveIndex(-1);
};
Board.prototype.gotoEnd=function(e){
if(this.tactics&&this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
this.gotoMoveIndex(this.lastMoveIndex);
};
Board.prototype.playMove=function(self){
if(!self.keepPlayingMoves||!self.currentMove.next){
var play=YAHOO.util.Dom.get(this.boardName+"-play");
play.src=this.boardImagePath+"/images/control_play_blue.vers"+SITE_VERSION+".gif";
self.keepPlayingMoves=false;
return;
}
self.forwardMove();
setTimeout(function(){
self.playMove(self);
},self.pauseBetweenMoves);
};
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.vers"+SITE_VERSION+".gif";
this.playMove(this);
};
Board.prototype.stopPlayingMoves=function(e){
this.keepPlayingMoves=false;
};
Board.prototype.backMove=function(e){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(this.currentMove.prev!=null){
if(this.tactics){
if(this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
}
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
this.updateToPlay();
move=this.currentMove.prev;
this.setCurrentMove(move);
piece=this.boardPieces[move.toColumn][move.toRow];
takenPiece=move.taken;
this.board_xy=null;
piece.setPosition(move.fromColumn,move.fromRow,true,null,0.5);
this.boardPieces[move.fromColumn][move.fromRow]=piece;
if(move.promotion){
piece.changePiece("p");
}
piece.setVisible(true);
if(move!=null&&move.prev!=null&&move.prev.next!=move){
move=move.prev.next;
}
this.setCurrentMove(move);
var _1cb=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_1cb=true;
}
if(takenPiece&&!_1cb){
this.board_xy=null;
var _1cc=move.toColumn;
var _1cd=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_1cd=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_1cc,_1cd,false,null,0.5);
this.boardPieces[_1cc][_1cd]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_1cb){
var _1ce=move.toRow;
var _1cf;
var _1d0;
if(move.fromColumn>move.toColumn){
_1cf=0;
_1d0=3;
}else{
_1cf=7;
_1d0=5;
}
var _1d1=this.boardPieces[_1d0][_1ce];
_1d1.setPosition(_1cf,_1ce,true,null,0.5);
this.boardPieces[_1cf][_1ce]=_1d1;
}
this.setForwardBack();
}
};
Board.prototype.processTaken=function(_1d2,_1d3){
var _1d4=this.boardName+"-piecestaken";
var _1d5=YAHOO.util.Dom.get(_1d4);
if(_1d5){
if(_1d3){
var _1d6=get_image_str(ChessPiece.pieceIconNames[_1d2.colour][_1d2.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize);
_1d5.innerHTML=_1d5.innerHTML+"<img src=\""+_1d6+"\"/>";
}else{
var _1d7=_1d5.innerHTML.split("<");
_1d5.innerHTML="";
for(var i=1;i<_1d7.length-1;i++){
_1d5.innerHTML=_1d5.innerHTML+"<"+_1d7[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();

