/
app.bundle.js
1 lines (1 loc) · 25.5 KB
/
app.bundle.js
1
!function(e){function t(r){if(i[r])return i[r].exports;var o=i[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var i={};t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,i,r){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=21)}([function(e,t,i){"use strict";var r=i(13),o=i(14),n=i(15),s=i(16),a=i(17);e.exports=Object.assign({},r,o,n,s,a)},function(e,t,i){"use strict";function r(e,t){return new N(e,t)}function o(){return r(0,0)}function n(){return r(4294967295,4294967295)}function s(){return r(1437226410,1437226410)}function a(){return r(2857740885,2857740885)}function u(e){return r(16843009,16843009).SHL(e)}function c(){for(var e=[],t=0;t<8;++t)e.push(u(t));return e}function p(e){return r(255,0).SHL(8*e)}function l(){for(var e=[],t=0;t<8;++t)e.push(p(t));return e}function h(e){return o().setBit(e)}function f(e){return r(270549120,16909320).AND(n().SHIFT(8*e)).SHIFT(e)}function v(){for(var e=[],t=-7;t<8;++t)e.push(f(t));return e}function B(e){return r(134480385,2151686160).AND(n().SHIFT(8*-e)).SHIFT(e)}function y(){for(var e=[],t=-7;t<8;++t)e.push(B(t));return e}var N=i(3);e.exports={makeBB:r,zeroBB:o,oneBB:n,lightBB:s,darkBB:a,fileBB:u,fileBBs:c,rankBB:p,rankBBs:l,idxBB:h,diagBB:f,diagBBs:v,antiDiagBB:B,antiDiagBBs:y}},function(e,t,i){"use strict";function r(e,t){return h.PIECE_CHARS.charAt(2*e+t)}function o(e){return 1^e}function n(e){return e>>>3}function s(e){return 7&e}function a(e,t){return t+e*h.NUM_FILES}function u(e,t){return!!((e+t)%2)}function c(e,t){return h.FILE_CHARS[t]+h.RANK_CHARS[e]}function p(e){return a(h.RANK_CHARS.indexOf(e[1]),h.FILE_CHARS.indexOf(e[0]))}function l(e){return c(n(e),s(e))}var h=i(0);e.exports={idxToRank:n,idxToFile:s,rfToIdx:a,isLight:u,rfToAlg:c,algToIdx:p,idxToAlg:l,pieceChar:r,otherColor:o}},function(e,t,i){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=i(11),s=n.U32,a=n.popcnt32,u=n.popLSB32,c=n.getLSB32;e.exports=function(){function e(t,i){r(this,e),this.lower=s(t),this.upper=s(i)}return o(e,[{key:"empty",value:function(){return!this.lower&&!this.upper}},{key:"isZero",value:function(e){return e=s(e),e<32?!(this.lower&1<<e):!(this.upper&1<<e-32)}},{key:"isOne",value:function(e){return!this.isZero(e)}},{key:"setBit",value:function(e){return e=s(e),e<32?this.lower=s(this.lower|1<<e):this.upper=s(this.upper|1<<e-32),this}},{key:"clearBit",value:function(e){return e=s(e),e<32?this.lower=s(this.lower&~(1<<e)):this.upper=s(this.upper&~(1<<e-32)),this}},{key:"popcnt",value:function(){return a(this.lower)+a(this.upper)}},{key:"popLSB",value:function(){return this.lower?this.lower=u(this.lower):this.upper=u(this.upper),this}},{key:"LSB",value:function(){return this.lower?c(this.lower):32+c(this.upper)}},{key:"popRetLSB",value:function(){var e=this.LSB();return this.popLSB(),e}},{key:"AND",value:function(e){return this.lower=s(this.lower&e.lower),this.upper=s(this.upper&e.upper),this}},{key:"AND_NOT",value:function(e){return this.lower=s(this.lower&~e.lower),this.upper=s(this.upper&~e.upper),this}},{key:"OR",value:function(e){return this.lower=s(this.lower|e.lower),this.upper=s(this.upper|e.upper),this}},{key:"XOR",value:function(e){return this.lower=s(this.lower^e.lower),this.upper=s(this.upper^e.upper),this}},{key:"NOT",value:function(){return this.lower=s(~this.lower),this.upper=s(~this.upper),this}},{key:"SHL",value:function(e){return e=s(e),e>31?(this.upper=s(this.lower<<e-32),this.lower=s(0)):e>0&&(this.upper=s(this.upper<<e|this.lower>>>32-e),this.lower=s(this.lower<<e)),this}},{key:"SHR",value:function(e){return e=s(e),e>31?(this.lower=this.upper>>>e-32,this.upper=s(0)):e>0&&(this.lower=s(this.lower>>>e|this.upper<<32-e),this.upper>>>=e),this}},{key:"SHIFT",value:function(e){return e>63||e<-63?this.lower=this.upper=s(0):e>0?this.SHL(e):e<0&&this.SHR(-e),this}},{key:"equals",value:function(e){return this.lower===e.lower&&this.upper===e.upper}},{key:"copy",value:function(){return new e(this.lower,this.upper)}}]),e}()},function(e,t,i){"use strict";var r=i(1),o=r.zeroBB,n=r.oneBB,s=r.lightBB,a=r.darkBB,u=r.fileBBs,c=r.rankBBs,p=r.diagBBs,l=r.antiDiagBBs;e.exports={ZERO:o(),ONE:n(),LIGHT_SQUARES:s(),DARK_SQUARES:a(),FILES:u(),RANKS:c(),DIAGONALS:p(),ANTIDIAGONALS:l()}},function(e,t,i){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=i(19),s=i(6),a=i(0),u=i(2),c=(u.idxToRank,u.idxToFile,u.rfToIdx,u.isLight),p=u.rfToAlg,l=u.algToIdx,h=u.idxToAlg,f=u.pieceChar,v=(u.otherColor,a.UI),B=v.ID,y=v.TABLE,N=v.SQUARE,O=v.PIECE,A=v.PIECE_SQ;e.exports=function(){function e(){r(this,e),this.pos=new n,this.ai=new s}return o(e,[{key:"createBoard",value:function(){for(var e=$("<table>"),t=0;t<a.NUM_RANKS;t++){var i=a.NUM_RANKS-1-t,r=$("<tr>");e.append(r);var o='<th class="rank">'+(a.NUM_RANKS-t)+"</th>";r.append(o);for(var n=0;n<a.NUM_FILES;n++){var s=$("<td>"),u=c(i,n)?"light":"dark";s.attr("id",p(i,n)),s.addClass(u),r.append(s)}}var l="<tr><th></th>"+"abcdefgh".split("").map(function(e){return'<th class="file">'+e+"</th>"}).join("")+"<th></th></tr>";e.append(l),$(B).append(e)}},{key:"clearMoving",value:function(){$(A).removeClass("from to king-castle queen-castle")}},{key:"clearDragging",value:function(){$(O+".ui-draggable").draggable("destroy"),$(N+".ui-droppable").droppable("destroy")}},{key:"updatePieces",value:function(){$(O).remove(),$(N).removeClass("white black turn last-move "+a.PIECE_NAMES.join(" "));for(var e=this.pos.colorBB(a.Colors.WHITE),t=this.pos.colorBB(a.Colors.BLACK),i=0;i<a.NUM_RANKS*a.NUM_FILES;++i)for(var r=$("#"+h(i)),o=a.Pieces.PAWN;o<=a.Pieces.KING;o++)if(this.pos.pieceBB(o).isOne(i)){var n=this.pos.turn===a.Colors.WHITE?e.isOne(i):t.isOne(i),s=$("<div>");s.text(f(o,e.isOne(i)?a.Colors.WHITE:a.Colors.BLACK));var u=s.add(r);u.addClass(a.PIECE_NAMES[o]),u.toggleClass("white",e.isOne(i)),u.toggleClass("black",t.isOne(i)),u.toggleClass("turn",n),r.append(s);break}}},{key:"updateMoves",value:function(){var e=this.pos.availableMoves();$(A).removeClass("can-move");var t=!0,i=!1,r=void 0;try{for(var o,n=e[Symbol.iterator]();!(t=(o=n.next()).done);t=!0){var s=o.value,u=$("#"+h(s.from()));u.add(u.children()).addClass("can-move")}}catch(e){i=!0,r=e}finally{try{!t&&n.return&&n.return()}finally{if(i)throw r}}var c=!1,p=this;$(O+".can-move").mouseenter(function(t){if(!c){var i=$(this),r=i.parent(),o=l(""+r.attr("id")),n=r.add(i);if(n.toggleClass("from",e.some(function(e){return e.from()===o})),n.hasClass("from")){var s=!0,u=!1,f=void 0;try{for(var v,B=e[Symbol.iterator]();!(s=(v=B.next()).done);s=!0){var O=v.value;if(O.from()===o){var A=$("#"+h(O.to()));A=A.add(A.children()),A.addClass("to"),O.type()===a.MoveTypes.KING_CASTLE&&A.addClass("king-castle"),O.type()===a.MoveTypes.QUEEN_CASTLE&&A.addClass("queen-castle")}}}catch(e){u=!0,f=e}finally{try{!s&&B.return&&B.return()}finally{if(u)throw f}}p.clearDragging(),$(N+".to").droppable({drop:function(){var t=l(""+$(this).attr("id")),i=e.filter(function(e){return e.from()===o&&e.to()===t});i.length>0?(p.pos.makeMove(i[0]),p.updatePos()):(p.clearMoving(),p.clearDragging())}}),i.draggable({start:function(){return c=!0},stop:function(){return c=!1},containment:y,zIndex:10,revert:"invalid"})}}}).mouseleave(function(){c||p.clearMoving()})}},{key:"aiMove",value:function(){var e=this,t=e.ai.search(e.pos);e.pos.makeMove(t);var i=$("#"+h(t.from())),r=$("#"+h(t.to())),o=r.offset().left-i.offset().left,n=r.offset().top-i.offset().top,s=i.children("div");s.css({position:"relative",top:"0px",left:"0px"}),s.animate({top:n+"px",left:o+"px"},function(){return e.updatePos()})}},{key:"updatePos",value:function(){this.clearMoving(),this.clearDragging(),this.updatePieces();var e=this.pos.status(),t=this.pos.turn;e===a.Status.NORMAL&&t===a.Colors.BLACK?this.aiMove():this.updateMoves()}}]),e}()},function(e,t,i){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=i(0),s=i(7),a=(s.material,s.evalMaterial,s.pieceSqVal,s.evalLocations,s.evaluate),u=s.orderMoves;e.exports=function(){function e(){r(this,e)}return o(e,[{key:"search",value:function(e){function t(e,i,r){if(e.isDraw())return 0;var o=a(e),s=e.turn===n.Colors.WHITE;if(s){if(o>=r)return r;i=o>i?o:i}else{if(o<=i)return i;r=o<r?o:r}var c=u(e.availableMoves(!0,!e.inCheck())),p=!0,l=!1,h=void 0;try{for(var f,v=c[Symbol.iterator]();!(p=(f=v.next()).done);p=!0){var B=f.value;if(e.makeMove(B)){var y=t(e,i,r);if(e.unmakeMove(),s){if(y>=r)return r;i=y>i?y:i}else{if(y<=i)return i;r=y<r?y:r}}}}catch(e){l=!0,h=e}finally{try{!p&&v.return&&v.return()}finally{if(l)throw h}}return s?i:r}function i(e,r,o,s){if(r<1)return t(e,o,s);var a=u(e.availableMoves(!0,!1)),c=e.turn===n.Colors.WHITE,p=!1,l=!0,h=!1,f=void 0;try{for(var v,B=a[Symbol.iterator]();!(l=(v=B.next()).done);l=!0){var y=v.value;if(e.makeMove(y)){p=!0;var N=i(e,r-1,o,s);if(e.unmakeMove(),c?o=N>o?N:o:s=N<s?N:s,s<=o)break}}}catch(e){h=!0,f=e}finally{try{!l&&B.return&&B.return()}finally{if(h)throw f}}if(!p){if(!e.inCheck())return 0;var O=n.PIECE_VALS[n.Pieces.KING];return c?-O:O}return e.isDraw()?0:c?o:s}var r=-1/0,o=1/0,s=null,c=u(e.availableMoves(!0)),p=!0,l=!1,h=void 0;try{for(var f,v=c[Symbol.iterator]();!(p=(f=v.next()).done);p=!0){var B=f.value;if(e.makeMove(B)){var y=i(e,3,r,o);e.unmakeMove(),e.turn===n.Colors.WHITE?y>r&&(r=y,s=B):y<o&&(o=y,s=B)}}}catch(e){l=!0,h=e}finally{try{!p&&v.return&&v.return()}finally{if(l)throw h}}return s}}]),e}()},function(e,t,i){"use strict";function r(e,t){for(var i=0,r=p.Pieces.PAWN;r<p.Pieces.KING;r++)i+=e.pieceColorBB(r,t).popcnt()*p.PIECE_VALS[r];return e.pieceColorBB(p.Pieces.BISHOP,t).popcnt()>1&&(i+=p.BISHOP_PAIR),i}function o(e){return r(e,p.Colors.WHITE)-r(e,p.Colors.BLACK)}function n(e,t){for(var i=0,r=p.Pieces.PAWN;r<=p.Pieces.KING;r++)for(var o=e.pieceColorBB(r,t).copy();!o.empty();){var n=o.popRetLSB();i+=p.PST[r][t?n:56^n]}return i}function s(e){return n(e,p.Colors.WHITE)-n(e,p.Colors.BLACK)}function a(e){return o(e)+s(e)}function u(e){var t=e.isCapt()?(1+e.captPiece())/(1+e.piece()):0;return t=6*t+e.piece(),t=16*t+e.type(),t=64*t+e.to(),t=64*t+e.from()}function c(e){return e.sort(function(e,t){return u(t)-u(e)}),e}var p=i(0);e.exports={material:r,evalMaterial:o,pieceSqVal:n,evalLocations:s,evaluate:a,orderMoves:c}},function(e,t,i){"use strict";var r=i(4),o=i(9),n=i(10);e.exports=Object.assign({},r,o,n)},function(e,t,i){"use strict";function r(e){var t=a().setBit(e),i=t.copy().SHR(1).AND_NOT(n.FILES[7]),r=t.copy().SHR(2).AND_NOT(n.FILES[7]).AND_NOT(n.FILES[6]),o=t.copy().SHL(1).AND_NOT(n.FILES[0]),s=t.copy().SHL(2).AND_NOT(n.FILES[0]).AND_NOT(n.FILES[1]),u=r.OR(s),c=i.OR(o);return u.copy().SHL(8).OR(u.SHR(8)).OR(c.copy().SHL(16)).OR(c.SHR(16))}function o(e){var t=a().setBit(e),i=t.copy().SHR(1).AND_NOT(n.FILES[7]).OR(t.copy().SHL(1).AND_NOT(n.FILES[0])),r=t.copy().OR(i).SHR(8),o=t.copy().OR(i).SHL(8);return i.OR(r).OR(o)}var n=i(4),s=i(1),a=s.zeroBB;e.exports={KNIGHT_MOVEMENTS:function(){for(var e=[],t=0;t<64;++t)e.push(r(t));return e}(),KING_MOVEMENTS:function(){for(var e=[],t=0;t<64;++t)e.push(o(t));return e}()}},function(e,t,i){"use strict";var r=i(0),o=i(1),n=o.fileBB,s=o.oneBB;e.exports={SLIDING_MASKS:[n(r.NUM_FILES-1).NOT(),s(),n(0).NOT()]}},function(e,t,i){"use strict";function r(e){return e>>>0}function o(e){return e=r(e),e-=e>>>1&1431655765,16843009*((e=(858993459&e)+(e>>>2&858993459))+(e>>>4)&252645135)>>>24}function n(e){return e=r(e),r(e&e-1)}function s(e){return e=r(e),o((e&-e)-1)}e.exports={U32:r,popcnt32:o,popLSB32:n,getLSB32:s}},function(e,t,i){"use strict";var r=i(3),o=i(8),n=i(1);e.exports={Bitboard:r,Boards:o,BButils:n}},function(e,t,i){"use strict";e.exports={PIECE_VALS:[100,300,300,500,900,2e4],PST:[[0,0,0,0,0,0,0,0,50,50,50,50,50,50,50,50,10,10,20,30,30,20,10,10,5,5,10,25,25,10,5,5,0,0,0,20,20,0,0,0,5,-5,-10,0,0,-10,-5,5,5,10,10,-20,-20,10,10,5,0,0,0,0,0,0,0,0],[-50,-40,-30,-30,-30,-30,-40,-50,-40,-20,0,0,0,0,-20,-40,-30,0,10,15,15,10,0,-30,-30,5,15,20,20,15,5,-30,-30,0,15,20,20,15,0,-30,-30,5,10,15,15,10,5,-30,-40,-20,0,5,5,0,-20,-40,-50,-40,-30,-30,-30,-30,-40,-50],[-20,-10,-10,-10,-10,-10,-10,-20,-10,0,0,0,0,0,0,-10,-10,0,5,10,10,5,0,-10,-10,5,5,10,10,5,5,-10,-10,0,10,10,10,10,0,-10,-10,10,10,10,10,10,10,-10,-10,5,0,0,0,0,5,-10,-20,-10,-10,-10,-10,-10,-10,-20],[0,0,0,0,0,0,0,0,5,10,10,10,10,10,10,5,-5,0,0,0,0,0,0,-5,-5,0,0,0,0,0,0,-5,-5,0,0,0,0,0,0,-5,-5,0,0,0,0,0,0,-5,-5,0,0,0,0,0,0,-5,0,0,0,5,5,0,0,0],[-20,-10,-10,-5,-5,-10,-10,-20,-10,0,0,0,0,0,0,-10,-10,0,5,5,5,5,0,-10,-5,0,5,5,5,5,0,-5,0,0,5,5,5,5,0,-5,-10,5,5,5,5,5,0,-10,-10,0,5,0,0,0,0,-10,-20,-10,-10,-5,-5,-10,-10,-20],[-30,-40,-40,-50,-50,-40,-40,-30,-30,-40,-40,-50,-50,-40,-40,-30,-30,-40,-40,-50,-50,-40,-40,-30,-30,-40,-40,-50,-50,-40,-40,-30,-20,-30,-30,-40,-40,-30,-30,-20,-10,-20,-20,-20,-20,-20,-20,-10,20,20,0,0,0,0,20,20,20,30,10,0,0,10,30,20]],BISHOP_PAIR:50}},function(e,t,i){"use strict";e.exports={NUM_RANKS:8,NUM_FILES:8,FILE_CHARS:"abcdefgh",RANK_CHARS:"12345678",PIECE_CHARS:"♙♟♘♞♗♝♖♜♕♛♔♚",Pieces:{PAWN:0,KNIGHT:1,BISHOP:2,ROOK:3,QUEEN:4,KING:5},Colors:{WHITE:0,BLACK:1},PIECE_NAMES:["pawn","knight","bishop","rook","queen","king"],ALG_NAMES:" NBRQK"}},function(e,t,i){"use strict";e.exports={MoveTypes:{QUIET:0,DOUBLE_PAWN_PUSH:1,KING_CASTLE:2,QUEEN_CASTLE:3,CAPTURE:4,EN_PASSANT_CAPTURE:5,KNIGHT_PROMOTION:8,BISHOP_PROMOTION:9,ROOK_PROMOTION:10,QUEEN_PROMOTION:11,KNIGHT_PROMOTION_CAPTURE:12,BISHOP_PROMOTION_CAPTURE:13,ROOK_PROMOTION_CAPTURE:14,QUEEN_PROMOTION_CAPTURE:15}}},function(e,t,i){"use strict";e.exports={WHITES:6,BLACKS:7,CORNERS:[7,63,0,56],Status:{NORMAL:0,CHECKMATE:1,DRAW:2}}},function(e,t,i){"use strict";var r={};r.ID="#board",r.TABLE=r.ID+" table",r.SQUARE=r.ID+" table tr td",r.PIECE=r.SQUARE+" div",r.PIECE_SQ=r.SQUARE+", "+r.PIECE,e.exports={UI:r}},function(e,t,i){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=i(0),s=i(2);s.idxToRank,s.getFile,s.isInsideBoard,s.getIndex,s.isLight,s.getAlgebraic,s.algToIdx,s.idxToAlg,s.pieceChar,s.otherColor;e.exports=function(){function e(t,i,o,n,s){r(this,e),s=s||0,this.val=63&i|(63&t)<<6|(15&o)<<12|(7&n)<<16|(7&s)<<19}return o(e,[{key:"to",value:function(){return 63&this.val}},{key:"from",value:function(){return this.val>>>6&63}},{key:"type",value:function(){return this.val>>>12&15}},{key:"piece",value:function(){return this.val>>>16&7}},{key:"isCapt",value:function(){return!!(4&this.type())}},{key:"captPiece",value:function(){return this.val>>>19&7}},{key:"isPromo",value:function(){return!!(8&this.type())}},{key:"isCas",value:function(){return this.type()===n.MoveTypes.KING_CASTLE||this.type()===n.MoveTypes.QUEEN_CASTLE}},{key:"promoPiece",value:function(){return this.isPromo()?n.Pieces.KNIGHT+(3&this.type()):n.Pieces.PAWN}},{key:"captSq",value:function(){return this.type()!==n.MoveTypes.EN_PASSANT_CAPTURE?this.to():this.to()+(this.from()<this.to()?-n.NUM_FILES:n.NUM_FILES)}}]),e}()},function(e,t,i){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),n=i(0),s=i(18),a=i(12),u=(a.Bitboard,a.Boards),c=a.BButils,p=i(2),l=(p.idxToRank,p.idxToFile,p.rfToIdx,p.isLight,p.rfToAlg,p.algToIdx,p.idxToAlg,p.pieceChar,p.otherColor),h=i(20),f=h.casIdx,v=h.casRkSq;e.exports=function(){function e(){r(this,e),this.bitboards=[u.RANKS[1].copy().OR(u.RANKS[6]),c.idxBB(1).OR(c.idxBB(6)).OR(c.idxBB(57)).OR(c.idxBB(62)),c.idxBB(2).OR(c.idxBB(5)).OR(c.idxBB(58)).OR(c.idxBB(61)),c.idxBB(0).OR(c.idxBB(7)).OR(c.idxBB(56)).OR(c.idxBB(63)),c.idxBB(3).OR(c.idxBB(59)),c.idxBB(4).OR(c.idxBB(60)),u.RANKS[0].copy().OR(u.RANKS[1]),u.RANKS[6].copy().OR(u.RANKS[7])],this.turn=n.Colors.WHITE,this.cas=15,this.enPas=-1,this.halfMoves=0,this.pieceList=[],this.moves=[],this.hist=[];for(var t=0;t<64;t++)this.pieceList[t]=this.getPieceFromBB(t)}return o(e,[{key:"colorBB",value:function(e){return this.bitboards[n.WHITES+e]}},{key:"pieceBB",value:function(e){return this.bitboards[e]}},{key:"pieceColorBB",value:function(e,t){return this.bitboards[e].copy().AND(this.colorBB(t))}},{key:"kingPos",value:function(e){return this.pieceColorBB(n.Pieces.KING,e).LSB()}},{key:"occupiedBB",value:function(){return this.bitboards[n.WHITES].copy().OR(this.bitboards[n.BLACKS])}},{key:"emptyBB",value:function(){return this.occupiedBB().NOT()}},{key:"inCheck",value:function(){return this.isAttacked(l(this.turn),this.kingPos(this.turn))}},{key:"pawnAttack",value:function(e,t){var i=e===n.Colors.WHITE,r=t.copy().AND_NOT(u.FILES[0]).SHIFT(i?7:-9),o=t.copy().AND_NOT(u.FILES[n.NUM_FILES-1]).SHIFT(i?9:-7);return r.OR(o)}},{key:"slidingAttack",value:function(e,t,i,r){var o=c.zeroBB(),s=i*n.NUM_FILES+r,a=u.SLIDING_MASKS[1+r];for(e.SHIFT(s);!e.AND(a).empty();e.AND_NOT(t).SHIFT(s))o.OR(e);return o}},{key:"bishopAttack",value:function(e,t){return this.slidingAttack(e.copy(),t,1,1).OR(this.slidingAttack(e.copy(),t,1,-1)).OR(this.slidingAttack(e.copy(),t,-1,1)).OR(this.slidingAttack(e.copy(),t,-1,-1))}},{key:"rookAttack",value:function(e,t){return this.slidingAttack(e.copy(),t,0,1).OR(this.slidingAttack(e.copy(),t,0,-1)).OR(this.slidingAttack(e.copy(),t,1,0)).OR(this.slidingAttack(e.copy(),t,-1,0))}},{key:"isAttacked",value:function(e,t){var i=this.pieceColorBB(n.Pieces.PAWN,e);if(this.pawnAttack(e,i).isOne(t))return!0;var r=this.pieceColorBB(n.Pieces.KNIGHT,e);if(!u.KNIGHT_MOVEMENTS[t].copy().AND(r).empty())return!0;var o=this.pieceColorBB(n.Pieces.KING,e);if(!u.KING_MOVEMENTS[t].copy().AND(o).empty())return!0;var s=this.occupiedBB(),a=this.pieceColorBB(n.Pieces.QUEEN,e),c=this.pieceColorBB(n.Pieces.BISHOP,e).copy().OR(a);if(this.bishopAttack(c,s).isOne(t))return!0;var p=this.pieceColorBB(n.Pieces.ROOK,e).copy().OR(a);return!!this.rookAttack(p,s).isOne(t)}},{key:"hasCasRight",value:function(e,t){return 0!=(this.cas&1<<f(e,t))}},{key:"clearCasRight",value:function(e,t){this.cas&=~(1<<f(e,t))}},{key:"canCastle",value:function(e,t){if(!this.hasCasRight(e,t))return!1;var i=t?1:-1,r=e===n.Colors.WHITE?4:60,o=this.occupiedBB();return!o.isOne(r+i)&&!o.isOne(r+2*i)&&(!(!t&&o.isOne(r+3*i))&&!!this.isCasLegal(e,t))}},{key:"isCasLegal",value:function(e,t){var i=l(e),r=t?1:-1,o=e===n.Colors.WHITE?4:60;return!this.isAttacked(i,o)&&!this.isAttacked(i,o+r)&&!this.isAttacked(i,o+2*r)}},{key:"isDraw",value:function(){if(this.halfMoves>=100)return!0;if(!this.pieceBB(n.Pieces.PAWN).empty())return!1;if(!this.pieceBB(n.Pieces.ROOK).empty())return!1;if(!this.pieceBB(n.Pieces.QUEEN).empty())return!1;if(this.colorBB(n.Colors.WHITE).popcnt()+this.colorBB(n.Colors.BLACK).popcnt()<4)return!0;if(!this.pieceBB(n.Pieces.KNIGHT).empty())return!1;var e=this.pieceBB(n.Pieces.BISHOP);return!(!e.copy().AND(u.LIGHT_SQUARES).equals(e)&&!e.copy().AND(u.DARK_SQUARES).equals(e))}},{key:"status",value:function(){return this.availableMoves().length?this.isDraw()?n.Status.DRAW:n.Status.NORMAL:this.inCheck()?n.Status.CHECKMATE:n.Status.DRAW}},{key:"availableMoves",value:function(e,t){var i=this.getMoves(!!t);return e?i:i.filter(this.isLegalMove,this)}},{key:"isLegalMove",value:function(e){this.update(e);var t=this.inCheck();return this.revert(e),!t}},{key:"getMoves",value:function(e){var t=[],i=this.turn,r=this.colorBB(i),o=this.colorBB(l(i)),a=this.occupiedBB(),p=this,h=function(e,i,r){for(;!e.empty();){var o=e.popRetLSB();t.push(new s(o-i,o,r,n.Pieces.PAWN,p.getPieceFromPL(o)))}},f=function(e,t,i){h(e.copy(),t,i?n.MoveTypes.QUEEN_PROMOTION_CAPTURE:n.MoveTypes.QUEEN_PROMOTION),h(e.copy(),t,i?n.MoveTypes.ROOK_PROMOTION_CAPTURE:n.MoveTypes.ROOK_PROMOTION),h(e.copy(),t,i?n.MoveTypes.BISHOP_PROMOTION_CAPTURE:n.MoveTypes.BISHOP_PROMOTION),h(e.copy(),t,i?n.MoveTypes.KNIGHT_PROMOTION_CAPTURE:n.MoveTypes.KNIGHT_PROMOTION)},v=function(e,i,a){for(;!i.empty();){var u=i.popRetLSB();r.isZero(u)&&t.push(new s(e,u,o.isOne(u)?n.MoveTypes.CAPTURE:n.MoveTypes.QUIET,a,p.getPieceFromPL(u)))}},B=1-2*i,y=n.NUM_FILES*B,N=this.pieceColorBB(n.Pieces.PAWN,i),O=u.RANKS[i?0:n.NUM_RANKS-1];if(!e){var A=N.copy().AND(u.RANKS[i?6:1]).SHIFT(2*y).AND_NOT(a).AND_NOT(a.copy().SHIFT(y));h(A,2*y,n.MoveTypes.DOUBLE_PAWN_PUSH);var S=N.copy().SHIFT(y).AND_NOT(a);h(S.copy().AND_NOT(O),y,n.MoveTypes.QUIET),f(S.copy().AND(O),y,!1)}var T=u.FILES[i?n.NUM_FILES-1:0],d=y-B,E=N.copy().AND_NOT(T).SHIFT(d).AND(o);h(E.copy().AND_NOT(O),d,n.MoveTypes.CAPTURE),f(E.copy().AND(O),d,!0);var P=u.FILES[i?0:n.NUM_FILES-1],R=y+B,I=N.copy().AND_NOT(P).SHIFT(R).AND(o);if(h(I.copy().AND_NOT(O),R,n.MoveTypes.CAPTURE),f(I.copy().AND(O),R,!0),this.enPas>=0){var C=c.idxBB(this.enPas+B).AND(N).AND_NOT(T).SHIFT(d);h(C,d,n.MoveTypes.EN_PASSANT_CAPTURE);var k=c.idxBB(this.enPas-B).AND(N).AND_NOT(P).SHIFT(R);h(k,R,n.MoveTypes.EN_PASSANT_CAPTURE)}for(var M=e?o:u.ONE,_=this.pieceColorBB(n.Pieces.KNIGHT,i).copy();!_.empty();){var g=_.popRetLSB();v(g,u.KNIGHT_MOVEMENTS[g].copy().AND(M),n.Pieces.KNIGHT)}for(var L=this.pieceColorBB(n.Pieces.QUEEN,i).copy();!L.empty();){var m=L.popRetLSB();v(m,this.bishopAttack(c.idxBB(m),a).OR(this.rookAttack(c.idxBB(m),a)).AND(M),n.Pieces.QUEEN)}for(var H=this.pieceColorBB(n.Pieces.BISHOP,i).copy();!H.empty();){var x=H.popRetLSB();v(x,this.bishopAttack(c.idxBB(x),a).AND(M),n.Pieces.BISHOP)}for(var K=this.pieceColorBB(n.Pieces.ROOK,i).copy();!K.empty();){var b=K.popRetLSB();v(b,this.rookAttack(c.idxBB(b),a).AND(M),n.Pieces.ROOK)}var w=this.kingPos(i);return v(w,u.KING_MOVEMENTS[w].copy().AND(M),n.Pieces.KING),e||(this.canCastle(i,!0)&&t.push(new s(w,w+2,n.MoveTypes.KING_CASTLE,n.Pieces.KING,null)),this.canCastle(i,!1)&&t.push(new s(w,w-2,n.MoveTypes.QUEEN_CASTLE,n.Pieces.KING,null))),t}},{key:"capture",value:function(e,t,i){this.pieceBB(e).clearBit(i),this.colorBB(t).clearBit(i),this.pieceList[i]=null}},{key:"uncapture",value:function(e,t,i){this.pieceBB(e).setBit(i),this.colorBB(t).setBit(i),this.pieceList[i]=e}},{key:"move",value:function(e,t,i,r){var o=c.idxBB(i).OR(c.idxBB(r));this.pieceBB(e).XOR(o),this.colorBB(t).XOR(o),this.pieceList[i]=null,this.pieceList[r]=e}},{key:"casRook",value:function(e,t){var i=v(e,t),r=i+(t?-2:3);this.move(n.Pieces.ROOK,e,i,r)}},{key:"unCasRook",value:function(e,t){var i=v(e,t),r=i+(t?-2:3);this.move(n.Pieces.ROOK,e,r,i)}},{key:"promote",value:function(e,t,i,r){this.pieceBB(e).clearBit(r),this.pieceBB(t).setBit(r),this.pieceList[r]=t}},{key:"update",value:function(e){e.isCapt()&&this.capture(e.captPiece(),l(this.turn),e.captSq()),e.isCas()&&this.casRook(this.turn,e.type()===n.MoveTypes.KING_CASTLE),this.move(e.piece(),this.turn,e.from(),e.to()),e.isPromo()&&this.promote(n.Pieces.PAWN,e.promoPiece(),this.turn,e.to())}},{key:"revert",value:function(e){e.isPromo()&&this.promote(e.promoPiece(),n.Pieces.PAWN,this.turn,e.to()),this.move(e.piece(),this.turn,e.to(),e.from()),e.isCas()&&this.unCasRook(this.turn,e.type()===n.MoveTypes.KING_CASTLE),e.isCapt()&&this.uncapture(e.captPiece(),l(this.turn),e.captSq())}},{key:"makeMove",value:function(e){if(this.update(e),this.inCheck())return this.revert(e),!1;this.moves.push(e),this.hist.push(this.enPas),this.hist.push(this.cas),this.hist.push(this.halfMoves),e.type()===n.MoveTypes.DOUBLE_PAWN_PUSH?this.enPas=e.to():this.enPas=-1;var t=this.turn;e.piece()===n.Pieces.KING?(this.clearCasRight(t,!0),this.clearCasRight(t,!1)):e.piece()===n.Pieces.ROOK&&(e.from()===v(t,!0)?this.clearCasRight(t,!0):e.from()===v(t,!1)&&this.clearCasRight(t,!1));var i=l(t);return e.captPiece()===n.Pieces.ROOK&&(e.captSq()===v(i,!0)?this.clearCasRight(i,!0):e.captSq()===v(i,!1)&&this.clearCasRight(i,!1)),e.isCapt()||e.piece()===n.Pieces.PAWN?this.halfMoves=0:this.halfMoves++,this.turn=i,!0}},{key:"unmakeMove",value:function(){if(!this.moves.length>0)return null;var e=this.moves.pop();return this.turn=l(this.turn),this.revert(e),this.halfMoves=this.hist.pop(),this.cas=this.hist.pop(),this.enPas=this.hist.pop(),e}},{key:"getPieceFromPL",value:function(e){return this.pieceList[e]}},{key:"getPieceFromBB",value:function(e){for(var t=n.Pieces.PAWN;t<=n.Pieces.KING;t++)if(this.pieceBB(t).isOne(e))return t;return null}}]),e}()},function(e,t,i){"use strict";function r(e,t){if(!e)return 1;var i=0,o=!0,n=!1,s=void 0;try{for(var a,u=t.availableMoves(!0)[Symbol.iterator]();!(o=(a=u.next()).done);o=!0){var c=a.value;t.makeMove(c)&&(i+=r(e-1,t),t.unmakeMove())}}catch(e){n=!0,s=e}finally{try{!o&&u.return&&u.return()}finally{if(n)throw s}}return i}function o(e,t){return e+(t?0:2)}function n(e,t){return s.CORNERS[o(e,t)]}var s=i(0);e.exports={perft:r,casIdx:o,casRkSq:n}},function(e,t,i){"use strict";var r=i(5);!function(){document.addEventListener("DOMContentLoaded",function(){var e=new r;e.createBoard(),e.updatePos()},!1)}()}]);