=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',e=0;e"+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\tStatic \t\t\tDeep \t\t\tMoves \t\t \t \t\n'+this._buffer+"\t
"},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?"":'Evaluation Move Static Deep '+o+"
"},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
Oyster
- Maximal depth :
- Maximal nodes :
+ Maximal depth :
+ Maximal nodes :
Maximize the nodes
Minimize the liberty
Maximal number of replies :
@@ -224,7 +224,15 @@ Board
Variant
Promote pawns as queen
Active pawns
- White board
+ Pieces :
+
+ Normal
+ White pieces
+ Black pieces
+ Blind
+ Random
+
+
@@ -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;
});