diff --git a/README.md b/README.md index 5fafd6d..fb9a93e 100644 --- a/README.md +++ b/README.md @@ -274,9 +274,15 @@ The option gives the pawn a higher static valuation when it has left its initial The impact is on the valuation, not on the performances. -- **AntiCrux.options.variant.whiteBoard** +- **AntiCrux.options.variant.pieces** -This human-related option renders the board with white pieces only. It may be used to reduce the readability of the game but the players must still follow the basic rules. +This human-related option renders the board differently. It may be used to reduce the readability of the game but the players must still follow the basic rules. The possible modes are : + +- 0 : normal +- 1 : only white pieces +- 2 : only black pieces +- 3 : blind +- 4 : random The export to FEN and PGN is not impacted. @@ -418,7 +424,7 @@ node --expose-gc nodejs_demo_solve.js - November 11th 2016 - Creation of the project - December 25th 2016 - Version 0.1.0 - Initial set of features -- January 29th 2017 - Version 0.2.0 +- February 3rd 2017 - Version 0.2.0 - Library: AntiCrux.prototype.getMoves renamed as AntiCrux.prototype.getMovesHtml - Library: new mandatory parameter for AntiCrux.prototype.highlightMoves - UI: highlighted target cells when requesting a detailed hint @@ -454,6 +460,7 @@ node --expose-gc nodejs_demo_solve.js - Library: improvement of the deep analysis - Library: new parameter for AntiCrux.prototype.isEndGame - Library: the minimal search depth is now 1 (previously 3) + - UI: blind and random modes ### License diff --git a/anticrux.js b/anticrux.js index 783f343..54b691b 100644 --- a/anticrux.js +++ b/anticrux.js @@ -35,6 +35,7 @@ // 1n1qk1n1/r1pp1p1r/1p6/8/8/1P4P1/2PK1P1P/1N3BNR w - - Mate in 10 to be found (Na3) // rnb4r/p1pk3p/5P2/8/1p6/1P3P2/P1PNP1P1/R3KBN1 b - - Mate in 10 to be found (Ke7) // rn2k2r/ppp2p1p/5p2/8/8/N6P/PPPKPP1P/R1B2BNR b - - Mate in 11 to be found (b5) +// 6n1/p7/2B2p2/8/8/4K3/P1P2PPR/RN6 w - - Mate in 12 to be found (Rh6) // rnb4K/pppp1k1p/5p2/2b5/4n3/8/8/8 b - - Mate in 13 to be found // rnb1kb1r/p1pp1ppp/7n/4P3/1p5R/1P6/P1P1PPP1/RNBQKBN1 w - - Mate in 15 to be found (Bh6) // 4k2r/pppn2pp/4p3/8/8/N3PN2/PPP1K1P1/R1B5 w - - Mate to find g4 and Nb5 (Ne5-g4) @@ -1226,7 +1227,7 @@ AntiCrux.prototype.getMovesHtml = function(pPlayer, pNode) { }; AntiCrux.prototype.toHtml = function(pNode) { - var x, y, rotated, color, abc, output; + var x, y, rotated, color, abc, owner, output; //-- Self if (pNode === undefined) @@ -1246,7 +1247,33 @@ AntiCrux.prototype.toHtml = function(pNode) { for (x=(rotated?7:0) ; (!rotated&&(x<8)) || (rotated&&(x>=0)) ; (rotated?x--:x++)) { color = 1 - color; - output += '
'; + switch (this.options.variant.pieces) + { + case 1: + owner = (pNode.owner[8*y+x] != this.constants.owner.none ? this.constants.owner.white : pNode.owner[8*y+x]); + break; + case 2: + owner = (pNode.owner[8*y+x] != this.constants.owner.none ? this.constants.owner.black : pNode.owner[8*y+x]); + break; + case 3: + owner = this.constants.owner.none; + break; + case 4: + if (pNode.owner[8*y+x] == this.constants.owner.none) + owner = this.constants.owner.none; + else + { + if (Math.floor(100*Math.random()) % 2 == 0) + owner = this.constants.owner.black; + else + owner = this.constants.owner.white; + } + break; + default: + owner = pNode.owner[8*y+x]; + break; + } + output += '
'; if (this.options.board.debugCellId) output += y + '/' + x + '
' + (8*y+x); output += '
'; @@ -1348,7 +1375,7 @@ AntiCrux.prototype.toFen = function(pNode) { AntiCrux.prototype.toText = function(pNode) { // Use one of the fonts "Chess" available at www.dafont.com - var x, y, rotated, i, b, car, buffer; + var x, y, rotated, i, b, car, buffer, owner; //-- Self if (pNode === undefined) @@ -1372,8 +1399,36 @@ AntiCrux.prototype.toText = function(pNode) { buffer += '$'; } + //- Owner + switch (this.options.variant.pieces) + { + case 1: + owner = (pNode.owner[i] != this.constants.owner.none ? this.constants.owner.white : pNode.owner[i]); + break; + case 2: + owner = (pNode.owner[i] != this.constants.owner.none ? this.constants.owner.black : pNode.owner[i]); + break; + case 3: + owner = this.constants.owner.none; + break; + case 4: + if (pNode.owner[i] == this.constants.owner.none) + owner = this.constants.owner.none; + else + { + if (Math.floor(100*Math.random()) % 2 == 0) + owner = this.constants.owner.black; + else + owner = this.constants.owner.white; + } + break; + default: + owner = pNode.owner[i]; + break; + } + //- Nature of the position - switch (this.options.variant.whiteBoard && (pNode.owner[i] != this.constants.owner.none) ? this.constants.owner.white : pNode.owner[i]) + switch (owner) { case this.constants.owner.none: car = (b ? '+' : '*'); @@ -1634,7 +1689,7 @@ AntiCrux.prototype._init = function() { variant : { promoteQueen : false, //TRUE only promotes pawns as queen activePawns : false, //TRUE makes the pawns stronger for the valuation once they are moved, and are consequently less mobile - whiteBoard : false //TRUE makes the board fully white + pieces : 0 //Variant for the pieces: 0=normal, 1=white pieces, 2=black pieces, 3=blind, 4=random }, board : { rotated : false, //TRUE rotates the board at 180° diff --git a/anticrux.min.js b/anticrux.min.js index ed7ea2a..6c8c762 100644 --- a/anticrux.min.js +++ b/anticrux.min.js @@ -18,4 +18,4 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -"use strict";var AntiCrux=function(){this._init(),this._root_node={},this.clearBoard()};AntiCrux.prototype.startUI=function(){if("undefined"==typeof module||!module.exports)throw"Error - AntiCrux.prototype.startUI() is restricted to NodeJS";var t=require("opn");t("./node_modules/anticrux/index.html")},AntiCrux.prototype.copyOptions=function(t){return!!t.hasOwnProperty("options")&&(this.options=JSON.parse(JSON.stringify(t.options)),!0)},AntiCrux.prototype.clearBoard=function(){var t;for(this.freeMemory(),this._buffer="",this._highlight=[],this._history=[],this._history_fen0="",this._root_node={piece:[],owner:[],player:this.constants.owner.white},t=0;t<64;t++)this._root_node.piece[t]=this.constants.piece.none,this._root_node.owner[t]=this.constants.owner.none;this.fischer=null},AntiCrux.prototype.getNewFischerId=function(){return Math.floor(960*Math.random())+1},AntiCrux.prototype.defaultBoard=function(t){var e,o,n,i,s;if(void 0===t&&(t=this.constants.board.classicalFischer),t<1||t>960)return!1;for(this.clearBoard(),this.fischer=t,s=[this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none],s[Math.floor(.08*(Math.floor(25*(t-1))%100)+1.5)]=this.constants.piece.bishop,s[Math.floor(.08*(Math.floor(25*Math.floor((t-1)/4))%100)+.5)]=this.constants.piece.bishop,o=Math.floor(Math.floor((t-1)/4)/4)/6,n=Math.floor(6*(o-Math.floor(o))+.5),e=0;e<8;e++)if(s[e]==this.constants.piece.none){if(0===n){s[e]=this.constants.piece.queen;break}n--}for(i=["NNRKR","NRNKR","NRKNR","NRKRN","RNNKR","RNKNR","RNKRN","RKNNR","RKNRN","RKRNN"][Math.floor(o)],e=0;e<8;e++)s[e]==this.constants.piece.none&&(s[e]=this.constants.piece.mapping[i.charAt(0)],i=i.substring(1));for(e=0;e<8;e++)this._root_node.piece[0+e]=s[e],this._root_node.piece[8+e]=this.constants.piece.pawn,this._root_node.piece[48+e]=this.constants.piece.pawn,this._root_node.piece[56+e]=s[e],this._root_node.owner[0+e]=this.constants.owner.black,this._root_node.owner[8+e]=this.constants.owner.black,this._root_node.owner[48+e]=this.constants.owner.white,this._root_node.owner[56+e]=this.constants.owner.white;return this._history_fen0=this.toFen(),!0},AntiCrux.prototype.loadFen=function(t){var e,o,n,i,s;if(0===t.length)return!1;for(this.clearBoard(),e=t.split(" "),o=0,n=0,i=0;i1?this.constants.piece.mapping[i[6].substring(1)]:0,y="abcdefgh".indexOf(i[5].charAt(0)),w=8-parseInt(i[5].charAt(1)),r=this._ai_nodeCopy(n,!1),a=[],o==this.constants.owner.none?(r.player=this.constants.owner.black,this._ai_nodeMoves(r),a=a.concat(r.moves),r.player=this.constants.owner.white,this._ai_nodeMoves(r),r.moves=a.concat(r.moves)):(r.player=o,this._ai_nodeMoves(r)),a=[],h=0;h7||f<0||f>7||y<0||y>7||w<0||w>7||v>this.constants.piece.king)return this.constants.move.none;if(t=1e4*v+1e3*f+100*_+10*w+y,s=n.owner[8*f+_],s==this.constants.owner.none)return this.constants.move.none;if(n.player=s,e){for(r=this._ai_nodeCopy(n,!1),r.player=s,this._ai_nodeMoves(r),u=!1,h=0;h=0&&l<=7&&d>=0&&d<=7&&n.piece[8*d+l]==this.constants.piece.pawn&&n.owner[8*d+l]!=n.owner[8*f+_]&&(n.piece[8*d+l]=this.constants.piece.none,n.owner[8*d+l]=this.constants.owner.none,delete n.enpassant)):n.piece[8*f+_]==this.constants.piece.pawn&&2==Math.abs(w-f)?n.enpassant=4*(w+f)+y:delete n.enpassant,n.piece[8*w+y]=n.piece[8*f+_],n.piece[8*f+_]=this.constants.piece.none,n.owner[8*w+y]=n.owner[8*f+_],n.owner[8*f+_]=this.constants.owner.none,0!==w&&7!==w||n.piece[8*w+y]==this.constants.piece.pawn&&(this.options.variant.promoteQueen&&(v=this.constants.piece.queen),v!=this.constants.piece.none?n.piece[8*w+y]=v:n._pendingPromotion=8*w+y),this._highlight=[],t},AntiCrux.prototype.getMoveAI=function(t,e){var o,n,i,s,r,a,h,c,p,l,d,u,v;if(void 0===e&&(e=this._root_node),void 0===t&&(t=this.getPlayer(e)),t!=this.constants.owner.black&&t!=this.constants.owner.white)return null;if(this._buffer="",this.hasPendingPromotion(e))return null;if(this.options.ai.maxReply<1&&(this.options.ai.maxReply=1),this._ai_nodeFreeMemory(e),this._ai_nodeShrink(e),e.player=t,n=this.options.ai.maxDepth,this._ai_nodeMoves(e),0===e.moves.length)return null;if(s=this.options.ai.noStatOnForcedMove&&1===e.moves.length,this.options.ai.oyster)return this.resetStats(),e.moves[Math.round(Math.random()*(e.moves.length-1))];for(r=[],a=[],i=1;i<=n;i++){if(this._numNodes=0,this.options.ai.maxDepth=i,this._ai_nodeRecurseTree(t,0,e),this._reachedDepth=i,0===this._numNodes)throw"Internal error - Report any error (#001)";for(r.push(i),a.push(this._numNodes),h=0,c=0,o=0;o=(s?1:n)||!this.options.ai.wholeNodes&&0!==this.options.ai.maxNodes&&v>this.options.ai.maxNodes||this.options.ai.wholeNodes&&0!==this.options.ai.maxNodes&&this._numNodes>=this.options.ai.maxNodes)break}return this.options.ai.maxDepth=n,this._ai_gc(),this._ai_nodeSolve(t,0,"",e),this._ai_nodePick(t,e)},AntiCrux.prototype.predictMoves=function(t){var e,o,n,i;if(void 0===t&&(t=this._root_node),this.hasPendingPromotion(t))return"Error : the position is waiting for a promotion.";if(this._ai_nodeFreeMemory(t),e=new AntiCrux,e.options.ai.maxDepth=3,e.options.ai.maxNodes=0,e.options.ai.wholeNodes=!0,e.options.board.symbols=this.options.board.symbols,!e.loadFen(this.toFen(t)))return"Error : the position cannot be loaded.";if(e._ai_nodeMoves(e._root_node),0===e._root_node.moves.length)return"The game is over.";for(i="",n=0;n<5;n++){if(o=e.getMoveAI(),null===o){e.freeMemory();break}if(i.length>0&&(i+=" "),i+=e.moveToString(o),e.freeMemory(),e.movePiece(o,!0)==e.constants.move.none)throw"Internal error - Report any error (#012)";e.switchPlayer()}return"The predicted moves are :\n"+i+"\n\nScore = "+e.getScore().valuationSolverPC+"%"},AntiCrux.prototype.logMove=function(t){return void 0!==t&&0!==t&&("number"==typeof t&&(this._history.push(t),!0))},AntiCrux.prototype.resetStats=function(){this._numNodes=0,this._reachedDepth=0},AntiCrux.prototype.undoMove=function(){var t,e;if(!this._has(this,"_history",!0)||!this._has(this,"_history_fen0",!0))return"";for(e=this._history.slice(0),e.pop(),this.loadFen(this._history_fen0),t=0;t'+n+""}return t==this.constants.piece.pawn?"":this.constants.piece.mapping_rev[t].toUpperCase()},AntiCrux.prototype.moveToString=function(t,e){var o,n,i,s,r,a,h,c,p;return void 0===e&&(e=this._root_node),null===t?"":(o=parseInt(t),n=Math.floor(o/1e4)%10,i=Math.floor(o/1e3)%10,s=Math.floor(o/100)%10,r=Math.floor(o/10)%10,a=o%10,p=this.getPieceSymbol(e.piece[8*i+s],e.owner[8*i+s],this.options.board.symbols),c=e.owner[8*r+a]!=e.owner[8*i+s]&&e.owner[8*r+a]!=this.constants.owner.none,e.hasOwnProperty("enpassant")&&(c=c||e.piece[8*i+s]==this.constants.piece.pawn&&8*r+a==e.enpassant),this._ai_nodeInventory(e.owner[8*i+s],e.piece[8*i+s],void 0,e)>1||c&&e.piece[8*i+s]==this.constants.piece.pawn?(h="abcdefgh".charAt(s),this._ai_nodeInventory(e.owner[8*i+s],e.piece[8*i+s],s,e)>1&&(h+=8-i)):h="",c||e.piece[8*i+s]!=this.constants.piece.pawn||s!=a||(h=""),c||1!=this._ai_nodeInventory(e.owner[8*i+s],e.piece[8*i+s],void 0,e)||(h=""),c&&(h+="x"),p+=h,p+="abcdefgh".charAt(a),p+=8-r,n!=this.constants.piece.none&&(p+="="+this.getPieceSymbol(n,e.owner[8*i+s],this.options.board.symbols)),p)},AntiCrux.prototype.getScore=function(t){var e;return void 0===t&&(t=this._root_node),e=this._ai_nodeValuate(t),null===e?{valuation:t.hasOwnProperty("valuation")?t.valuation:null,valuationSolver:t.hasOwnProperty("valuationSolver")?t.valuationSolver:null}:e},AntiCrux.prototype.switchPlayer=function(t){return void 0===t&&(t=this._root_node),!!t.hasOwnProperty("player")&&(t.player==this.constants.owner.white?t.player=this.constants.owner.black:t.player=this.constants.owner.white,!0)},AntiCrux.prototype.getWinner=function(t){var e=this._ai_nodeCopy(void 0===t?this._root_node:t,!0);return e.player=this.constants.owner.white,this._ai_nodeMoves(e),this._has(e,"moves",!0)?(e.player=this.constants.owner.black,this._ai_nodeMoves(e),this._has(e,"moves",!0)?this.constants.owner.none:this.constants.owner.black):this.constants.owner.white},AntiCrux.prototype.isDraw=function(t){return void 0===t&&(t=this._root_node),!!(this.hasOwnProperty("_reachedDepth")&&t.hasOwnProperty("valuation")&&t.hasOwnProperty("valuationSolver"))&&(this._reachedDepth>=5&&0===t.valuation&&0===t.valuationSolver&&this._ai_nodeInventory(this.constants.owner.black,null,void 0,t)<=5&&this._ai_nodeInventory(this.constants.owner.white,null,void 0,t)<=5)},AntiCrux.prototype.isEndGame=function(t,e){var o=this._ai_nodeCopy(void 0===e?this._root_node:e,!1);return t&&this.switchPlayer(o),this._ai_nodeMoves(o),!this._has(o,"moves",!0)},AntiCrux.prototype.highlight=function(t,e){if(void 0===e&&(e=null),(t||null===e)&&(this._highlight=[]),null===e);else if(Array.isArray(e))this._highlight=this._highlight.concat(e);else if("string"!=typeof e)this._highlight.push(parseInt(e));else if(0===e.length);else if(e.match(/^[a-h][1-8]$/))this._highlight.push(8*(8-parseInt(e.charAt(1)))+"abcdefgh".indexOf(e.charAt(0)));else{if(!e.match(/^[0-7]{2}$/))return!1;this._highlight.push(parseInt(e))}return!0},AntiCrux.prototype.highlightMove=function(t){var e,o,n,i;0===t?this._highlight=[]:(e=Math.floor(t/1e3)%10,o=Math.floor(t/100)%10,n=Math.floor(t/10)%10,i=t%10,this._highlight=[8*e+o,8*n+i])},AntiCrux.prototype.highlightMoves=function(t){var e,o,n;if(this._highlight=[],t?(e=this._ai_nodeCopy(this._root_node,!1),this._ai_nodeMoves(e)):e=this._root_node,1==e.moves.length)this.highlightMove(e.moves[0]);else for(o=0;o"+Math.floor((e+2)/2)+""),o+=''+t.moveToString(this._history[e])+"",t.movePiece(this._history[e],!0,t.constants.owner.none)==t.constants.move.none)throw"Internal error - Report any error (#010)";e%2==1&&(o+="")}return e%2==1&&(o+=""),o+""},AntiCrux.prototype.getDecisionTreeHtml=function(t){return void 0===t&&(t=this._root_node),this._buffer="",this._ai_nodeTreeHtml(0,t),0===this._buffer.length&&(this._buffer='No data'),'\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n'+this._buffer+"\t
StaticDeepMoves
"},AntiCrux.prototype.getMovesHtml=function(t,e){var o,n,i;if(void 0===e&&(e=this._root_node),!this._has(e,"nodes",!0)||!this._has(e,"moves",!0))return"";for(n="",o=0;o"+this.moveToString(e.moves[o],e)+"",i=this._ai_nodeValuate(e.nodes[o]),n+="",n+=i.valuation==this.constants.owner.black*this.constants.score.infinite?'-∞':i.valuation==this.constants.owner.white*this.constants.score.infinite?'+∞':null!==i.valuationPC?i.valuationPC+"%":i.valuation,n+="",n+="",n+=i.valuationSolver==this.constants.owner.black*this.constants.score.infinite?'-∞':i.valuationSolver==this.constants.owner.white*this.constants.score.infinite?'+∞':null!==i.valuationSolverPC?i.valuationSolverPC+"%":i.valuationSolver,e.nodes[o].hasOwnProperty("_opportunity")&&Math.abs(e.nodes[o].valuationSolver)!=this.constants.score.infinite){switch(n+="",e.nodes[o]._opportunity){case"-":n+='';break;case"±":n+='';break;case"+":n+='';break;default:throw"Internal error - Report any error (#016)"}n+=""}else n+="";n+=""}return 0===n.length?"":''+n+"
Evaluation
MoveStaticDeep 
"},AntiCrux.prototype.toHtml=function(t){var e,o,n,i,s,r;for(void 0===t&&(t=this._root_node),n=this.options.board.rotated,r="",i=1,s="abcdefgh",o=n?7:0;!n&&o<8||n&&o>=0;n?o--:o++){for(i=1-i,r+='
',this.options.board.coordinates&&(r+='
'+(8-o)+"
"),e=n?7:0;!n&&e<8||n&&e>=0;n?e--:e++)i=1-i,r+='
',this.options.board.debugCellId&&(r+=o+"/"+e+"
"+(8*o+e)),r+="
";r+="
"}if(this.options.board.coordinates){for(s=s.toUpperCase(),r+='
',r+='
',e=0;e'+s[n?7-e:e]+"
";r+="
"}return'
'+r+"
"},AntiCrux.prototype.toFen=function(t){var e,o,n,i;if(void 0===t&&(t=this._root_node),!this._has(t,"piece",!0)||!this._has(t,"owner",!0))return"";for(o="",n=0,e=0;e<64;e++)t.owner[e]==this.constants.owner.none?n++:(n>0&&(o+=n,n=0),i=this.constants.piece.mapping_rev[t.piece[e]],t.owner[e]==this.constants.owner.black&&(i=i.toLowerCase()),o+=i),(e+1)%8===0&&(n>0&&(o+=n,n=0),e<63&&(o+="/"));return o+=t.player==this.constants.owner.black?" b":" w",o+=" -",o+=t.hasOwnProperty("enpassant")?" "+"abcdefgh"[t.enpassant%8]:" -",o+=" 0",o+=this._has(this,"_history",!0)?" "+Math.ceil(this._history.length/2):" 0"},AntiCrux.prototype.toText=function(t){var e,o,n,i,s,r,a;for(void 0===t&&(t=this._root_node),n=this.options.board.rotated,a="",o=n?7:0;!n&&o<8||n&&o>=0;n?o--:o++)for(e=n?7:0;!n&&e<8||n&&e>=0;n?e--:e++){switch(i=8*o+e,s=(e+o)%2==1,e===(n?7:0)&&(a+=this.options.board.coordinates?"àáâãäåæç"[7-o]:"$"),this.options.variant.whiteBoard&&t.owner[i]!=this.constants.owner.none?this.constants.owner.white:t.owner[i]){case this.constants.owner.none:r=s?"+":"*";break;case this.constants.owner.white:r=" prnbqk"[t.piece[i]];break;case this.constants.owner.black:r=" otmvwl"[t.piece[i]];break;default:throw"Internal error - Report any error (#009)"}s&&(r=r.toUpperCase()),a+=r,e===(n?0:7)&&(a+="%\n")}return'A""""""""S\n'+a+(this.options.board.coordinates?n?"DïîíìëêéèF":"DèéêëìíîïF":"D((((((((F")},AntiCrux.prototype.toPgn=function(){var t,e,o,n,i,s;if(!this._has(this,"_history",!0)||!this._has(this,"_history_fen0",!0))return"";if(t='[Event "Game"]\n',t+='[Site "https://github.com/ecrucru/anticrux/"]\n',t+='[Date "'+(new Date).toISOString().slice(0,10)+'"]\n',t+=this.options.board.rotated?'[White "AntiCrux '+this.options.ai.version+'"]\n[Black "You"]\n':'[White "You"]\n[Black "AntiCrux '+this.options.ai.version+'"]\n',t+='[Result "?"]\n',this.hasSetUp()&&(t+='[SetUp "1"]\n',t+='[FEN "'+this._history_fen0+'"]\n'),t+='[PlyCount "'+this._history.length+'"]\n',t+='[Variant "antichess"]\n',t+='[TimeControl "-"]\n\n',s=this.options.board.symbols,this.options.board.symbols=!1,e=new AntiCrux,e.copyOptions(this),!e.loadFen(this._history_fen0))return"";for(n=0,o=0;o0?" ":"")+ ++n+"."),i=e.moveToString(this._history[o]),e.movePiece(this._history[o],!0,this.constants.owner.none)==e.constants.move.none)throw"Internal error - Report any error (#011)";t+=" "+i,e.switchPlayer()}switch(e.getWinner()){case e.constants.owner.white:t+="# 1-0",t=t.replace('[Result "?"]','[Result "1-0"]');break;case e.constants.owner.black:t+="# 0-1",t=t.replace('[Result "?"]','[Result "0-1"]')}return this.options.board.symbols=s,t},AntiCrux.prototype.toConsole=function(t,e){var o,n,i,s,r,a;for(void 0===e&&(e=this._root_node),i=this.options.board.rotated,a="",n=i?7:0;!i&&n<8||i&&n>=0;i?n--:n++){for(o=i?7:0;!i&&o<8||i&&o>=0;i?o--:o++){switch(s=8*n+o,t&&o===(i?7:0)&&(a+=this.options.board.coordinates?" "+"12345678"[7-n]+" |":"|"),r=this.constants.piece.mapping_rev[e.piece[s]],e.owner[s]){case this.constants.owner.white:r=r.toUpperCase();break;case this.constants.owner.black:r=r.toLowerCase();break;case this.constants.owner.none:r=t||e.piece[s]!=this.constants.owner.none?" ":"."}a+=" "+r+(t?" |":""),o===(i?0:7)&&(a+="\n")}t&&(a+=(this.options.board.coordinates?" ":"")+"+---+---+---+---+---+---+---+---+"),n!=(i?0:7)&&(a+="\n")}return t&&(a=(this.options.board.coordinates?" ":"")+"+---+---+---+---+---+---+---+---+\n"+a),t&&(a+="\n",this.options.board.coordinates&&(a+=(this.options.board.coordinates?" ":"")+(i?" H G F E D C B A ":" A B C D E F G H ")+"\n")),a},AntiCrux.prototype.freeMemory=function(){var t;return this._buffer="",t=this._ai_nodeFreeMemory(this._root_node),this._ai_gc(),t},AntiCrux.prototype._init=function(){this.constants={piece:{none:0,pawn:1,rook:2,knight:3,bishop:4,queen:5,king:6},owner:{black:-1,none:0,white:1},score:{infinite:16777217,neutral:0},board:{classicalFischer:519},move:{none:0}},this.constants.piece.mapping={"":this.constants.piece.none,p:this.constants.piece.pawn,P:this.constants.piece.pawn,r:this.constants.piece.rook,R:this.constants.piece.rook,n:this.constants.piece.knight,N:this.constants.piece.knight,b:this.constants.piece.bishop,B:this.constants.piece.bishop,q:this.constants.piece.queen,Q:this.constants.piece.queen,k:this.constants.piece.king,K:this.constants.piece.king},this.constants.piece.mapping_rev=[],this.constants.piece.mapping_rev[this.constants.piece.none]="",this.constants.piece.mapping_rev[this.constants.piece.pawn]="P",this.constants.piece.mapping_rev[this.constants.piece.rook]="R",this.constants.piece.mapping_rev[this.constants.piece.knight]="N",this.constants.piece.mapping_rev[this.constants.piece.bishop]="B",this.constants.piece.mapping_rev[this.constants.piece.queen]="Q",this.constants.piece.mapping_rev[this.constants.piece.king]="K",this.options={ai:{version:"0.2.0",valuation:[],maxDepth:12,maxNodes:1e5,minimizeLiberty:!0,maxReply:1,noStatOnForcedMove:!1,wholeNodes:!0,randomizedSearch:!0,pessimisticScenario:!0,bestStaticScore:!0,opportunistic:!1,handicap:0,acceleratedEndGame:!0,oyster:!1},variant:{promoteQueen:!1,activePawns:!1,whiteBoard:!1},board:{rotated:!1,symbols:!1,fischer:this.getNewFischerId(),coordinates:!0,noStatOnOwnMove:!0,decisionTree:!1,fullDecisionTree:!1,analysisDepth:5,debugCellId:!1}},this.options.ai.valuation[this.constants.piece.none]=0,this.options.ai.valuation[this.constants.piece.pawn]=100,this.options.ai.valuation[-this.constants.piece.pawn]=180,this.options.ai.valuation[this.constants.piece.rook]=500,this.options.ai.valuation[this.constants.piece.knight]=300,this.options.ai.valuation[this.constants.piece.bishop]=300,this.options.ai.valuation[this.constants.piece.queen]=900,this.options.ai.valuation[this.constants.piece.king]=250},AntiCrux.prototype._has=function(t,e,o){var n=void 0!==t&&null!==t;if(n){if(n=t.hasOwnProperty(e),n&&null===t[e])return!1;void 0===o?n&&(n=t[e]===!0):"string"==typeof o?n&&(n=t[e]==o):n&&o&&(n=t[e].length>0)}return n},AntiCrux.prototype._discoverFischer=function(t){var e,o,n,i;for(void 0===t&&(t=this._root_node),o=null,i=new AntiCrux,n=this.toFen(t).split(" ")[0],e=1;e<=960;e++)if(i.defaultBoard(e),i.toFen().substring(0,n.length)==n){o=e;break}return o},AntiCrux.prototype._ai_nodeCopy=function(t,e){var o={player:t.player,piece:t.piece.slice(0),owner:t.owner.slice(0)};return t.hasOwnProperty("enpassant")&&(o.enpassant=t.enpassant),e&&(t.hasOwnProperty("valuation")&&(o.valuation=t.valuation),t.hasOwnProperty("valuationSolver")&&(o.valuationSolver=t.valuationSolver),t.hasOwnProperty("moves")&&(o.moves=t.moves.slice(0)),t.hasOwnProperty("_pendingPromotion")&&(o._pendingPromotion=t._pendingPromotion)),o},AntiCrux.prototype._ai_nodeShrink=function(t){var e;for(e in t)["owner","piece","player","enpassant","_pendingPromotion"].indexOf(e)===-1&&delete t[e]},AntiCrux.prototype._ai_nodeInventory=function(t,e,o,n){var i,s;for(void 0===n&&(n=this._root_node),s=0,i=0;i<64;i++)if(!(n.owner[i]!=t&&null!==t||n.piece[i]!=e&&null!==e)){if(void 0!==o&&i%8!=o)continue;s++}return s},AntiCrux.prototype._ai_nodeLocatePiece=function(t,e,o){var n,i;for(void 0===o&&(o=this._root_node),i=0;i<8;i++)for(n=0;n<8;n++)if(!(o.owner[8*i+n]!=t&&null!==t||o.piece[8*i+n]!=e&&null!==e))return{x:n,y:i};return null},AntiCrux.prototype._ai_nodeMoves=function(t){var e,o,n,i,s,r,a,h,c,p,l,d,u,v,f=this,_=function(e,i,s,r){var a,h,d,u;return!(i<0||i>7||e<0||e>7)&&(a=t.owner[8*e+i],h=a!=t.player&&a!=f.constants.owner.none,!(a==t.player||h&&!s)&&(h&&!l&&(p=[],l=!0),!h&&(h||l||r)||(u=!1,t.piece[8*n+o]==f.constants.piece.pawn&&(0===e&&t.owner[8*n+o]==f.constants.owner.white||7===e&&t.owner[8*n+o]==f.constants.owner.black)&&(d=c+10*e+i,p.push(d+1e4*f.constants.piece.queen),f.options.variant.promoteQueen||(p.push(d+1e4*f.constants.piece.rook),p.push(d+1e4*f.constants.piece.knight),p.push(d+1e4*f.constants.piece.bishop),p.push(d+1e4*f.constants.piece.king)),u=!0),u||p.push(c+10*e+i)),!h))};if(void 0!==t&&null!==t){for(l=!1,p=[],n=0;n<8;n++)for(o=0;o<8;o++)if(e=8*n+o,t.owner[e]==t.player)switch(c=1e3*n+100*o,t.piece[e]){case this.constants.piece.none:continue;case this.constants.piece.pawn:u=-t.player,_(n+u,o,!1,!1)&&(u==-1&&6==n||1==u&&1==n)&&_(n+2*u,o,!1,!1),_(n+u,o-1,!0,!0),_(n+u,o+1,!0,!0),t.hasOwnProperty("enpassant")&&(s=t.enpassant%8,r=Math.floor(t.enpassant/8),a=s,h=r-u,s>=0&&s<=7&&r>=0&&r<=7&&a>=0&&a<=7&&h>=0&&h<=7&&1==Math.abs(s-o)&&r-n==u&&t.piece[e]==this.constants.piece.pawn&&t.piece[8*r+s]==this.constants.piece.none&&t.piece[8*h+a]==this.constants.piece.pawn&&t.owner[8*r+s]!=t.owner[8*h+a]&&(l||(p=[]),l=!0,p.push(c+10*r+s)));break;case this.constants.piece.queen:case this.constants.piece.rook:for(d=1;d<8&&_(n,o+d,!0,!1);d++);for(d=1;d<8&&_(n,o-d,!0,!1);d++);for(u=1;u<8&&_(n+u,o,!0,!1);u++);for(u=1;u<8&&_(n-u,o,!0,!1);u++);if(t.piece[e]==this.constants.piece.rook)break;case this.constants.piece.bishop:for(v=1;v<8&&_(n+v,o+v,!0,!1);v++);for(v=1;v<8&&_(n+v,o-v,!0,!1);v++);for(v=1;v<8&&_(n-v,o+v,!0,!1);v++);for(v=1;v<8&&_(n-v,o-v,!0,!1);v++);break;case this.constants.piece.king:for(d=-1;d<=1;d++)for(u=-1;u<=1;u++)0===d&&0===u||_(n+u,o+d,!0,!1);break;case this.constants.piece.knight:_(n-2,o-1,!0,!1),_(n-2,o+1,!0,!1),_(n+2,o-1,!0,!1),_(n+2,o+1,!0,!1),_(n-1,o-2,!0,!1),_(n-1,o+2,!0,!1),_(n+1,o-2,!0,!1),_(n+1,o+2,!0,!1);break;default:throw"Internal error - Report any error (#003)"}if(this.options.ai.randomizedSearch)for(o=p.length-1;o>=0;o--)n=Math.round(Math.random()*o),i=p[n],p[n]=p[o],p[o]=i;t.moves=p}},AntiCrux.prototype._ai_nodeCreateNodes=function(t){var e,o;if(t.hasOwnProperty("moves")&&t.hasOwnProperty("player"))for(t.nodes=[],e=0;e0&&o.player==t)for(s=o.moves.length>4?Math.floor((o.moves.length-4)*this.options.ai.handicap/100):0,n=s;n>0;n--)i=Math.floor(Math.random()*o.moves.length),o.moves.splice(i,1),o.hasOwnProperty("nodes")&&o.nodes.splice(i,1);for(o.hasOwnProperty("nodes")||this._ai_nodeCreateNodes(o),s=this.constants.score.infinite,n=0;n=this.options.ai.maxReply&&o.nodes[n].moves.length=0;n--)o.player==t&&o.nodes[n].moves.length>s?(o.moves.splice(n,1),o.nodes.splice(n,1)):(this._numNodes++,o.nodes[n].hasOwnProperty("valuation")||(o.nodes[n].valuation=this._ai_nodeValuate(o.nodes[n]).valuation),e>=this.options.ai.maxDepth||0!==this.options.ai.maxNodes&&this._numNodes>=this.options.ai.maxNodes||this._ai_nodeRecurseTree(t,e+1,o.nodes[n]))}},AntiCrux.prototype._ai_nodeValuate=function(t){var e,o,n;if(void 0===t&&(t=this._root_node),!this._has(t,"piece",!0)||!this._has(t,"owner",!0))return{black:0,white:0,scale:1,valuation:t.hasOwnProperty("valuation")?t.valuation:"-",valuationPC:null,valuationSolver:t.hasOwnProperty("valuationSolver")?t.valuationSolver:"-",valuationSolverPC:null};for(n={black:0,white:0,scale:0,valuation:0,valuationPC:0,valuationSolver:0,valuationSolverPC:0},e=0;e<64;e++)switch(o=this.options.variant.activePawns&&t.piece[e]==this.constants.piece.pawn&&(t.owner[e]==this.constants.owner.black&&1!=Math.floor(e/8)||t.owner[e]==this.constants.owner.white&&6!=Math.floor(e/8))?this.options.ai.valuation[-t.piece[e]]:this.options.ai.valuation[t.piece[e]],t.owner[e]){case this.constants.owner.black:n.black+=o;break;case this.constants.owner.white:n.white+=o;break;case this.constants.owner.none:break;default:throw"Internal error - Report any error (#014)"}return 0===n.black?n.valuation=this.constants.owner.white*this.constants.score.infinite:0===n.white?n.valuation=this.constants.owner.black*this.constants.score.infinite:n.valuation=this.constants.owner.black*n.black+this.constants.owner.white*n.white,t.hasOwnProperty("moves")&&0===t.moves.length&&(n.valuation=t.player*-this.constants.score.infinite),n.scale=n.black>n.white?n.black:n.white,0===n.scale&&(n.valuation=0,n.scale=1),n.valuationPC=Math.round(100*n.valuation/n.scale),n.scale=Math.round(n.scale),n.valuation=Math.round(n.valuation),n.valuationSolver=t.hasOwnProperty("valuationSolver")?t.valuationSolver:n.valuation,Math.abs(n.valuationSolver)>n.scale&&(n.scale=Math.abs(n.valuationSolver)),n.valuationSolverPC=Math.round(2*(100*(n.valuationSolver+n.scale)/(2*n.scale)-50)),n},AntiCrux.prototype._ai_nodeSolve=function(t,e,o,n){var i,s,r,a,h,c,p,l,d;if(void 0===n&&(n=this._root_node),r=this._has(n,"nodes",!0),this.options.board.decisionTree&&r&&e<=this.options.board.analysisDepth)for(i=0;i0&&(n.nodes[i].path+="¦"),n.nodes[i].path+=this.moveToString(n.moves[i],n);if(!r)return n.valuationSolver=n.valuation,n._forced=!0,n.valuationSolver==t*-this.constants.score.infinite?(n._sequence=1,n._opportunity="+"):n.valuationSolver==t*this.constants.score.infinite&&(n._opportunity="-"),void(e>1&&(delete n.owner,delete n.piece));for(a=!0,h=!1,i=0;i=0;i--)this._has(n.nodes[i],"_forced")?(t==this.constants.owner.white&&n.nodes[i].valuationSolverp)&&(p=n.nodes[i].valuationSolver):(n.moves.splice(i,1),n.nodes.splice(i,1));for(i=n.nodes.length-1;i>=0;i--)n.nodes[i].valuationSolver!=p&&(n.moves.splice(i,1),n.nodes.splice(i,1))}if(c=n.player==t||!this.options.ai.pessimisticScenario){for(n.valuationSolver=0,d=0,i=0;i1&&(delete n.owner,delete n.piece)):c=!1}if(!c){for(l=t*-this.constants.score.infinite,i=0;il||t==this.constants.owner.black&&n.nodes[i].valuationSolver1&&(delete n.owner,delete n.piece)}if(this.options.ai.acceleratedEndGame&&this._has(n,"_forced")&&n.valuationSolver==t*-this.constants.score.infinite){for(l=this.constants.score.infinite,i=0;i0&&n.nodes[i]._sequence0&&e.nodes[o]._sequence=0;o--)e.nodes[o]._sequence!=n&&(e.moves.splice(o,1),this._ai_nodeFreeMemory(e.nodes[o]),e.nodes.splice(o,1))}if(l(e),this.options.ai.opportunistic&&e.nodes.length>1){for(i="",o=0;o"- ±+".indexOf(i))&&(i=s);for(o=e.nodes.length-1;o>=0;o--)(e.nodes[o].hasOwnProperty("_opportunity")?e.nodes[o]._opportunity:" ")!=i&&(e.moves.splice(o,1),this._ai_nodeFreeMemory(e.nodes[o]),e.nodes.splice(o,1))}if(l(e),this.options.ai.bestStaticScore&&!a&&r){for(n=t*this.constants.score.infinite,o=0;on)&&(n=e.nodes[o].valuation);for(o=e.nodes.length-1;o>=0;o--)e.nodes[o].valuation!=n&&(e.moves.splice(o,1),this._ai_nodeFreeMemory(e.nodes[o]),e.nodes.splice(o,1))}for(p=[],n=t*this.constants.score.infinite,o=0;on,c=t==this.constants.owner.white&&s==n||t==this.constants.owner.black&&s==n,h&&(p=[],n=s),(c||h)&&p.push(e.moves[o]);switch(p.length){case 0:throw"Internal error - Report any error (#002)";case 1:return p[0];default:return p[Math.round(Math.random()*(p.length-1))]}},AntiCrux.prototype._ai_nodeTreeHtml=function(t,e){var o,n,i,s,r,a;if(void 0===e&&(e=this._root_node),this.options.board.decisionTree&&this._has(e,"nodes",!0))for(o=this,n=function(t){var e;for(e=0;e':t==o.constants.owner.white*o.constants.score.infinite?'+∞':t},s=0;s',this._buffer+=""+i(e.nodes[s].valuation)+"",this._buffer+=""+i(e.nodes[s].valuationSolver)+"",this._buffer+=""+e.nodes[s].path.split("¦").join("")+"",r=t+1;r ";this._buffer+="\n"}e.nodes[s].hasOwnProperty("nodes")&&t+1960)return!1;for(this.clearBoard(),this.fischer=t,i=[this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none,this.constants.piece.none],i[Math.floor(.08*(Math.floor(25*(t-1))%100)+1.5)]=this.constants.piece.bishop,i[Math.floor(.08*(Math.floor(25*Math.floor((t-1)/4))%100)+.5)]=this.constants.piece.bishop,n=Math.floor(Math.floor((t-1)/4)/4)/6,o=Math.floor(6*(n-Math.floor(n))+.5),e=0;e<8;e++)if(i[e]==this.constants.piece.none){if(0===o){i[e]=this.constants.piece.queen;break}o--}for(s=["NNRKR","NRNKR","NRKNR","NRKRN","RNNKR","RNKNR","RNKRN","RKNNR","RKNRN","RKRNN"][Math.floor(n)],e=0;e<8;e++)i[e]==this.constants.piece.none&&(i[e]=this.constants.piece.mapping[s.charAt(0)],s=s.substring(1));for(e=0;e<8;e++)this._root_node.piece[0+e]=i[e],this._root_node.piece[8+e]=this.constants.piece.pawn,this._root_node.piece[48+e]=this.constants.piece.pawn,this._root_node.piece[56+e]=i[e],this._root_node.owner[0+e]=this.constants.owner.black,this._root_node.owner[8+e]=this.constants.owner.black,this._root_node.owner[48+e]=this.constants.owner.white,this._root_node.owner[56+e]=this.constants.owner.white;return this._history_fen0=this.toFen(),!0},AntiCrux.prototype.loadFen=function(t){var e,n,o,s,i;if(0===t.length)return!1;for(this.clearBoard(),e=t.split(" "),n=0,o=0,s=0;s1?this.constants.piece.mapping[s[6].substring(1)]:0,y="abcdefgh".indexOf(s[5].charAt(0)),w=8-parseInt(s[5].charAt(1)),r=this._ai_nodeCopy(o,!1),a=[],n==this.constants.owner.none?(r.player=this.constants.owner.black,this._ai_nodeMoves(r),a=a.concat(r.moves),r.player=this.constants.owner.white,this._ai_nodeMoves(r),r.moves=a.concat(r.moves)):(r.player=n,this._ai_nodeMoves(r)),a=[],h=0;h7||f<0||f>7||y<0||y>7||w<0||w>7||v>this.constants.piece.king)return this.constants.move.none;if(t=1e4*v+1e3*f+100*_+10*w+y,i=o.owner[8*f+_],i==this.constants.owner.none)return this.constants.move.none;if(o.player=i,e){for(r=this._ai_nodeCopy(o,!1),r.player=i,this._ai_nodeMoves(r),u=!1,h=0;h=0&&l<=7&&d>=0&&d<=7&&o.piece[8*d+l]==this.constants.piece.pawn&&o.owner[8*d+l]!=o.owner[8*f+_]&&(o.piece[8*d+l]=this.constants.piece.none,o.owner[8*d+l]=this.constants.owner.none,delete o.enpassant)):o.piece[8*f+_]==this.constants.piece.pawn&&2==Math.abs(w-f)?o.enpassant=4*(w+f)+y:delete o.enpassant,o.piece[8*w+y]=o.piece[8*f+_],o.piece[8*f+_]=this.constants.piece.none,o.owner[8*w+y]=o.owner[8*f+_],o.owner[8*f+_]=this.constants.owner.none,0!==w&&7!==w||o.piece[8*w+y]==this.constants.piece.pawn&&(this.options.variant.promoteQueen&&(v=this.constants.piece.queen),v!=this.constants.piece.none?o.piece[8*w+y]=v:o._pendingPromotion=8*w+y),this._highlight=[],t},AntiCrux.prototype.getMoveAI=function(t,e){var n,o,s,i,r,a,h,c,p,l,d,u,v;if(void 0===e&&(e=this._root_node),void 0===t&&(t=this.getPlayer(e)),t!=this.constants.owner.black&&t!=this.constants.owner.white)return null;if(this._buffer="",this.hasPendingPromotion(e))return null;if(this.options.ai.maxReply<1&&(this.options.ai.maxReply=1),this._ai_nodeFreeMemory(e),this._ai_nodeShrink(e),e.player=t,o=this.options.ai.maxDepth,this._ai_nodeMoves(e),0===e.moves.length)return null;if(i=this.options.ai.noStatOnForcedMove&&1===e.moves.length,this.options.ai.oyster)return this.resetStats(),e.moves[Math.round(Math.random()*(e.moves.length-1))];for(r=[],a=[],s=1;s<=o;s++){if(this._numNodes=0,this.options.ai.maxDepth=s,this._ai_nodeRecurseTree(t,0,e),this._reachedDepth=s,0===this._numNodes)throw"Internal error - Report any error (#001)";for(r.push(s),a.push(this._numNodes),h=0,c=0,n=0;n=(i?1:o)||!this.options.ai.wholeNodes&&0!==this.options.ai.maxNodes&&v>this.options.ai.maxNodes||this.options.ai.wholeNodes&&0!==this.options.ai.maxNodes&&this._numNodes>=this.options.ai.maxNodes)break}return this.options.ai.maxDepth=o,this._ai_gc(),this._ai_nodeSolve(t,0,"",e),this._ai_nodePick(t,e)},AntiCrux.prototype.predictMoves=function(t){var e,n,o,s;if(void 0===t&&(t=this._root_node),this.hasPendingPromotion(t))return"Error : the position is waiting for a promotion.";if(this._ai_nodeFreeMemory(t),e=new AntiCrux,e.options.ai.maxDepth=3,e.options.ai.maxNodes=0,e.options.ai.wholeNodes=!0,e.options.board.symbols=this.options.board.symbols,!e.loadFen(this.toFen(t)))return"Error : the position cannot be loaded.";if(e._ai_nodeMoves(e._root_node),0===e._root_node.moves.length)return"The game is over.";for(s="",o=0;o<5;o++){if(n=e.getMoveAI(),null===n){e.freeMemory();break}if(s.length>0&&(s+=" "),s+=e.moveToString(n),e.freeMemory(),e.movePiece(n,!0)==e.constants.move.none)throw"Internal error - Report any error (#012)";e.switchPlayer()}return"The predicted moves are :\n"+s+"\n\nScore = "+e.getScore().valuationSolverPC+"%"},AntiCrux.prototype.logMove=function(t){return void 0!==t&&0!==t&&("number"==typeof t&&(this._history.push(t),!0))},AntiCrux.prototype.resetStats=function(){this._numNodes=0,this._reachedDepth=0},AntiCrux.prototype.undoMove=function(){var t,e;if(!this._has(this,"_history",!0)||!this._has(this,"_history_fen0",!0))return"";for(e=this._history.slice(0),e.pop(),this.loadFen(this._history_fen0),t=0;t'+o+""}return t==this.constants.piece.pawn?"":this.constants.piece.mapping_rev[t].toUpperCase()},AntiCrux.prototype.moveToString=function(t,e){var n,o,s,i,r,a,h,c,p;return void 0===e&&(e=this._root_node),null===t?"":(n=parseInt(t),o=Math.floor(n/1e4)%10,s=Math.floor(n/1e3)%10,i=Math.floor(n/100)%10,r=Math.floor(n/10)%10,a=n%10,p=this.getPieceSymbol(e.piece[8*s+i],e.owner[8*s+i],this.options.board.symbols),c=e.owner[8*r+a]!=e.owner[8*s+i]&&e.owner[8*r+a]!=this.constants.owner.none,e.hasOwnProperty("enpassant")&&(c=c||e.piece[8*s+i]==this.constants.piece.pawn&&8*r+a==e.enpassant),this._ai_nodeInventory(e.owner[8*s+i],e.piece[8*s+i],void 0,e)>1||c&&e.piece[8*s+i]==this.constants.piece.pawn?(h="abcdefgh".charAt(i),this._ai_nodeInventory(e.owner[8*s+i],e.piece[8*s+i],i,e)>1&&(h+=8-s)):h="",c||e.piece[8*s+i]!=this.constants.piece.pawn||i!=a||(h=""),c||1!=this._ai_nodeInventory(e.owner[8*s+i],e.piece[8*s+i],void 0,e)||(h=""),c&&(h+="x"),p+=h,p+="abcdefgh".charAt(a),p+=8-r,o!=this.constants.piece.none&&(p+="="+this.getPieceSymbol(o,e.owner[8*s+i],this.options.board.symbols)),p)},AntiCrux.prototype.getScore=function(t){var e;return void 0===t&&(t=this._root_node),e=this._ai_nodeValuate(t),null===e?{valuation:t.hasOwnProperty("valuation")?t.valuation:null,valuationSolver:t.hasOwnProperty("valuationSolver")?t.valuationSolver:null}:e},AntiCrux.prototype.switchPlayer=function(t){return void 0===t&&(t=this._root_node),!!t.hasOwnProperty("player")&&(t.player==this.constants.owner.white?t.player=this.constants.owner.black:t.player=this.constants.owner.white,!0)},AntiCrux.prototype.getWinner=function(t){var e=this._ai_nodeCopy(void 0===t?this._root_node:t,!0);return e.player=this.constants.owner.white,this._ai_nodeMoves(e),this._has(e,"moves",!0)?(e.player=this.constants.owner.black,this._ai_nodeMoves(e),this._has(e,"moves",!0)?this.constants.owner.none:this.constants.owner.black):this.constants.owner.white},AntiCrux.prototype.isDraw=function(t){return void 0===t&&(t=this._root_node),!!(this.hasOwnProperty("_reachedDepth")&&t.hasOwnProperty("valuation")&&t.hasOwnProperty("valuationSolver"))&&(this._reachedDepth>=5&&0===t.valuation&&0===t.valuationSolver&&this._ai_nodeInventory(this.constants.owner.black,null,void 0,t)<=5&&this._ai_nodeInventory(this.constants.owner.white,null,void 0,t)<=5)},AntiCrux.prototype.isEndGame=function(t,e){var n=this._ai_nodeCopy(void 0===e?this._root_node:e,!1);return t&&this.switchPlayer(n),this._ai_nodeMoves(n),!this._has(n,"moves",!0)},AntiCrux.prototype.highlight=function(t,e){if(void 0===e&&(e=null),(t||null===e)&&(this._highlight=[]),null===e);else if(Array.isArray(e))this._highlight=this._highlight.concat(e);else if("string"!=typeof e)this._highlight.push(parseInt(e));else if(0===e.length);else if(e.match(/^[a-h][1-8]$/))this._highlight.push(8*(8-parseInt(e.charAt(1)))+"abcdefgh".indexOf(e.charAt(0)));else{if(!e.match(/^[0-7]{2}$/))return!1;this._highlight.push(parseInt(e))}return!0},AntiCrux.prototype.highlightMove=function(t){var e,n,o,s;0===t?this._highlight=[]:(e=Math.floor(t/1e3)%10,n=Math.floor(t/100)%10,o=Math.floor(t/10)%10,s=t%10,this._highlight=[8*e+n,8*o+s])},AntiCrux.prototype.highlightMoves=function(t){var e,n,o;if(this._highlight=[],t?(e=this._ai_nodeCopy(this._root_node,!1),this._ai_nodeMoves(e)):e=this._root_node,1==e.moves.length)this.highlightMove(e.moves[0]);else for(n=0;n"+Math.floor((e+2)/2)+""),n+=''+t.moveToString(this._history[e])+"",t.movePiece(this._history[e],!0,t.constants.owner.none)==t.constants.move.none)throw"Internal error - Report any error (#010)";e%2==1&&(n+="")}return e%2==1&&(n+=""),n+""},AntiCrux.prototype.getDecisionTreeHtml=function(t){return void 0===t&&(t=this._root_node),this._buffer="",this._ai_nodeTreeHtml(0,t),0===this._buffer.length&&(this._buffer='No data'),'\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n'+this._buffer+"\t
StaticDeepMoves
"},AntiCrux.prototype.getMovesHtml=function(t,e){var n,o,s;if(void 0===e&&(e=this._root_node),!this._has(e,"nodes",!0)||!this._has(e,"moves",!0))return"";for(o="",n=0;n"+this.moveToString(e.moves[n],e)+"",s=this._ai_nodeValuate(e.nodes[n]),o+="",o+=s.valuation==this.constants.owner.black*this.constants.score.infinite?'-∞':s.valuation==this.constants.owner.white*this.constants.score.infinite?'+∞':null!==s.valuationPC?s.valuationPC+"%":s.valuation,o+="",o+="",o+=s.valuationSolver==this.constants.owner.black*this.constants.score.infinite?'-∞':s.valuationSolver==this.constants.owner.white*this.constants.score.infinite?'+∞':null!==s.valuationSolverPC?s.valuationSolverPC+"%":s.valuationSolver,e.nodes[n].hasOwnProperty("_opportunity")&&Math.abs(e.nodes[n].valuationSolver)!=this.constants.score.infinite){switch(o+="",e.nodes[n]._opportunity){case"-":o+='';break;case"±":o+='';break;case"+":o+='';break;default:throw"Internal error - Report any error (#016)"}o+=""}else o+="";o+=""}return 0===o.length?"":''+o+"
Evaluation
MoveStaticDeep 
"},AntiCrux.prototype.toHtml=function(t){var e,n,o,s,i,r,a;for(void 0===t&&(t=this._root_node),o=this.options.board.rotated,a="",s=1,i="abcdefgh",n=o?7:0;!o&&n<8||o&&n>=0;o?n--:n++){for(s=1-s,a+='
',this.options.board.coordinates&&(a+='
'+(8-n)+"
"),e=o?7:0;!o&&e<8||o&&e>=0;o?e--:e++){switch(s=1-s,this.options.variant.pieces){case 1:r=t.owner[8*n+e]!=this.constants.owner.none?this.constants.owner.white:t.owner[8*n+e];break;case 2:r=t.owner[8*n+e]!=this.constants.owner.none?this.constants.owner.black:t.owner[8*n+e];break;case 3:r=this.constants.owner.none;break;case 4:r=t.owner[8*n+e]==this.constants.owner.none?this.constants.owner.none:Math.floor(100*Math.random())%2==0?this.constants.owner.black:this.constants.owner.white;break;default:r=t.owner[8*n+e]}a+='
',this.options.board.debugCellId&&(a+=n+"/"+e+"
"+(8*n+e)),a+="
"}a+="
"}if(this.options.board.coordinates){for(i=i.toUpperCase(),a+='
',a+='
',e=0;e'+i[o?7-e:e]+"
";a+=""}return'
'+a+"
"},AntiCrux.prototype.toFen=function(t){var e,n,o,s;if(void 0===t&&(t=this._root_node),!this._has(t,"piece",!0)||!this._has(t,"owner",!0))return"";for(n="",o=0,e=0;e<64;e++)t.owner[e]==this.constants.owner.none?o++:(o>0&&(n+=o,o=0),s=this.constants.piece.mapping_rev[t.piece[e]],t.owner[e]==this.constants.owner.black&&(s=s.toLowerCase()),n+=s),(e+1)%8===0&&(o>0&&(n+=o,o=0),e<63&&(n+="/"));return n+=t.player==this.constants.owner.black?" b":" w",n+=" -",n+=t.hasOwnProperty("enpassant")?" "+"abcdefgh"[t.enpassant%8]:" -",n+=" 0",n+=this._has(this,"_history",!0)?" "+Math.ceil(this._history.length/2):" 0"},AntiCrux.prototype.toText=function(t){var e,n,o,s,i,r,a,h;for(void 0===t&&(t=this._root_node),o=this.options.board.rotated,a="",n=o?7:0;!o&&n<8||o&&n>=0;o?n--:n++)for(e=o?7:0;!o&&e<8||o&&e>=0;o?e--:e++){switch(s=8*n+e,i=(e+n)%2==1,e===(o?7:0)&&(a+=this.options.board.coordinates?"àáâãäåæç"[7-n]:"$"),this.options.variant.pieces){case 1:h=t.owner[s]!=this.constants.owner.none?this.constants.owner.white:t.owner[s];break;case 2:h=t.owner[s]!=this.constants.owner.none?this.constants.owner.black:t.owner[s];break;case 3:h=this.constants.owner.none;break;case 4:h=t.owner[s]==this.constants.owner.none?this.constants.owner.none:Math.floor(100*Math.random())%2==0?this.constants.owner.black:this.constants.owner.white;break;default:h=t.owner[s]}switch(h){case this.constants.owner.none:r=i?"+":"*";break;case this.constants.owner.white:r=" prnbqk"[t.piece[s]];break;case this.constants.owner.black:r=" otmvwl"[t.piece[s]];break;default:throw"Internal error - Report any error (#009)"}i&&(r=r.toUpperCase()),a+=r,e===(o?0:7)&&(a+="%\n")}return'A""""""""S\n'+a+(this.options.board.coordinates?o?"DïîíìëêéèF":"DèéêëìíîïF":"D((((((((F")},AntiCrux.prototype.toPgn=function(){var t,e,n,o,s,i;if(!this._has(this,"_history",!0)||!this._has(this,"_history_fen0",!0))return"";if(t='[Event "Game"]\n',t+='[Site "https://github.com/ecrucru/anticrux/"]\n',t+='[Date "'+(new Date).toISOString().slice(0,10)+'"]\n',t+=this.options.board.rotated?'[White "AntiCrux '+this.options.ai.version+'"]\n[Black "You"]\n':'[White "You"]\n[Black "AntiCrux '+this.options.ai.version+'"]\n',t+='[Result "?"]\n',this.hasSetUp()&&(t+='[SetUp "1"]\n',t+='[FEN "'+this._history_fen0+'"]\n'),t+='[PlyCount "'+this._history.length+'"]\n',t+='[Variant "antichess"]\n',t+='[TimeControl "-"]\n\n',i=this.options.board.symbols,this.options.board.symbols=!1,e=new AntiCrux,e.copyOptions(this),!e.loadFen(this._history_fen0))return"";for(o=0,n=0;n0?" ":"")+ ++o+"."),s=e.moveToString(this._history[n]),e.movePiece(this._history[n],!0,this.constants.owner.none)==e.constants.move.none)throw"Internal error - Report any error (#011)";t+=" "+s,e.switchPlayer()}switch(e.getWinner()){case e.constants.owner.white:t+="# 1-0",t=t.replace('[Result "?"]','[Result "1-0"]');break;case e.constants.owner.black:t+="# 0-1",t=t.replace('[Result "?"]','[Result "0-1"]')}return this.options.board.symbols=i,t},AntiCrux.prototype.toConsole=function(t,e){var n,o,s,i,r,a;for(void 0===e&&(e=this._root_node),s=this.options.board.rotated,a="",o=s?7:0;!s&&o<8||s&&o>=0;s?o--:o++){for(n=s?7:0;!s&&n<8||s&&n>=0;s?n--:n++){switch(i=8*o+n,t&&n===(s?7:0)&&(a+=this.options.board.coordinates?" "+"12345678"[7-o]+" |":"|"),r=this.constants.piece.mapping_rev[e.piece[i]],e.owner[i]){case this.constants.owner.white:r=r.toUpperCase();break;case this.constants.owner.black:r=r.toLowerCase();break;case this.constants.owner.none:r=t||e.piece[i]!=this.constants.owner.none?" ":"."}a+=" "+r+(t?" |":""),n===(s?0:7)&&(a+="\n")}t&&(a+=(this.options.board.coordinates?" ":"")+"+---+---+---+---+---+---+---+---+"),o!=(s?0:7)&&(a+="\n")}return t&&(a=(this.options.board.coordinates?" ":"")+"+---+---+---+---+---+---+---+---+\n"+a),t&&(a+="\n",this.options.board.coordinates&&(a+=(this.options.board.coordinates?" ":"")+(s?" H G F E D C B A ":" A B C D E F G H ")+"\n")),a},AntiCrux.prototype.freeMemory=function(){var t;return this._buffer="",t=this._ai_nodeFreeMemory(this._root_node),this._ai_gc(),t},AntiCrux.prototype._init=function(){this.constants={piece:{none:0,pawn:1,rook:2,knight:3,bishop:4,queen:5,king:6},owner:{black:-1,none:0,white:1},score:{infinite:16777217,neutral:0},board:{classicalFischer:519},move:{none:0}},this.constants.piece.mapping={"":this.constants.piece.none,p:this.constants.piece.pawn,P:this.constants.piece.pawn,r:this.constants.piece.rook,R:this.constants.piece.rook,n:this.constants.piece.knight,N:this.constants.piece.knight,b:this.constants.piece.bishop,B:this.constants.piece.bishop,q:this.constants.piece.queen,Q:this.constants.piece.queen,k:this.constants.piece.king,K:this.constants.piece.king},this.constants.piece.mapping_rev=[],this.constants.piece.mapping_rev[this.constants.piece.none]="",this.constants.piece.mapping_rev[this.constants.piece.pawn]="P",this.constants.piece.mapping_rev[this.constants.piece.rook]="R",this.constants.piece.mapping_rev[this.constants.piece.knight]="N",this.constants.piece.mapping_rev[this.constants.piece.bishop]="B",this.constants.piece.mapping_rev[this.constants.piece.queen]="Q",this.constants.piece.mapping_rev[this.constants.piece.king]="K",this.options={ai:{version:"0.2.0",valuation:[],maxDepth:12,maxNodes:1e5,minimizeLiberty:!0,maxReply:1,noStatOnForcedMove:!1,wholeNodes:!0,randomizedSearch:!0,pessimisticScenario:!0,bestStaticScore:!0,opportunistic:!1,handicap:0,acceleratedEndGame:!0,oyster:!1},variant:{promoteQueen:!1,activePawns:!1,pieces:0},board:{rotated:!1,symbols:!1,fischer:this.getNewFischerId(),coordinates:!0,noStatOnOwnMove:!0,decisionTree:!1,fullDecisionTree:!1,analysisDepth:5,debugCellId:!1}},this.options.ai.valuation[this.constants.piece.none]=0,this.options.ai.valuation[this.constants.piece.pawn]=100,this.options.ai.valuation[-this.constants.piece.pawn]=180,this.options.ai.valuation[this.constants.piece.rook]=500,this.options.ai.valuation[this.constants.piece.knight]=300,this.options.ai.valuation[this.constants.piece.bishop]=300,this.options.ai.valuation[this.constants.piece.queen]=900,this.options.ai.valuation[this.constants.piece.king]=250},AntiCrux.prototype._has=function(t,e,n){var o=void 0!==t&&null!==t;if(o){if(o=t.hasOwnProperty(e),o&&null===t[e])return!1;void 0===n?o&&(o=t[e]===!0):"string"==typeof n?o&&(o=t[e]==n):o&&n&&(o=t[e].length>0)}return o},AntiCrux.prototype._discoverFischer=function(t){var e,n,o,s;for(void 0===t&&(t=this._root_node),n=null,s=new AntiCrux,o=this.toFen(t).split(" ")[0],e=1;e<=960;e++)if(s.defaultBoard(e),s.toFen().substring(0,o.length)==o){n=e;break}return n},AntiCrux.prototype._ai_nodeCopy=function(t,e){var n={player:t.player,piece:t.piece.slice(0),owner:t.owner.slice(0)};return t.hasOwnProperty("enpassant")&&(n.enpassant=t.enpassant),e&&(t.hasOwnProperty("valuation")&&(n.valuation=t.valuation),t.hasOwnProperty("valuationSolver")&&(n.valuationSolver=t.valuationSolver),t.hasOwnProperty("moves")&&(n.moves=t.moves.slice(0)),t.hasOwnProperty("_pendingPromotion")&&(n._pendingPromotion=t._pendingPromotion)),n},AntiCrux.prototype._ai_nodeShrink=function(t){var e;for(e in t)["owner","piece","player","enpassant","_pendingPromotion"].indexOf(e)===-1&&delete t[e]},AntiCrux.prototype._ai_nodeInventory=function(t,e,n,o){var s,i;for(void 0===o&&(o=this._root_node),i=0,s=0;s<64;s++)if(!(o.owner[s]!=t&&null!==t||o.piece[s]!=e&&null!==e)){if(void 0!==n&&s%8!=n)continue;i++}return i},AntiCrux.prototype._ai_nodeLocatePiece=function(t,e,n){var o,s;for(void 0===n&&(n=this._root_node),s=0;s<8;s++)for(o=0;o<8;o++)if(!(n.owner[8*s+o]!=t&&null!==t||n.piece[8*s+o]!=e&&null!==e))return{x:o,y:s};return null},AntiCrux.prototype._ai_nodeMoves=function(t){var e,n,o,s,i,r,a,h,c,p,l,d,u,v,f=this,_=function(e,s,i,r){var a,h,d,u;return!(s<0||s>7||e<0||e>7)&&(a=t.owner[8*e+s],h=a!=t.player&&a!=f.constants.owner.none,!(a==t.player||h&&!i)&&(h&&!l&&(p=[],l=!0),!h&&(h||l||r)||(u=!1,t.piece[8*o+n]==f.constants.piece.pawn&&(0===e&&t.owner[8*o+n]==f.constants.owner.white||7===e&&t.owner[8*o+n]==f.constants.owner.black)&&(d=c+10*e+s,p.push(d+1e4*f.constants.piece.queen),f.options.variant.promoteQueen||(p.push(d+1e4*f.constants.piece.rook),p.push(d+1e4*f.constants.piece.knight),p.push(d+1e4*f.constants.piece.bishop),p.push(d+1e4*f.constants.piece.king)),u=!0),u||p.push(c+10*e+s)),!h))};if(void 0!==t&&null!==t){for(l=!1,p=[],o=0;o<8;o++)for(n=0;n<8;n++)if(e=8*o+n,t.owner[e]==t.player)switch(c=1e3*o+100*n,t.piece[e]){case this.constants.piece.none:continue;case this.constants.piece.pawn:u=-t.player,_(o+u,n,!1,!1)&&(u==-1&&6==o||1==u&&1==o)&&_(o+2*u,n,!1,!1),_(o+u,n-1,!0,!0),_(o+u,n+1,!0,!0),t.hasOwnProperty("enpassant")&&(i=t.enpassant%8,r=Math.floor(t.enpassant/8),a=i,h=r-u,i>=0&&i<=7&&r>=0&&r<=7&&a>=0&&a<=7&&h>=0&&h<=7&&1==Math.abs(i-n)&&r-o==u&&t.piece[e]==this.constants.piece.pawn&&t.piece[8*r+i]==this.constants.piece.none&&t.piece[8*h+a]==this.constants.piece.pawn&&t.owner[8*r+i]!=t.owner[8*h+a]&&(l||(p=[]),l=!0,p.push(c+10*r+i)));break;case this.constants.piece.queen:case this.constants.piece.rook:for(d=1;d<8&&_(o,n+d,!0,!1);d++);for(d=1;d<8&&_(o,n-d,!0,!1);d++);for(u=1;u<8&&_(o+u,n,!0,!1);u++);for(u=1;u<8&&_(o-u,n,!0,!1);u++);if(t.piece[e]==this.constants.piece.rook)break;case this.constants.piece.bishop:for(v=1;v<8&&_(o+v,n+v,!0,!1);v++);for(v=1;v<8&&_(o+v,n-v,!0,!1);v++);for(v=1;v<8&&_(o-v,n+v,!0,!1);v++);for(v=1;v<8&&_(o-v,n-v,!0,!1);v++);break;case this.constants.piece.king:for(d=-1;d<=1;d++)for(u=-1;u<=1;u++)0===d&&0===u||_(o+u,n+d,!0,!1);break;case this.constants.piece.knight:_(o-2,n-1,!0,!1),_(o-2,n+1,!0,!1),_(o+2,n-1,!0,!1),_(o+2,n+1,!0,!1),_(o-1,n-2,!0,!1),_(o-1,n+2,!0,!1),_(o+1,n-2,!0,!1),_(o+1,n+2,!0,!1);break;default:throw"Internal error - Report any error (#003)"}if(this.options.ai.randomizedSearch)for(n=p.length-1;n>=0;n--)o=Math.round(Math.random()*n),s=p[o],p[o]=p[n],p[n]=s;t.moves=p}},AntiCrux.prototype._ai_nodeCreateNodes=function(t){var e,n;if(t.hasOwnProperty("moves")&&t.hasOwnProperty("player"))for(t.nodes=[],e=0;e0&&n.player==t)for(i=n.moves.length>4?Math.floor((n.moves.length-4)*this.options.ai.handicap/100):0,o=i;o>0;o--)s=Math.floor(Math.random()*n.moves.length),n.moves.splice(s,1),n.hasOwnProperty("nodes")&&n.nodes.splice(s,1);for(n.hasOwnProperty("nodes")||this._ai_nodeCreateNodes(n),i=this.constants.score.infinite,o=0;o=this.options.ai.maxReply&&n.nodes[o].moves.length=0;o--)n.player==t&&n.nodes[o].moves.length>i?(n.moves.splice(o,1),n.nodes.splice(o,1)):(this._numNodes++,n.nodes[o].hasOwnProperty("valuation")||(n.nodes[o].valuation=this._ai_nodeValuate(n.nodes[o]).valuation),e>=this.options.ai.maxDepth||0!==this.options.ai.maxNodes&&this._numNodes>=this.options.ai.maxNodes||this._ai_nodeRecurseTree(t,e+1,n.nodes[o]));}},AntiCrux.prototype._ai_nodeValuate=function(t){var e,n,o;if(void 0===t&&(t=this._root_node),!this._has(t,"piece",!0)||!this._has(t,"owner",!0))return{black:0,white:0,scale:1,valuation:t.hasOwnProperty("valuation")?t.valuation:"-",valuationPC:null,valuationSolver:t.hasOwnProperty("valuationSolver")?t.valuationSolver:"-",valuationSolverPC:null};for(o={black:0,white:0,scale:0,valuation:0,valuationPC:0,valuationSolver:0,valuationSolverPC:0},e=0;e<64;e++)switch(n=this.options.variant.activePawns&&t.piece[e]==this.constants.piece.pawn&&(t.owner[e]==this.constants.owner.black&&1!=Math.floor(e/8)||t.owner[e]==this.constants.owner.white&&6!=Math.floor(e/8))?this.options.ai.valuation[-t.piece[e]]:this.options.ai.valuation[t.piece[e]],t.owner[e]){case this.constants.owner.black:o.black+=n;break;case this.constants.owner.white:o.white+=n;break;case this.constants.owner.none:break;default:throw"Internal error - Report any error (#014)"}return 0===o.black?o.valuation=this.constants.owner.white*this.constants.score.infinite:0===o.white?o.valuation=this.constants.owner.black*this.constants.score.infinite:o.valuation=this.constants.owner.black*o.black+this.constants.owner.white*o.white,t.hasOwnProperty("moves")&&0===t.moves.length&&(o.valuation=t.player*-this.constants.score.infinite),o.scale=o.black>o.white?o.black:o.white,0===o.scale&&(o.valuation=0,o.scale=1),o.valuationPC=Math.round(100*o.valuation/o.scale),o.scale=Math.round(o.scale),o.valuation=Math.round(o.valuation),o.valuationSolver=t.hasOwnProperty("valuationSolver")?t.valuationSolver:o.valuation,Math.abs(o.valuationSolver)>o.scale&&(o.scale=Math.abs(o.valuationSolver)),o.valuationSolverPC=Math.round(2*(100*(o.valuationSolver+o.scale)/(2*o.scale)-50)),o},AntiCrux.prototype._ai_nodeSolve=function(t,e,n,o){var s,i,r,a,h,c,p,l,d;if(void 0===o&&(o=this._root_node),r=this._has(o,"nodes",!0),this.options.board.decisionTree&&r&&e<=this.options.board.analysisDepth)for(s=0;s0&&(o.nodes[s].path+="¦"),o.nodes[s].path+=this.moveToString(o.moves[s],o);if(!r)return o.valuationSolver=o.valuation,o._forced=!0,o.valuationSolver==t*-this.constants.score.infinite?(o._sequence=1,o._opportunity="+"):o.valuationSolver==t*this.constants.score.infinite&&(o._opportunity="-"),void(e>1&&(delete o.owner,delete o.piece));for(a=!0,h=!1,s=0;s=0;s--)this._has(o.nodes[s],"_forced")?(t==this.constants.owner.white&&o.nodes[s].valuationSolverp)&&(p=o.nodes[s].valuationSolver):(o.moves.splice(s,1),o.nodes.splice(s,1));for(s=o.nodes.length-1;s>=0;s--)o.nodes[s].valuationSolver!=p&&(o.moves.splice(s,1),o.nodes.splice(s,1))}if(c=o.player==t||!this.options.ai.pessimisticScenario){for(o.valuationSolver=0,d=0,s=0;s1&&(delete o.owner,delete o.piece)):c=!1}if(!c){for(l=t*-this.constants.score.infinite,s=0;sl||t==this.constants.owner.black&&o.nodes[s].valuationSolver1&&(delete o.owner,delete o.piece)}if(this.options.ai.acceleratedEndGame&&this._has(o,"_forced")&&o.valuationSolver==t*-this.constants.score.infinite){for(l=this.constants.score.infinite,s=0;s0&&o.nodes[s]._sequence0&&e.nodes[n]._sequence=0;n--)e.nodes[n]._sequence!=o&&(e.moves.splice(n,1),this._ai_nodeFreeMemory(e.nodes[n]),e.nodes.splice(n,1))}if(l(e),this.options.ai.opportunistic&&e.nodes.length>1){for(s="",n=0;n"- ±+".indexOf(s))&&(s=i);for(n=e.nodes.length-1;n>=0;n--)(e.nodes[n].hasOwnProperty("_opportunity")?e.nodes[n]._opportunity:" ")!=s&&(e.moves.splice(n,1),this._ai_nodeFreeMemory(e.nodes[n]),e.nodes.splice(n,1))}if(l(e),this.options.ai.bestStaticScore&&!a&&r){for(o=t*this.constants.score.infinite,n=0;no)&&(o=e.nodes[n].valuation);for(n=e.nodes.length-1;n>=0;n--)e.nodes[n].valuation!=o&&(e.moves.splice(n,1),this._ai_nodeFreeMemory(e.nodes[n]),e.nodes.splice(n,1))}for(p=[],o=t*this.constants.score.infinite,n=0;no,c=t==this.constants.owner.white&&i==o||t==this.constants.owner.black&&i==o,h&&(p=[],o=i),(c||h)&&p.push(e.moves[n]);switch(p.length){case 0:throw"Internal error - Report any error (#002)";case 1:return p[0];default:return p[Math.round(Math.random()*(p.length-1))]}},AntiCrux.prototype._ai_nodeTreeHtml=function(t,e){var n,o,s,i,r,a;if(void 0===e&&(e=this._root_node),this.options.board.decisionTree&&this._has(e,"nodes",!0))for(n=this,o=function(t){var e;for(e=0;e':t==n.constants.owner.white*n.constants.score.infinite?'+∞':t},i=0;i',this._buffer+=""+s(e.nodes[i].valuation)+"",this._buffer+=""+s(e.nodes[i].valuationSolver)+"",this._buffer+=""+e.nodes[i].path.split("¦").join("")+"",r=t+1;r ";this._buffer+="\n"}e.nodes[i].hasOwnProperty("nodes")&&t+1Artificial intelligence

-

-

+

+

@@ -224,7 +224,15 @@

Board

Variant

-

+

+ +

@@ -317,7 +325,7 @@

Information

//-- Variant $('#acui_option_promotequeen').prop('checked', ai.options.variant.promoteQueen); $('#acui_option_activepawns').prop('checked', ai.options.variant.activePawns); - $('#acui_option_whiteboard').prop('checked', ai.options.variant.whiteBoard); + $('#acui_option_pieces').val(ai.options.variant.pieces).change(); } function acui_reset_ui(pResetPlayer) { @@ -447,6 +455,9 @@

Information

//-- Determines the position for the provided index rewind = new AntiCrux(); + rewind.copyOptions(ai); + if (rewind.options.variant.pieces == 3) + rewind.options.variant.pieces = 0; if (!rewind.loadFen(ai.getInitialPosition())) return false; for (i=0 ; i<=index ; i++) @@ -925,7 +936,7 @@

Information

//-- Variant ai.options.variant.promoteQueen = $('#acui_option_promotequeen').prop('checked'); ai.options.variant.activePawns = $('#acui_option_activepawns').prop('checked'); - ai.options.variant.whiteBoard = $('#acui_option_whiteboard').prop('checked'); + ai.options.variant.pieces = parseInt($('#acui_option_pieces').val()); return true; });