Kaj Björklund
11 years ago
3 changed files with 28 additions and 40 deletions
@ -1,32 +1,29 @@ |
|||||
(function(){'use strict';var h=0,k=5,p=0,ba="pawn knight bishop rook queen king".split(" ");function ca(a,b){return"abcdefgh"[b]+"12345678"[a]}function da(a){return"abcdefgh".indexOf(a[0])+8*"12345678".indexOf(a[1])}function q(a){return ca(a>>>3,a&7)};function ea(a,b){this.a=a>>>0;this.b=b>>>0}function fa(a){a>>>=0;a-=a>>>1&1431655765;a=(a&858993459)+(a>>>2&858993459);return 16843009*(a+(a>>>4)&252645135)>>>24}function ga(a){a>>>=0;return(a&a-1)>>>0}function ha(a){a>>>=0;return fa((a&-a)-1)}function r(a){return fa(a.a)+fa(a.b)}function ia(a){return a.a?ha(a.a):32+ha(a.b)}function s(a){var b=ia(a);a.a?a.a=ga(a.a):a.b=ga(a.b);return b}function t(a){return!a.a&&!a.b}function v(a,b){b>>>=0;return 32>b?!(a.a&1<<b):!(a.b&1<<b-32)} |
|
||||
function ja(a,b){return!v(a,b)}function w(a,b){b>>>=0;32>b?a.a=(a.a|1<<b)>>>0:a.b=(a.b|1<<b-32)>>>0;return a}function ka(a,b){b>>>=0;32>b?a.a=(a.a&~(1<<b))>>>0:a.b=(a.b&~(1<<b-32))>>>0}function y(a,b){a.a=(a.a&b.a)>>>0;a.b=(a.b&b.b)>>>0;return a}function A(a,b){a.a=(a.a&~b.a)>>>0;a.b=(a.b&~b.b)>>>0;return a}function B(a,b){a.a=(a.a|b.a)>>>0;a.b=(a.b|b.b)>>>0;return a}function la(a,b){a.a=(a.a^b.a)>>>0;a.b=(a.b^b.b)>>>0}function na(a){a.a=~a.a>>>0;a.b=~a.b>>>0;return a} |
|
||||
function C(a,b){b>>>=0;31<b?(a.b=a.a<<b-32>>>0,a.a=0):0<b&&(a.b=(a.b<<b|a.a>>>32-b)>>>0,a.a=a.a<<b>>>0);return a}function D(a,b){b>>>=0;31<b?(a.a=a.b>>>b-32,a.b=0):0<b&&(a.a=(a.a>>>b|a.b<<32-b)>>>0,a.b>>>=b);return a}function E(a,b){63<b||-63>b?a.a=a.b=0:0<b?C(a,b):0>b&&D(a,-b);return a}function oa(a,b){return a.a===b.a&&a.b===b.b}function F(a){return H(a.a,a.b)}function H(a,b){return new ea(a,b)}function I(a){return w(H(0,0),a)} |
|
||||
function pa(){var a=qa;return E(y(H(270549120,16909320),E(H(4294967295,4294967295),8*a)),a)}function ra(){var a=sa;return E(y(H(134480385,2151686160),E(H(4294967295,4294967295),8*-a)),a)}function ta(){var a=w(H(0,0),ua),b=A(D(F(a),1),J[7]),c=A(A(D(F(a),2),J[7]),J[6]),d=A(C(F(a),1),J[0]),a=A(A(C(F(a),2),J[0]),J[1]),c=B(c,a),b=B(b,d);return B(B(B(C(F(c),8),D(c,8)),C(F(b),16)),D(b,16))} |
|
||||
function va(){var a=w(H(0,0),wa),b=B(A(D(F(a),1),J[7]),A(C(F(a),1),J[0])),c=D(B(F(a),b),8),a=C(B(F(a),b),8);return B(B(b,c),a)}for(var xa=H(4294967295,4294967295),ya=H(1437226410,1437226410),za=H(2857740885,2857740885),Aa=[],Ba=0;8>Ba;++Ba)Aa.push(C(H(16843009,16843009),Ba));for(var J=Aa,K=[],Ca=0;8>Ca;++Ca)K.push(C(H(255,0),8*Ca));for(var Da=[],qa=-7;8>qa;++qa)Da.push(pa());for(var Ea=[],sa=-7;8>sa;++sa)Ea.push(ra());for(var Fa=[],ua=0;64>ua;++ua)Fa.push(ta());for(var Ga=[],wa=0;64>wa;++wa)Ga.push(va());function Ha(a,b){this.b=a>>>0;this.a=b>>>0}for(var Ia=[],Ja=0;1586>Ja;++Ja)Ia.push(1+4294967295*Math.random()>>>0);function L(a,b){a.b=(a.b^Ia[b])>>>0;a.a=(a.a^Ia[b+1])>>>0}function N(a,b){0<=b&&L(a,1570+(b&7))};function Ka(a,b,c,d,e){this.a=b&63|(a&63)<<6|(c&15)<<12|(d&7)<<16|((e|0)&7)<<19}var La=0,Ma=4,Na=8,Oa=9,Pa=10,Qa=11,Ra=12,Sa=13,Ta=14,Ua=15;function O(a){return a.a>>>6&63}function P(a){return a.a>>>12&15}function Q(a){return a.a>>>16&7}function Va(a){return 2===P(a)||3===P(a)}function Wa(a){return P(a)&8?1+(P(a)&3):h}function Xa(a){return 5!==P(a)?a.a&63:(a.a&63)+(O(a)<(a.a&63)?-8:8)} |
|
||||
function Ya(a){return Va(a)?"0-0"+(3===P(a)?"-0":""):" NBRQK".charAt(Q(a))+q(O(a))+(P(a)&4?"x":"-")+q(a.a&63)+(5===P(a)?"e.p.":"")+(P(a)&8?" NBRQK".charAt(Wa(a)):"")};function ab(){this.b=new Ha(0,0);this.a=[B(F(K[1]),K[6]),B(B(B(I(1),I(6)),I(57)),I(62)),B(B(B(I(2),I(5)),I(58)),I(61)),B(B(B(I(0),I(7)),I(56)),I(63)),B(I(3),I(59)),B(I(4),I(60)),B(F(K[0]),K[1]),B(F(K[6]),K[7])];this.f=[];this.c=p;this.e=15;this.d=-1;this.h=0;this.g=[];this.i=[];for(var a=this.f.length=0;64>a;++a){var b;a:{for(b=h;b<=k;++b)if(!v(this.a[b],a))break a;b=null}this.f.push(b)}this.b=new Ha(0,0);this.c&&L(this.b,0);for(a=p;1>=a;++a)for(b=h;b<=k;++b)for(var c=this.b,d=b,e=a,f=R(this,b,a), |
|
||||
f=F(f);!t(f);){var g=s(f);L(c,2+d+6*e+12*g)}L(this.b,1538+this.e);N(this.b,this.d);this.j=[]}var S=k+1,bb=S+1,T=[7,63,0,56],cb=[na(C(H(16843009,16843009),7)),xa,na(C(H(16843009,16843009),0))];function U(a,b,c){c=db(a,!!c);return b?c:c.filter(ab.prototype.k,a)}function R(a,b,c){return y(F(a.a[b]),a.a[S+c])}function V(a){return B(F(a.a[S]),a.a[bb])}function W(a){return eb(a,a.c^1,ia(R(a,k,a.c)))}function fb(a,b){var c=a===p,d=E(A(F(b),J[0]),c?7:-9),c=E(A(F(b),J[7]),c?9:-7);return B(d,c)} |
|
||||
function X(a,b,c,d){var e=H(0,0);c=8*c+d;d=cb[1+d];for(E(a,c);!t(y(a,d));E(A(a,b),c))B(e,a);return e}function gb(a,b){return B(B(B(X(F(a),b,1,1),X(F(a),b,1,-1)),X(F(a),b,-1,1)),X(F(a),b,-1,-1))}function hb(a,b){return B(B(B(X(F(a),b,0,1),X(F(a),b,0,-1)),X(F(a),b,1,0)),X(F(a),b,-1,0))} |
|
||||
function eb(a,b,c){var d=R(a,h,b);if(ja(fb(b,d),c))return!0;d=R(a,1,b);if(!t(y(F(Fa[c]),d)))return!0;d=R(a,k,b);if(!t(y(F(Ga[c]),d)))return!0;var d=V(a),e=R(a,4,b),f=B(F(R(a,2,b)),e);if(ja(gb(f,d),c))return!0;a=B(F(R(a,3,b)),e);return ja(hb(a,d),c)?!0:!1}function Y(a,b,c){L(a.b,1538+a.e);a.e&=~(1<<b+(c?0:2));L(a.b,1538+a.e)} |
|
||||
function ib(a,b,c){if(0===(a.e&1<<b+(c?0:2)))return!1;var d=c?1:-1,e=b===p?4:60,f=V(a);(d=!v(f,e+d)||!v(f,e+2*d)||!c&&!v(f,e+3*d))||(d=b^1,c=c?1:-1,b=b===p?4:60,d=!(!eb(a,d,b)&&!eb(a,d,b+c)&&!eb(a,d,b+2*c)));return d?!1:!0}function jb(a){var b=a.b;return 3<=a.j.reduce(function(a,d){return a+(d.b===b.b&&d.a===b.a?1:0)},0)} |
|
||||
function kb(a){if(!t(a.a[h])||!t(a.a[3])||!t(a.a[4]))return!1;if(4>r(a.a[S+p])+r(a.a[S+1]))return!0;if(!t(a.a[1]))return!1;a=a.a[2];return oa(y(F(a),ya),a)||oa(y(F(a),za),a)?!0:!1} |
|
||||
function db(a,b){function c(a,b,c){for(;!t(a);){var d=s(a);f.push(new Ka(d-b,d,c,h,z.f[d]))}}function d(a,b,d){c(F(a),b,d?Ua:Qa);c(F(a),b,d?Ta:Pa);c(F(a),b,d?Sa:Oa);c(F(a),b,d?Ra:Na)}function e(a,b,c){for(;!t(b);){var d=s(b);v(yb,d)&&f.push(new Ka(a,d,v(m,d)?La:Ma,c,z.f[d]))}}var f=[],g=a.c,m=a.a[S+(g^1)],l=V(a),z=a,n=1-2*g,G=8*n,x=R(a,h,g),u=K[g?0:7];if(!b){var M=A(A(E(y(F(x),K[g?6:1]),2*G),l),E(F(l),G));c(M,2*G,1);M=A(E(F(x),G),l);c(A(F(M),u),G,La);d(y(F(M),u),G,!1)}var Za=J[g?7:0],M=G-n,aa=y(E(A(F(x), |
|
||||
Za),M),m);c(A(F(aa),u),M,Ma);d(y(F(aa),u),M,!0);var aa=J[g?0:7],G=G+n,$a=y(E(A(F(x),aa),G),m);c(A(F($a),u),G,Ma);d(y(F($a),u),G,!0);0<=a.d&&(u=E(A(y(I(a.d+n),x),Za),M),c(u,M,5),n=E(A(y(I(a.d-n),x),aa),G),c(n,G,5));for(var yb=a.a[S+g],n=b?m:xa,x=F(R(a,1,g));!t(x);)u=s(x),e(u,y(F(Fa[u]),n),1);for(x=F(R(a,4,g));!t(x);)u=s(x),e(u,y(B(gb(I(u),l),hb(I(u),l)),n),4);for(x=F(R(a,2,g));!t(x);)u=s(x),e(u,y(gb(I(u),l),n),2);for(x=F(R(a,3,g));!t(x);)u=s(x),e(u,y(hb(I(u),l),n),3);l=ia(R(a,k,g));e(l,y(F(Ga[l]), |
|
||||
n),k);b||(ib(a,g,!0)&&f.push(new Ka(l,l+2,2,k,null)),ib(a,g,!1)&&f.push(new Ka(l,l-2,3,k,null)));return f}function lb(a,b,c,d,e){var f=B(I(d),I(e));la(a.a[b],f);la(a.a[S+c],f);a.f[d]=null;a.f[e]=b;L(a.b,2+b+6*c+12*d);L(a.b,2+b+6*c+12*e)}function mb(a,b,c,d,e){ka(a.a[b],e);w(a.a[c],e);a.f[e]=c;L(a.b,2+b+6*d+12*e);L(a.b,2+c+6*d+12*e)} |
|
||||
function nb(a,b){if(P(b)&4){var c=b.a>>>19&7,d=a.c^1,e=Xa(b);ka(a.a[c],e);ka(a.a[S+d],e);a.f[e]=null;L(a.b,2+c+6*d+12*e)}Va(b)&&(c=a.c,d=2===P(b),e=T[c+(d?0:2)],lb(a,3,c,e,e+(d?-2:3)));lb(a,Q(b),a.c,O(b),b.a&63);P(b)&8&&mb(a,h,Wa(b),a.c,b.a&63)}function ob(a,b){P(b)&8&&mb(a,Wa(b),h,a.c,b.a&63);lb(a,Q(b),a.c,b.a&63,O(b));if(Va(b)){var c=a.c,d=2===P(b),e=T[c+(d?0:2)];lb(a,3,c,e+(d?-2:3),e)}P(b)&4&&(c=b.a>>>19&7,d=a.c^1,e=Xa(b),w(a.a[c],e),w(a.a[S+d],e),a.f[e]=c,L(a.b,2+c+6*d+12*e))} |
|
||||
ab.prototype.k=function(a){nb(this,a);var b=W(this);ob(this,a);return!b};function Z(a,b){a.j.push(new Ha(a.b.b,a.b.a));nb(a,b);if(W(a))return ob(a,b),a.j.pop(),!1;a.g.push(b);a.i.push(a.d);a.i.push(a.e);a.i.push(a.h);N(a.b,a.d);a.d=1===P(b)?b.a&63:-1;N(a.b,a.d);var c=a.c;Q(b)===k?(Y(a,c,!0),Y(a,c,!1)):3===Q(b)&&(O(b)===T[c+0]?Y(a,c,!0):O(b)===T[c+2]&&Y(a,c,!1));c^=1;3===(b.a>>>19&7)&&(Xa(b)===T[c+0]?Y(a,c,!0):Xa(b)===T[c+2]&&Y(a,c,!1));P(b)&4||Q(b)===h?a.h=0:++a.h;a.c=c;L(a.b,0);return!0} |
|
||||
function pb(a){if(a.g.length){var b=a.g.pop();a.c^=1;L(a.b,0);ob(a,b);a.i.pop();L(a.b,1538+a.e);a.e=a.i.pop();L(a.b,1538+a.e);N(a.b,a.d);a.d=a.i.pop();N(a.b,a.d);a.j.pop()}};var qb=[100,300,300,500,900,2E4],rb=[[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, |
|
||||
|
(function(){'use strict';var h=0,k=5,n=0,aa="pawn knight bishop rook queen king".split(" ");function ba(a,b){return"abcdefgh"[b]+"12345678"[a]}function ca(a){return"abcdefgh".indexOf(a[0])+8*"12345678".indexOf(a[1])}function q(a){return ba(a>>>3,a&7)};function da(a,b){this.a=a>>>0;this.b=b>>>0}function ea(a){a>>>=0;a-=a>>>1&1431655765;a=(a&858993459)+(a>>>2&858993459);return 16843009*(a+(a>>>4)&252645135)>>>24}function fa(a){a>>>=0;return(a&a-1)>>>0}function ha(a){a>>>=0;return ea((a&-a)-1)}function ia(a){return ea(a.a)+ea(a.b)}function ja(a){return a.a?ha(a.a):32+ha(a.b)}function r(a){var b=ja(a);a.a?a.a=fa(a.a):a.b=fa(a.b);return b}function s(a){return!a.a&&!a.b}function v(a,b){b>>>=0;return 32>b?!(a.a&1<<b):!(a.b&1<<b-32)} |
||||
|
function w(a,b){b>>>=0;32>b?a.a=(a.a|1<<b)>>>0:a.b=(a.b|1<<b-32)>>>0;return a}function ka(a,b){b>>>=0;32>b?a.a=(a.a&~(1<<b))>>>0:a.b=(a.b&~(1<<b-32))>>>0}function x(a,b){a.a=(a.a&b.a)>>>0;a.b=(a.b&b.b)>>>0;return a}function y(a,b){a.a=(a.a&~b.a)>>>0;a.b=(a.b&~b.b)>>>0;return a}function z(a,b){a.a=(a.a|b.a)>>>0;a.b=(a.b|b.b)>>>0;return a}function la(a,b){a.a=(a.a^b.a)>>>0;a.b=(a.b^b.b)>>>0}function ma(a){a.a=~a.a>>>0;a.b=~a.b>>>0;return a} |
||||
|
function A(a,b){b>>>=0;31<b?(a.b=a.a<<b-32>>>0,a.a=0):0<b&&(a.b=(a.b<<b|a.a>>>32-b)>>>0,a.a=a.a<<b>>>0);return a}function B(a,b){b>>>=0;31<b?(a.a=a.b>>>b-32,a.b=0):0<b&&(a.a=(a.a>>>b|a.b<<32-b)>>>0,a.b>>>=b);return a}function C(a,b){63<b||-63>b?a.a=a.b=0:0<b?A(a,b):0>b&&B(a,-b);return a}function na(a,b){return a.a===b.a&&a.b===b.b}function D(a){return F(a.a,a.b)}function F(a,b){return new da(a,b)}function G(a){return w(F(0,0),a)} |
||||
|
function oa(){var a=pa;return C(x(F(270549120,16909320),C(F(4294967295,4294967295),8*a)),a)}function qa(){var a=ra;return C(x(F(134480385,2151686160),C(F(4294967295,4294967295),8*-a)),a)}function sa(){var a=w(F(0,0),ta),b=y(B(D(a),1),H[7]),d=y(y(B(D(a),2),H[7]),H[6]),c=y(A(D(a),1),H[0]),a=y(y(A(D(a),2),H[0]),H[1]),d=z(d,a),b=z(b,c);return z(z(z(A(D(d),8),B(d,8)),A(D(b),16)),B(b,16))} |
||||
|
function ua(){var a=w(F(0,0),va),b=z(y(B(D(a),1),H[7]),y(A(D(a),1),H[0])),d=B(z(D(a),b),8),a=A(z(D(a),b),8);return z(z(b,d),a)}for(var wa=F(4294967295,4294967295),xa=F(1437226410,1437226410),ya=F(2857740885,2857740885),za=[],Aa=0;8>Aa;++Aa)za.push(A(F(16843009,16843009),Aa));for(var H=za,J=[],Ba=0;8>Ba;++Ba)J.push(A(F(255,0),8*Ba));for(var Ca=[],pa=-7;8>pa;++pa)Ca.push(oa());for(var Da=[],ra=-7;8>ra;++ra)Da.push(qa());for(var Ea=[],ta=0;64>ta;++ta)Ea.push(sa());for(var Fa=[],va=0;64>va;++va)Fa.push(ua());function Ga(a,b){this.b=a>>>0;this.a=b>>>0}for(var Ha=[],Ia=0;1586>Ia;++Ia)Ha.push(1+4294967295*Math.random()>>>0);function L(a,b){a.b=(a.b^Ha[b])>>>0;a.a=(a.a^Ha[b+1])>>>0}function M(a,b){0<=b&&L(a,1570+(b&7))};function Ja(a,b,d,c,e){this.a=b&63|(a&63)<<6|(d&15)<<12|(c&7)<<16|((e|0)&7)<<19}var Ka=0,La=4,Ma=8,Na=9,Oa=10,Pa=11,Qa=12,Ra=13,Sa=14,Ta=15;function N(a){return a.a>>>6&63}function O(a){return a.a>>>12&15}function P(a){return a.a>>>16&7}function Wa(a){return 2===O(a)||3===O(a)}function Xa(a){return O(a)&8?1+(O(a)&3):h}function Ya(a){return 5!==O(a)?a.a&63:(a.a&63)+(N(a)<(a.a&63)?-8:8)};function Za(){this.b=new Ga(0,0);this.a=[z(D(J[1]),J[6]),z(z(z(G(1),G(6)),G(57)),G(62)),z(z(z(G(2),G(5)),G(58)),G(61)),z(z(z(G(0),G(7)),G(56)),G(63)),z(G(3),G(59)),z(G(4),G(60)),z(D(J[0]),J[1]),z(D(J[6]),J[7])];this.f=[];this.c=n;this.e=15;this.d=-1;this.h=0;this.g=[];this.i=[];for(var a=this.f.length=0;64>a;++a){var b;a:{for(b=h;b<=k;++b)if(!v(this.a[b],a))break a;b=null}this.f.push(b)}this.b=new Ga(0,0);this.c&&L(this.b,0);for(a=n;1>=a;++a)for(b=h;b<=k;++b)for(var d=this.b,c=b,e=a,f=Q(this,b,a), |
||||
|
f=D(f);!s(f);){var g=r(f);L(d,2+c+6*e+12*g)}L(this.b,1538+this.e);M(this.b,this.d);this.j=[]}var R=k+1,$a=R+1,S=[7,63,0,56],ab=[ma(A(F(16843009,16843009),7)),wa,ma(A(F(16843009,16843009),0))];function T(a,b,d){d=bb(a,!!d);return b?d:d.filter(Za.prototype.k,a)}function Q(a,b,d){return x(D(a.a[b]),a.a[R+d])}function cb(a){return z(D(a.a[R]),a.a[$a])}function U(a){return db(a,a.c^1,ja(Q(a,k,a.c)))}function V(a,b,d,c){var e=F(0,0);d=8*d+c;c=ab[1+c];for(C(a,d);!s(x(a,c));C(y(a,b),d))z(e,a);return e} |
||||
|
function eb(a,b){return z(z(z(V(D(a),b,1,1),V(D(a),b,1,-1)),V(D(a),b,-1,1)),V(D(a),b,-1,-1))}function fb(a,b){return z(z(z(V(D(a),b,0,1),V(D(a),b,0,-1)),V(D(a),b,1,0)),V(D(a),b,-1,0))} |
||||
|
function db(a,b,d){var c,e=Q(a,h,b),f=b===n;c=C(y(D(e),H[0]),f?7:-9);e=C(y(D(e),H[7]),f?9:-7);c=z(c,e);if(!v(c,d))return!0;c=Q(a,1,b);if(!s(x(D(Ea[d]),c)))return!0;c=Q(a,k,b);if(!s(x(D(Fa[d]),c)))return!0;c=cb(a);e=Q(a,4,b);f=z(D(Q(a,2,b)),e);f=eb(f,c);if(!v(f,d))return!0;a=z(D(Q(a,3,b)),e);a=fb(a,c);return v(a,d)?!1:!0}function W(a,b,d){L(a.b,1538+a.e);a.e&=~(1<<b+(d?0:2));L(a.b,1538+a.e)} |
||||
|
function gb(a,b,d){if(0===(a.e&1<<b+(d?0:2)))return!1;var c=d?1:-1,e=b===n?4:60,f=cb(a);(c=!v(f,e+c)||!v(f,e+2*c)||!d&&!v(f,e+3*c))||(c=b^1,d=d?1:-1,b=b===n?4:60,c=!(!db(a,c,b)&&!db(a,c,b+d)&&!db(a,c,b+2*d)));return c?!1:!0}function hb(a){var b=a.b;return 3<=a.j.reduce(function(a,c){return a+(c.b===b.b&&c.a===b.a?1:0)},0)} |
||||
|
function ib(a){if(!s(a.a[h])||!s(a.a[3])||!s(a.a[4]))return!1;if(4>ia(a.a[R+n])+ia(a.a[R+1]))return!0;if(!s(a.a[1]))return!1;a=a.a[2];return na(x(D(a),xa),a)||na(x(D(a),ya),a)?!0:!1} |
||||
|
function bb(a,b){function d(a,b,d){for(;!s(a);){var c=r(a);f.push(new Ja(c-b,c,d,h,I.f[c]))}}function c(a,b,c){d(D(a),b,c?Ta:Pa);d(D(a),b,c?Sa:Oa);d(D(a),b,c?Ra:Na);d(D(a),b,c?Qa:Ma)}function e(a,b,c){for(;!s(b);){var d=r(b);v(ub,d)&&f.push(new Ja(a,d,v(p,d)?Ka:La,c,I.f[d]))}}var f=[],g=a.c,p=a.a[R+(g^1)],l=cb(a),I=a,m=1-2*g,E=8*m,u=Q(a,h,g),t=J[g?0:7];if(!b){var K=y(y(C(x(D(u),J[g?6:1]),2*E),l),C(D(l),E));d(K,2*E,1);K=y(C(D(u),E),l);d(y(D(K),t),E,Ka);c(x(D(K),t),E,!1)}var Ua=H[g?7:0],K=E-m,Y=x(C(y(D(u), |
||||
|
Ua),K),p);d(y(D(Y),t),K,La);c(x(D(Y),t),K,!0);var Y=H[g?0:7],E=E+m,Va=x(C(y(D(u),Y),E),p);d(y(D(Va),t),E,La);c(x(D(Va),t),E,!0);0<=a.d&&(t=C(y(x(G(a.d+m),u),Ua),K),d(t,K,5),m=C(y(x(G(a.d-m),u),Y),E),d(m,E,5));for(var ub=a.a[R+g],m=b?p:wa,u=D(Q(a,1,g));!s(u);)t=r(u),e(t,x(D(Ea[t]),m),1);for(u=D(Q(a,4,g));!s(u);)t=r(u),e(t,x(z(eb(G(t),l),fb(G(t),l)),m),4);for(u=D(Q(a,2,g));!s(u);)t=r(u),e(t,x(eb(G(t),l),m),2);for(u=D(Q(a,3,g));!s(u);)t=r(u),e(t,x(fb(G(t),l),m),3);l=ja(Q(a,k,g));e(l,x(D(Fa[l]),m),k); |
||||
|
b||(gb(a,g,!0)&&f.push(new Ja(l,l+2,2,k,null)),gb(a,g,!1)&&f.push(new Ja(l,l-2,3,k,null)));return f}function jb(a,b,d,c,e){var f=z(G(c),G(e));la(a.a[b],f);la(a.a[R+d],f);a.f[c]=null;a.f[e]=b;L(a.b,2+b+6*d+12*c);L(a.b,2+b+6*d+12*e)}function kb(a,b,d,c,e){ka(a.a[b],e);w(a.a[d],e);a.f[e]=d;L(a.b,2+b+6*c+12*e);L(a.b,2+d+6*c+12*e)} |
||||
|
function lb(a,b){if(O(b)&4){var d=b.a>>>19&7,c=a.c^1,e=Ya(b);ka(a.a[d],e);ka(a.a[R+c],e);a.f[e]=null;L(a.b,2+d+6*c+12*e)}Wa(b)&&(d=a.c,c=2===O(b),e=S[d+(c?0:2)],jb(a,3,d,e,e+(c?-2:3)));jb(a,P(b),a.c,N(b),b.a&63);O(b)&8&&kb(a,h,Xa(b),a.c,b.a&63)}function mb(a,b){O(b)&8&&kb(a,Xa(b),h,a.c,b.a&63);jb(a,P(b),a.c,b.a&63,N(b));if(Wa(b)){var d=a.c,c=2===O(b),e=S[d+(c?0:2)];jb(a,3,d,e+(c?-2:3),e)}O(b)&4&&(d=b.a>>>19&7,c=a.c^1,e=Ya(b),w(a.a[d],e),w(a.a[R+c],e),a.f[e]=d,L(a.b,2+d+6*c+12*e))} |
||||
|
Za.prototype.k=function(a){lb(this,a);var b=U(this);mb(this,a);return!b};function X(a,b){a.j.push(new Ga(a.b.b,a.b.a));lb(a,b);if(U(a))return mb(a,b),a.j.pop(),!1;a.g.push(b);a.i.push(a.d);a.i.push(a.e);a.i.push(a.h);M(a.b,a.d);a.d=1===O(b)?b.a&63:-1;M(a.b,a.d);var d=a.c;P(b)===k?(W(a,d,!0),W(a,d,!1)):3===P(b)&&(N(b)===S[d+0]?W(a,d,!0):N(b)===S[d+2]&&W(a,d,!1));d^=1;3===(b.a>>>19&7)&&(Ya(b)===S[d+0]?W(a,d,!0):Ya(b)===S[d+2]&&W(a,d,!1));O(b)&4||P(b)===h?a.h=0:++a.h;a.c=d;L(a.b,0);return!0} |
||||
|
function Z(a){if(a.g.length){var b=a.g.pop();a.c^=1;L(a.b,0);mb(a,b);a.i.pop();L(a.b,1538+a.e);a.e=a.i.pop();L(a.b,1538+a.e);M(a.b,a.d);a.d=a.i.pop();M(a.b,a.d);a.j.pop()}};var nb=[100,300,300,500,900,2E4],ob=[[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, |
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]],sb=qb[h]/2;function tb(a,b){for(var c=0,d=h;d<k;++d)c+=r(R(a,d,b))*qb[d];1<r(R(a,2,b))&&(c+=sb);return c}function ub(a,b){for(var c=0,d=h;d<=k;++d)for(var e=F(R(a,d,b));!t(e);)var f=s(e),c=c+rb[d][b?f:56^f];return c} |
|
||||
function vb(a,b){var c=a.a[S+b],d=a.a[S+(b^1)],e=V(a),f=na(V(a)),g;g=0;var m,l=R(a,h,b),z=b===p;m=y(E(F(l),z?8:-8),f);f=y(y(E(y(F(l),K[z?1:6]),z?16:-16),f),E(F(f),z?8:-8));m=B(m,f);g=g+r(m);g+=r(y(fb(b,R(a,h,b)),d));for(d=F(R(a,1,b));!t(d);)g+=r(A(F(Fa[s(d)]),c));g+=r(A(F(Ga[ia(R(a,k,b))]),c));d=R(a,4,b);m=B(F(R(a,2,b)),d);g+=r(A(gb(m,e),c));d=B(F(R(a,3,b)),d);g+=r(A(hb(d,e),c));return g*qb[h]/100} |
|
||||
function wb(a){function b(a){function b(a){var c=P(a)&4?(1+(a.a>>>19&7))/(1+Q(a)):0,c=6*c+Q(a),c=16*c+P(a),c=64*c+(a.a&63);return c=64*c+O(a)}a.sort(function(a,c){return b(c)-b(a)});return a}function c(a,d,g){if(100<=a.h||jb(a)||kb(a))return 0;var f=tb(a,p)-tb(a,1)+(ub(a,p)-ub(a,1));++e;var m=a.c===p;if(m){if(f>=g)return g;d=f>d?f:d}else{if(f<=d)return d;g=f<g?f:g}for(var f=b(U(a,!0,!W(a))),l=0;l<f.length;++l)if(Z(a,f[l])){var n=c(a,d,g);pb(a);if(m){if(n>=g)return g;d=n>d?n:d}else{if(n<=d)return d; |
|
||||
g=n<g?n:g}}return m?d:g}function d(a,g,e,f){if(1>g)return c(a,e,f);for(var m=b(U(a,!0,!1)),l=a.c===p,n=!1,z=0;z<m.length;++z)if(Z(a,m[z])){var n=!0,ma=d(a,g-1,e,f);pb(a);l?e=ma>e?ma:e:f=ma<f?ma:f;if(f<=e)break}if(!n){if(!W(a))return 0;a=qb[k];return l?-a:a}return 100<=a.h||jb(a)||kb(a)?0:l?e:f}for(var e=0,f=null,g=-Infinity,m=Infinity,l=b(U(a,!0)),z=0;z<l.length;++z)if(Z(a,l[z])){var n=d(a,3,g,m);pb(a);a.c===p?n>g&&(g=n,f=l[z]):n<m&&(m=n,f=l[z])}window.console.log("Evaluations: "+e+", result move: "+ |
|
||||
Ya(f)+", alpha: "+g+", beta: "+m);return f};function xb(){this.a=new ab} |
|
||||
function zb(){var a=$("<table>"),b="<tr><th></th>"+"abcdefgh".split("").map(function(a){return'<th class="file">'+a+"</th>"}).join("")+"<th></th></tr>";a.append(b);for(var c=0;8>c;++c){var d=7-c,e=$("<tr>");a.append(e);var f='<th class="rank">'+(8-c)+"</th>";e.append(f);for(var g=0;8>g;++g){var m=$("<td>"),l=(d+g)%2?"light":"dark";m.attr("id",ca(d,g));m.attr("title","Algebraic: "+ca(d,g)+"\nRank: "+d+"\nFile: "+g+"\nIndex: "+(g+8*d)+"\nColor: "+l);m.addClass(l);e.append(m)}e.append(f)}a.append(b);$("#chessboard").append(a)} |
|
||||
function Ab(){$("#chessboard table tr td, #chessboard table tr td div").removeClass("from to positional capture double-push en-passant promotion castle king-castle queen-castle")}function Bb(){$("#chessboard table tr td div.ui-draggable").draggable("destroy");$("#chessboard table tr td.ui-droppable").droppable("destroy")} |
|
||||
function Cb(a){var b=U(a.a);$("#moves").html('<a href="#" id="undo" class="'+(a.a.g.length?"can":"cannot")+'">undo</a><br/><a href="#" id="auto" class="'+(0<b.length?"can":"cannot")+'">auto</a><br/>'+b.map(function(a,b){return'<a href="#" id="'+b+'">'+Ya(a)+"</a><br/>"}).join(""));$("#chessboard table tr td, #chessboard table tr td div").removeClass("can-move");b.forEach(function(a){a=$("#"+q(O(a)));a.add(a.children()).addClass("can-move")});var c=!1;$("#chessboard table tr td div.can-move").mouseenter(function(){if(!c){var d= |
|
||||
$(this),e=d.parent(),f=da(""+e.attr("id")),e=e.add(d);e.toggleClass("from",b.some(function(a){return O(a)===f}));e.hasClass("from")&&(b.forEach(function(a){if(O(a)===f){var b=$("#"+q(a.a&63)),b=b.add(b.children());b.addClass("to");b.addClass(P(a)===La?"positional":"");b.addClass(P(a)&4?"capture":"");b.addClass(1===P(a)?"double-push":"");b.addClass(5===P(a)?"en-passant":"");b.addClass(P(a)&8?"promotion":"");b.addClass(Va(a)?"castle":"");b.addClass(2===P(a)?"king-castle":"");b.addClass(3===P(a)?"queen-castle": |
|
||||
"")}}),Bb(),$("#chessboard table tr td.to").droppable({drop:function(){var c=da(""+$(this).attr("id")),d=b.filter(function(a){return O(a)===f&&(a.a&63)===c});0<d.length?(Z(a.a,d[0]),Db(a)):(Ab(),Bb())}}),d.draggable({start:function(){c=!0},stop:function(){c=!1},containment:"#chessboard table",zIndex:10,revert:"invalid"}))}}).mouseleave(function(){c||Ab()});$("#moves a").click(function(){var c=$(this).attr("id");"undo"===c?(pb(a.a),pb(a.a),Db(a)):"auto"===c?Eb(a):(Z(a.a,b[parseInt(c,10)]),Db(a))})} |
|
||||
function Eb(a){$("#moves").html("");var b=$("#dim");b.fadeIn(function(){var c=wb(a.a);if(!c)throw Error("Move not found");Z(a.a,c);var d=$("#"+q(O(c))),c=$("#"+q(c.a&63)),e=c.offset().left-d.offset().left,f=c.offset().top-d.offset().top,g=d.children("div");g.css({position:"relative",top:"0px",left:"0px"});b.fadeOut(function(){g.animate({top:f+"px",left:e+"px"},function(){Db(a)})})})} |
|
||||
function Db(a){window.console.log("Moves: "+a.a.g.length+", white material: "+tb(a.a,p)+", black material: "+tb(a.a,1)+", white mobility: "+vb(a.a,p)+", black mobility: "+vb(a.a,1)+", white location: "+ub(a.a,p)+", black location: "+ub(a.a,1));Ab();Bb();$("#chessboard table tr td div").remove();$("#chessboard table tr td").removeClass("white black turn last-move "+ba.join(" "));for(var b=a.a.a[S+p],c=a.a.a[S+1],d=0;64>d;++d)for(var e=$("#"+q(d)),f=h;f<=k;++f)if(!v(a.a.a[f],d)){var g=a.a.c===p?!v(b, |
|
||||
d):!v(c,d),m=$("<div>");m.attr("title",e.attr("title")+"\nPiece: "+ba[f]+"\nColor: "+(v(b,d)?"black":"white"));m.text("\u2659\u265f\u2658\u265e\u2657\u265d\u2656\u265c\u2655\u265b\u2654\u265a".charAt(2*f+(v(b,d)?1:p)));var l=m.add(e);l.addClass(ba[f]);l.toggleClass("white",!v(b,d));l.toggleClass("black",!v(c,d));l.toggleClass("turn",g);e.append(m);break}b=a.a.g.length?a.a.g[a.a.g.length-1]:null;null!==b&&($("#"+q(O(b))).addClass("last-move"),$("#"+q(b.a&63)).addClass("last-move"));b=U(a.a).length? |
|
||||
100<=a.a.h?3:jb(a.a)?4:kb(a.a)?5:0:W(a.a)?1:2;0===b&&1===a.a.c?Eb(a):(Cb(a),$("#dim").css({display:"none"}),1===b?$("#moves").append("#<br/>"+(a.a.c?"1-0":"0-1")):0!==b&&$("#moves").append("½-½"))};window.makeChessGame=function(){zb();Db(new xb)};})(); |
|
||||
|
-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]],pb=nb[h]/2;function qb(a,b){for(var d=0,c=h;c<k;++c)d+=ia(Q(a,c,b))*nb[c];1<ia(Q(a,2,b))&&(d+=pb);return d}function rb(a,b){for(var d=0,c=h;c<=k;++c)for(var e=D(Q(a,c,b));!s(e);)var f=r(e),d=d+ob[c][b?f:56^f];return d} |
||||
|
function sb(a){function b(a){function b(a){var c=O(a)&4?(1+(a.a>>>19&7))/(1+P(a)):0,c=6*c+P(a),c=16*c+O(a),c=64*c+(a.a&63);return c=64*c+N(a)}a.sort(function(a,c){return b(c)-b(a)});return a}function d(a,c,g){if(100<=a.h||hb(a)||ib(a))return 0;var f=qb(a,n)-qb(a,1)+(rb(a,n)-rb(a,1));++e;var p=a.c===n;if(p){if(f>=g)return g;c=f>c?f:c}else{if(f<=c)return c;g=f<g?f:g}for(var f=b(T(a,!0,!U(a))),l=0;l<f.length;++l)if(X(a,f[l])){var m=d(a,c,g);Z(a);if(p){if(m>=g)return g;c=m>c?m:c}else{if(m<=c)return c; |
||||
|
g=m<g?m:g}}return p?c:g}function c(a,e,g,f){if(1>e)return d(a,g,f);for(var p=b(T(a,!0,!1)),l=a.c===n,m=!1,I=0;I<p.length;++I)if(X(a,p[I])){var m=!0,ga=c(a,e-1,g,f);Z(a);l?g=ga>g?ga:g:f=ga<f?ga:f;if(f<=g)break}if(!m){if(!U(a))return 0;a=nb[k];return l?-a:a}return 100<=a.h||hb(a)||ib(a)?0:l?g:f}for(var e=0,f=null,g=-Infinity,p=Infinity,l=b(T(a,!0)),I=0;I<l.length;++I)if(X(a,l[I])){var m=c(a,3,g,p);Z(a);a.c===n?m>g&&(g=m,f=l[I]):m<p&&(p=m,f=l[I])}return f};function tb(){this.a=new Za} |
||||
|
function vb(){var a=$("<table>"),b="<tr><th></th>"+"abcdefgh".split("").map(function(a){return'<th class="file">'+a+"</th>"}).join("")+"<th></th></tr>";a.append(b);for(var d=0;8>d;++d){var c=7-d,e=$("<tr>");a.append(e);var f='<th class="rank">'+(8-d)+"</th>";e.append(f);for(var g=0;8>g;++g){var p=$("<td>"),l=(c+g)%2?"light":"dark";p.attr("id",ba(c,g));p.attr("title","Algebraic: "+ba(c,g)+"\nRank: "+c+"\nFile: "+g+"\nIndex: "+(g+8*c)+"\nColor: "+l);p.addClass(l);e.append(p)}e.append(f)}a.append(b);$("#chessboard").append(a)} |
||||
|
function wb(){$("#chessboard table tr td, #chessboard table tr td div").removeClass("from to positional capture double-push en-passant promotion castle king-castle queen-castle")}function xb(){$("#chessboard table tr td div.ui-draggable").draggable("destroy");$("#chessboard table tr td.ui-droppable").droppable("destroy")} |
||||
|
function yb(a){var b=T(a.a);$("#moves").html('<a href="#" id="undo" class="'+(a.a.g.length?"can":"cannot")+'">undo</a><br/><a href="#" id="auto" class="'+(0<b.length?"can":"cannot")+'">auto</a><br/>'+b.map(function(a,b){return'<a href="#" id="'+b+'">'+(Wa(a)?"0-0"+(3===O(a)?"-0":""):" NBRQK".charAt(P(a))+q(N(a))+(O(a)&4?"x":"-")+q(a.a&63)+(5===O(a)?"e.p.":"")+(O(a)&8?" NBRQK".charAt(Xa(a)):""))+"</a><br/>"}).join(""));$("#chessboard table tr td, #chessboard table tr td div").removeClass("can-move"); |
||||
|
b.forEach(function(a){a=$("#"+q(N(a)));a.add(a.children()).addClass("can-move")});var d=!1;$("#chessboard table tr td div.can-move").mouseenter(function(){if(!d){var c=$(this),e=c.parent(),f=ca(""+e.attr("id")),e=e.add(c);e.toggleClass("from",b.some(function(a){return N(a)===f}));e.hasClass("from")&&(b.forEach(function(a){if(N(a)===f){var b=$("#"+q(a.a&63)),b=b.add(b.children());b.addClass("to");b.addClass(O(a)===Ka?"positional":"");b.addClass(O(a)&4?"capture":"");b.addClass(1===O(a)?"double-push": |
||||
|
"");b.addClass(5===O(a)?"en-passant":"");b.addClass(O(a)&8?"promotion":"");b.addClass(Wa(a)?"castle":"");b.addClass(2===O(a)?"king-castle":"");b.addClass(3===O(a)?"queen-castle":"")}}),xb(),$("#chessboard table tr td.to").droppable({drop:function(){var c=ca(""+$(this).attr("id")),d=b.filter(function(a){return N(a)===f&&(a.a&63)===c});0<d.length?(X(a.a,d[0]),zb(a)):(wb(),xb())}}),c.draggable({start:function(){d=!0},stop:function(){d=!1},containment:"#chessboard table",zIndex:10,revert:"invalid"}))}}).mouseleave(function(){d|| |
||||
|
wb()});$("#moves a").click(function(){var c=$(this).attr("id");"undo"===c?(Z(a.a),Z(a.a),zb(a)):"auto"===c?Ab(a):(X(a.a,b[parseInt(c,10)]),zb(a))})} |
||||
|
function Ab(a){$("#moves").html("");var b=$("#dim");b.fadeIn(function(){var d=sb(a.a);if(!d)throw Error("Move not found");X(a.a,d);var c=$("#"+q(N(d))),d=$("#"+q(d.a&63)),e=d.offset().left-c.offset().left,f=d.offset().top-c.offset().top,g=c.children("div");g.css({position:"relative",top:"0px",left:"0px"});b.fadeOut(function(){g.animate({top:f+"px",left:e+"px"},function(){zb(a)})})})} |
||||
|
function zb(a){wb();xb();$("#chessboard table tr td div").remove();$("#chessboard table tr td").removeClass("white black turn last-move "+aa.join(" "));for(var b=a.a.a[R+n],d=a.a.a[R+1],c=0;64>c;++c)for(var e=$("#"+q(c)),f=h;f<=k;++f)if(!v(a.a.a[f],c)){var g=a.a.c===n?!v(b,c):!v(d,c),p=$("<div>");p.attr("title",e.attr("title")+"\nPiece: "+aa[f]+"\nColor: "+(v(b,c)?"black":"white"));p.text("\u2659\u265f\u2658\u265e\u2657\u265d\u2656\u265c\u2655\u265b\u2654\u265a".charAt(2*f+(v(b,c)?1:n)));var l=p.add(e); |
||||
|
l.addClass(aa[f]);l.toggleClass("white",!v(b,c));l.toggleClass("black",!v(d,c));l.toggleClass("turn",g);e.append(p);break}b=a.a.g.length?a.a.g[a.a.g.length-1]:null;null!==b&&($("#"+q(N(b))).addClass("last-move"),$("#"+q(b.a&63)).addClass("last-move"));b=T(a.a).length?100<=a.a.h?3:hb(a.a)?4:ib(a.a)?5:0:U(a.a)?1:2;0===b&&1===a.a.c?Ab(a):(yb(a),$("#dim").css({display:"none"}),1===b?$("#moves").append("#<br/>"+(a.a.c?"1-0":"0-1")):0!==b&&$("#moves").append("½-½"))};window.makeChessGame=function(){vb();zb(new tb)};})(); |
||||
|
Loading…
Reference in new issue