"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function i(a,s,u){function c(t,e){if(!s[t]){if(!a[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=s[t]={exports:{}};a[t][0].call(o.exports,function(e){return c(a[t][1][e]||e)},o,o.exports,i,a,s,u)}return s[t].exports}for(var l="function"==typeof require&&require,e=0;e<u.length;e++)c(u[e]);return c}({1:[function(e,t,n){var r=function(e){var c="b",l="w",u=-1,y="p",w="n",E="b",k="r",P="q",f="k",r="pnbrqkPNBRQK",t="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",h=["1-0","0-1","1/2-1/2","*"],C={b:[16,32,17,15],w:[-16,-32,-17,-15]},S={n:[-18,-33,-31,-14,18,33,31,14],b:[-17,-15,17,15],r:[-16,1,16,-1],q:[-17,-16,-15,1,17,16,15,-1],k:[-17,-16,-15,1,17,16,15,-1]},p=[20,0,0,0,0,0,0,24,0,0,0,0,0,0,20,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,24,24,24,24,24,24,56,0,56,24,24,24,24,24,24,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,20,0,0,0,0,0,0,24,0,0,0,0,0,0,20],d=[17,0,0,0,0,0,0,16,0,0,0,0,0,0,15,0,0,17,0,0,0,0,0,16,0,0,0,0,0,15,0,0,0,0,17,0,0,0,0,16,0,0,0,0,15,0,0,0,0,0,0,17,0,0,0,16,0,0,0,15,0,0,0,0,0,0,0,0,17,0,0,16,0,0,15,0,0,0,0,0,0,0,0,0,0,17,0,16,0,15,0,0,0,0,0,0,0,0,0,0,0,0,17,16,15,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,-15,-16,-17,0,0,0,0,0,0,0,0,0,0,0,0,-15,0,-16,0,-17,0,0,0,0,0,0,0,0,0,0,-15,0,0,-16,0,0,-17,0,0,0,0,0,0,0,0,-15,0,0,0,-16,0,0,0,-17,0,0,0,0,0,0,-15,0,0,0,0,-16,0,0,0,0,-17,0,0,0,0,-15,0,0,0,0,0,-16,0,0,0,0,0,-17,0,0,-15,0,0,0,0,0,0,-16,0,0,0,0,0,0,-17],v={p:0,n:1,b:2,r:3,q:4,k:5},o={NORMAL:"n",CAPTURE:"c",BIG_PAWN:"b",EP_CAPTURE:"e",PROMOTION:"p",KSIDE_CASTLE:"k",QSIDE_CASTLE:"q"},x={NORMAL:1,CAPTURE:2,BIG_PAWN:4,EP_CAPTURE:8,PROMOTION:16,KSIDE_CASTLE:32,QSIDE_CASTLE:64},_=7,A=6,T=1,O=0,N={a8:0,b8:1,c8:2,d8:3,e8:4,f8:5,g8:6,h8:7,a7:16,b7:17,c7:18,d7:19,e7:20,f7:21,g7:22,h7:23,a6:32,b6:33,c6:34,d6:35,e6:36,f6:37,g6:38,h6:39,a5:48,b5:49,c5:50,d5:51,e5:52,f5:53,g5:54,h5:55,a4:64,b4:65,c4:66,d4:67,e4:68,f4:69,g4:70,h4:71,a3:80,b3:81,c3:82,d3:83,e3:84,f3:85,g3:86,h3:87,a2:96,b2:97,c2:98,d2:99,e2:100,f2:101,g2:102,h2:103,a1:112,b1:113,c1:114,d1:115,e1:116,f1:117,g1:118,h1:119},g={w:[{square:N.a1,flag:x.QSIDE_CASTLE},{square:N.h1,flag:x.KSIDE_CASTLE}],b:[{square:N.a8,flag:x.QSIDE_CASTLE},{square:N.h8,flag:x.KSIDE_CASTLE}]},j=new Array(128),M={w:u,b:u},D=l,L={w:0,b:0},R=u,m=0,b=1,I=[],q={};function s(){j=new Array(128),M={w:u,b:u},D=l,L={w:0,b:0},R=u,m=0,b=1,I=[],q={},Q(B())}function K(){U(t)}function U(e){var t=e.split(/\s+/),n=t[0],r=0;if(!F(e).valid)return!1;s();for(var o=0;o<n.length;o++){var i=n.charAt(o);if("/"===i)r+=8;else if(-1!=="0123456789".indexOf(i))r+=parseInt(i,10);else{var a=i<"a"?l:c;z({type:i.toLowerCase(),color:a},ae(r)),r++}}return D=t[1],-1<t[2].indexOf("K")&&(L.w|=x.KSIDE_CASTLE),-1<t[2].indexOf("Q")&&(L.w|=x.QSIDE_CASTLE),-1<t[2].indexOf("k")&&(L.b|=x.KSIDE_CASTLE),-1<t[2].indexOf("q")&&(L.b|=x.QSIDE_CASTLE),R="-"===t[3]?u:N[t[3]],m=parseInt(t[4],10),b=parseInt(t[5],10),Q(B()),!0}function F(e){var t="No errors.",n="FEN string must contain six space-delimited fields.",r="6th field (move number) must be a positive integer.",o="5th field (half move counter) must be a non-negative integer.",i="4th field (en-passant square) is invalid.",a="3rd field (castling availability) is invalid.",s="2nd field (side to move) is invalid.",u="1st field (piece positions) does not contain 8 '/'-delimited rows.",c="1st field (piece positions) is invalid [consecutive numbers].",l="1st field (piece positions) is invalid [invalid piece].",f="1st field (piece positions) is invalid [row too large].",p="Illegal en-passant square",d=e.split(/\s+/);if(6!==d.length)return{valid:!1,error_number:1,error:n};if(isNaN(d[5])||parseInt(d[5],10)<=0)return{valid:!1,error_number:2,error:r};if(isNaN(d[4])||parseInt(d[4],10)<0)return{valid:!1,error_number:3,error:o};if(!/^(-|[abcdefgh][36])$/.test(d[3]))return{valid:!1,error_number:4,error:i};if(!/^(KQ?k?q?|Qk?q?|kq?|q|-)$/.test(d[2]))return{valid:!1,error_number:5,error:a};if(!/^(w|b)$/.test(d[1]))return{valid:!1,error_number:6,error:s};var h=d[0].split("/");if(8!==h.length)return{valid:!1,error_number:7,error:u};for(var v=0;v<h.length;v++){for(var g=0,m=!1,b=0;b<h[v].length;b++)if(isNaN(h[v][b])){if(!/^[prnbqkPRNBQK]$/.test(h[v][b]))return{valid:!1,error_number:9,error:l};g+=1,m=!1}else{if(m)return{valid:!1,error_number:8,error:c};g+=parseInt(h[v][b],10),m=!0}if(8!==g)return{valid:!1,error_number:10,error:f}}return"3"==d[3][1]&&"w"==d[1]||"6"==d[3][1]&&"b"==d[1]?{valid:!1,error_number:11,error:p}:{valid:!0,error_number:0,error:t}}function B(){for(var e=0,t="",n=N.a8;n<=N.h1;n++){if(null==j[n])e++;else{0<e&&(t+=e,e=0);var r=j[n].color,o=j[n].type;t+=r===l?o.toUpperCase():o.toLowerCase()}n+1&136&&(0<e&&(t+=e),n!==N.h1&&(t+="/"),e=0,n+=8)}var i="";L[l]&x.KSIDE_CASTLE&&(i+="K"),L[l]&x.QSIDE_CASTLE&&(i+="Q"),L[c]&x.KSIDE_CASTLE&&(i+="k"),L[c]&x.QSIDE_CASTLE&&(i+="q"),i=i||"-";var a=R===u?"-":ae(R);return[t,D,i,a,m,b].join(" ")}function $(e){for(var t=0;t<e.length;t+=2)"string"==typeof e[t]&&"string"==typeof e[t+1]&&(q[e[t]]=e[t+1]);return q}function Q(e){0<I.length||(e!==t?(q.SetUp="1",q.FEN=e):(delete q.SetUp,delete q.FEN))}function i(e){var t=j[N[e]];return t?{type:t.type,color:t.color}:null}function z(e,t){if(!("type"in e&&"color"in e))return!1;if(-1===r.indexOf(e.type.toLowerCase()))return!1;if(!(t in N))return!1;var n=N[t];return(e.type!=f||M[e.color]==u||M[e.color]==n)&&(j[n]={type:e.type,color:e.color},e.type===f&&(M[e.color]=n),Q(B()),!0)}function H(e,t,n,r,o){var i={color:D,from:t,to:n,flags:r,piece:e[t].type};return o&&(i.flags|=x.PROMOTION,i.promotion=o),e[n]?i.captured=e[n].type:r&x.EP_CAPTURE&&(i.captured=y),i}function W(e){function t(e,t,n,r,o){if(e[n].type!==y||oe(r)!==O&&oe(r)!==_)t.push(H(e,n,r,o));else for(var i=[P,k,E,w],a=0,s=i.length;a<s;a++)t.push(H(e,n,r,o,i[a]))}var n=[],r=D,o=se(r),i={b:T,w:A},a=N.a8,s=N.h1,u=!1,c=!(void 0!==e&&"legal"in e)||e.legal;if(void 0!==e&&"square"in e){if(!(e.square in N))return[];a=s=N[e.square],u=!0}for(var l=a;l<=s;l++)if(136&l)l+=7;else{var f=j[l];if(null!=f&&f.color===r)if(f.type===y){var p=l+C[r][0];if(null==j[p]){t(j,n,l,p,x.NORMAL);p=l+C[r][1];i[r]===oe(l)&&null==j[p]&&t(j,n,l,p,x.BIG_PAWN)}for(d=2;d<4;d++){136&(p=l+C[r][d])||(null!=j[p]&&j[p].color===o?t(j,n,l,p,x.CAPTURE):p===R&&t(j,n,l,R,x.EP_CAPTURE))}}else for(var d=0,h=S[f.type].length;d<h;d++){var v=S[f.type][d];for(p=l;!(136&(p+=v));){if(null!=j[p]){if(j[p].color===r)break;t(j,n,l,p,x.CAPTURE);break}if(t(j,n,l,p,x.NORMAL),"n"===f.type||"k"===f.type)break}}}if(!u||s===M[r]){if(L[r]&x.KSIDE_CASTLE){var g=(m=M[r])+2;null!=j[m+1]||null!=j[g]||X(o,M[r])||X(o,m+1)||X(o,g)||t(j,n,M[r],g,x.KSIDE_CASTLE)}if(L[r]&x.QSIDE_CASTLE){var m;g=(m=M[r])-2;null!=j[m-1]||null!=j[m-2]||null!=j[m-3]||X(o,M[r])||X(o,m-1)||X(o,g)||t(j,n,M[r],g,x.QSIDE_CASTLE)}}if(!c)return n;var b=[];for(l=0,h=n.length;l<h;l++)te(n[l]),G(r)||b.push(n[l]),ne();return b}function Z(e,t){var n="";if(e.flags&x.KSIDE_CASTLE)n="O-O";else if(e.flags&x.QSIDE_CASTLE)n="O-O-O";else{var r=function(e,t){for(var n=W({legal:!t}),r=e.from,o=e.to,i=e.piece,a=0,s=0,u=0,c=0,l=n.length;c<l;c++){var f=n[c].from,p=n[c].to,d=n[c].piece;i===d&&r!==f&&o===p&&(a++,oe(r)===oe(f)&&s++,ie(r)===ie(f)&&u++)}if(0<a)return 0<s&&0<u?ae(r):0<u?ae(r).charAt(1):ae(r).charAt(0);return""}(e,t);e.piece!==y&&(n+=e.piece.toUpperCase()+r),e.flags&(x.CAPTURE|x.EP_CAPTURE)&&(e.piece===y&&(n+=ae(e.from)[0]),n+="x"),n+=ae(e.to),e.flags&x.PROMOTION&&(n+="="+e.promotion.toUpperCase())}return te(e),a()&&(J()?n+="#":n+="+"),ne(),n}function V(e){return e.replace(/=/,"").replace(/[+#]?[?!]*$/,"")}function X(e,t){for(var n=N.a8;n<=N.h1;n++)if(136&n)n+=7;else if(null!=j[n]&&j[n].color===e){var r=j[n],o=n-t,i=o+119;if(p[i]&1<<v[r.type]){if(r.type===y){if(0<o){if(r.color===l)return!0}else if(r.color===c)return!0;continue}if("n"===r.type||"k"===r.type)return!0;for(var a=d[i],s=n+a,u=!1;s!==t;){if(null!=j[s]){u=!0;break}s+=a}if(!u)return!0}}return!1}function G(e){return X(se(e),M[e])}function a(){return G(D)}function J(){return a()&&0===W().length}function n(){return!a()&&0===W().length}function Y(){for(var e={},t=[],n=0,r=0,o=N.a8;o<=N.h1;o++)if(r=(r+1)%2,136&o)o+=7;else{var i=j[o];i&&(e[i.type]=i.type in e?e[i.type]+1:1,i.type===E&&t.push(r),n++)}if(2===n)return!0;if(3===n&&(1===e[E]||1===e[w]))return!0;if(n===e[E]+2){var a=0,s=t.length;for(o=0;o<s;o++)a+=t[o];if(0===a||a===s)return!0}return!1}function ee(){for(var e=[],t={},n=!1;;){var r=ne();if(!r)break;e.push(r)}for(;;){var o=B().split(" ").slice(0,4).join(" ");if(t[o]=o in t?t[o]+1:1,3<=t[o]&&(n=!0),!e.length)break;te(e.pop())}return n}function te(e){var t,n=D,r=se(n);if(t=e,I.push({move:t,kings:{b:M.b,w:M.w},turn:D,castling:{b:L.b,w:L.w},ep_square:R,half_moves:m,move_number:b}),j[e.to]=j[e.from],j[e.from]=null,e.flags&x.EP_CAPTURE&&(D===c?j[e.to-16]=null:j[e.to+16]=null),e.flags&x.PROMOTION&&(j[e.to]={type:e.promotion,color:n}),j[e.to].type===f){if(M[j[e.to].color]=e.to,e.flags&x.KSIDE_CASTLE){var o=e.to-1,i=e.to+1;j[o]=j[i],j[i]=null}else if(e.flags&x.QSIDE_CASTLE){o=e.to+1,i=e.to-2;j[o]=j[i],j[i]=null}L[n]=""}if(L[n])for(var a=0,s=g[n].length;a<s;a++)if(e.from===g[n][a].square&&L[n]&g[n][a].flag){L[n]^=g[n][a].flag;break}if(L[r])for(a=0,s=g[r].length;a<s;a++)if(e.to===g[r][a].square&&L[r]&g[r][a].flag){L[r]^=g[r][a].flag;break}R=e.flags&x.BIG_PAWN?"b"===D?e.to-16:e.to+16:u,e.piece===y?m=0:e.flags&(x.CAPTURE|x.EP_CAPTURE)?m=0:m++,D===c&&b++,D=se(D)}function ne(){var e=I.pop();if(null==e)return null;var t=e.move;M=e.kings,D=e.turn,L=e.castling,R=e.ep_square,m=e.half_moves,b=e.move_number;var n,r,o=D,i=se(D);if(j[t.from]=j[t.to],j[t.from].type=t.piece,j[t.to]=null,t.flags&x.CAPTURE)j[t.to]={type:t.captured,color:i};else if(t.flags&x.EP_CAPTURE){var a;a=o===c?t.to-16:t.to+16,j[a]={type:y,color:i}}t.flags&(x.KSIDE_CASTLE|x.QSIDE_CASTLE)&&(t.flags&x.KSIDE_CASTLE?(n=t.to+1,r=t.to-1):t.flags&x.QSIDE_CASTLE&&(n=t.to-2,r=t.to+1),j[n]=j[r],j[r]=null);return t}function re(e,t){var n=V(e);if(t){var r=n.match(/([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/);if(r)var o=r[1],i=r[2],a=r[3],s=r[4]}for(var u=W(),c=0,l=u.length;c<l;c++){if(n===V(Z(u[c]))||t&&n===V(Z(u[c],!0)))return u[c];if(r&&(!o||o.toLowerCase()==u[c].piece)&&N[i]==u[c].from&&N[a]==u[c].to&&(!s||s.toLowerCase()==u[c].promotion))return u[c]}return null}function oe(e){return e>>4}function ie(e){return 15&e}function ae(e){var t=ie(e),n=oe(e);return"abcdefgh".substring(t,t+1)+"87654321".substring(n,n+1)}function se(e){return e===l?c:l}function ue(e){var t=function e(t){var n=t instanceof Array?[]:{};for(var r in t)"object"===_typeof(r)?n[r]=e(t[r]):n[r]=t[r];return n}(e);t.san=Z(t,!1),t.to=ae(t.to),t.from=ae(t.from);var n="";for(var r in x)x[r]&t.flags&&(n+=o[r]);return t.flags=n,t}function ce(e){return e.replace(/^\s+|\s+$/g,"")}return U(void 0===e?t:e),{WHITE:l,BLACK:c,PAWN:y,KNIGHT:w,BISHOP:E,ROOK:k,QUEEN:P,KING:f,SQUARES:function(){for(var e=[],t=N.a8;t<=N.h1;t++)136&t?t+=7:e.push(ae(t));return e}(),FLAGS:o,load:function(e){return U(e)},reset:function(){return K()},moves:function(e){for(var t=W(e),n=[],r=0,o=t.length;r<o;r++)void 0!==e&&"verbose"in e&&e.verbose?n.push(ue(t[r])):n.push(Z(t[r],!1));return n},in_check:function(){return a()},in_checkmate:function(){return J()},in_stalemate:function(){return n()},in_draw:function(){return 100<=m||n()||Y()||ee()},insufficient_material:function(){return Y()},in_threefold_repetition:function(){return ee()},game_over:function(){return 100<=m||J()||n()||Y()||ee()},validate_fen:function(e){return F(e)},fen:function(){return B()},pgn:function(e){var t="object"===_typeof(e)&&"string"==typeof e.newline_char?e.newline_char:"\n",n="object"===_typeof(e)&&"number"==typeof e.max_width?e.max_width:0,r=[],o=!1;for(var i in q)r.push("["+i+' "'+q[i]+'"]'+t),o=!0;o&&I.length&&r.push(t);for(var a=[];0<I.length;)a.push(ne());for(var s=[],u="";0<a.length;){var c=a.pop();I.length||"b"!==c.color?"w"===c.color&&(u.length&&s.push(u),u=b+"."):u=b+". ...",u=u+" "+Z(c,!1),te(c)}if(u.length&&s.push(u),void 0!==q.Result&&s.push(q.Result),0===n)return r.join("")+s.join(" ");var l=0;for(i=0;i<s.length;i++)l+s[i].length>n&&0!==i?(" "===r[r.length-1]&&r.pop(),r.push(t),l=0):0!==i&&(r.push(" "),l++),r.push(s[i]),l+=s[i].length;return r.join("")},load_pgn:function(e,t){var n=void 0!==t&&"sloppy"in t&&t.sloppy;function u(e){return e.replace(/\\/g,"\\")}var r="object"===_typeof(t)&&"string"==typeof t.newline_char?t.newline_char:"\r?\n",o=new RegExp("^(\\[(.|"+u(r)+")*\\])("+u(r)+")*1.("+u(r)+"|.)*$","g"),i=e.replace(o,"$1");"["!==i[0]&&(i=""),K();var a=function(e,t){for(var n="object"===_typeof(t)&&"string"==typeof t.newline_char?t.newline_char:"\r?\n",r={},o=e.split(new RegExp(u(n))),i="",a="",s=0;s<o.length;s++)i=o[s].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/,"$1"),a=o[s].replace(/^\[[A-Za-z]+\s"(.*)"\]$/,"$1"),0<ce(i).length&&(r[i]=a);return r}(i,t);for(var s in a)$([s,a[s]]);if("1"===a.SetUp&&!("FEN"in a&&U(a.FEN)))return!1;var c=e.replace(i,"").replace(new RegExp(u(r),"g")," ");c=c.replace(/(\{[^}]+\})+?/g,"");for(var l=/(\([^\(\)]+\))+?/g;l.test(c);)c=c.replace(l,"");var f=ce(c=(c=(c=c.replace(/\d+\.(\.\.)?/g,"")).replace(/\.\.\./g,"")).replace(/\$\d+/g,"")).split(new RegExp(/\s+/));f=f.join(",").replace(/,,+/g,",").split(",");for(var p="",d=0;d<f.length-1;d++){if(null==(p=re(f[d],n)))return!1;te(p)}if(p=f[f.length-1],-1<h.indexOf(p))(function(e){for(var t in e)return!0;return!1})(q)&&void 0===q.Result&&$(["Result",p]);else{if(null==(p=re(p,n)))return!1;te(p)}return!0},header:function(){return $(arguments)},ascii:function(){return function(){for(var e="   +------------------------+\n",t=N.a8;t<=N.h1;t++){if(0===ie(t)&&(e+=" "+"87654321"[oe(t)]+" |"),null==j[t])e+=" . ";else{var n=j[t].type;e+=" "+(j[t].color===l?n.toUpperCase():n.toLowerCase())+" "}t+1&136&&(e+="|\n",t+=8)}return e+="   +------------------------+\n",e+="     a  b  c  d  e  f  g  h\n"}()},turn:function(){return D},move:function(e,t){var n=void 0!==t&&"sloppy"in t&&t.sloppy,r=null;if("string"==typeof e)r=re(e,n);else if("object"===_typeof(e))for(var o=W(),i=0,a=o.length;i<a;i++)if(!(e.from!==ae(o[i].from)||e.to!==ae(o[i].to)||"promotion"in o[i]&&e.promotion!==o[i].promotion)){r=o[i];break}if(!r)return null;var s=ue(r);return te(r),s},undo:function(){var e=ne();return e?ue(e):null},clear:function(){return s()},put:function(e,t){return z(e,t)},get:function(e){return i(e)},remove:function(e){return n=i(t=e),j[N[t]]=null,n&&n.type===f&&(M[n.color]=u),Q(B()),n;var t,n},perft:function(e){return function e(t){for(var n=W({legal:!1}),r=0,o=D,i=0,a=n.length;i<a;i++)te(n[i]),G(o)||(0<t-1?r+=e(t-1):r++),ne();return r}(e)},square_color:function(e){if(e in N){var t=N[e];return(oe(t)+ie(t))%2==0?"light":"dark"}return null},history:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(e){for(var t=[],n=[],r=(void 0!==e&&"verbose"in e&&e.verbose);0<I.length;)t.push(ne());for(;0<t.length;){var o=t.pop();r?n.push(ue(o)):n.push(Z(o)),te(o)}return n})}};void 0!==n&&(n.Chess=r),"undefined"!=typeof define&&define(function(){return r})},{}],2:[function(e,t,n){var a=this&&this.__assign||Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};Object.defineProperty(n,"__esModule",{value:!0});var v=e("./util");function r(e,t){var n=e(t);return t.dom.redraw(),n}function g(e,t){return{key:e,pos:v.key2pos(e),piece:t}}n.anim=function(e,t){return t.animation.enabled?function(e,t){var n=a({},t.pieces),r=e(t),o=function(e,t){var n,r,o,i,a={},s=[],u={},c=[],l=[],f={};for(o in e)f[o]=g(o,e[o]);for(var p=0,d=v.allKeys;p<d.length;p++){var h=d[p];n=t.pieces[h],r=f[h],n?r?v.samePiece(n,r.piece)||(c.push(r),l.push(g(h,n))):l.push(g(h,n)):r&&c.push(r)}return l.forEach(function(t){var n,e;n=t,e=c.filter(function(e){return v.samePiece(t.piece,e.piece)}),(r=e.sort(function(e,t){return v.distanceSq(n.pos,e.pos)-v.distanceSq(n.pos,t.pos)})[0])&&(i=[r.pos[0]-t.pos[0],r.pos[1]-t.pos[1]],a[t.key]=i.concat(i),s.push(r.key))}),c.forEach(function(e){v.containsX(s,e.key)||t.items&&t.items(e.pos,e.key)||(u[e.key]=e.piece)}),{anims:a,fadings:u}}(n,t);if(s(o.anims)&&s(o.fadings))t.dom.redraw();else{var i=t.animation.current&&t.animation.current.start;t.animation.current={start:c.now(),frequency:1/t.animation.duration,plan:o},i||function t(n,e){var r=n.animation.current;if(void 0!==r){var o,i=1-(e-r.start)*r.frequency;if(i<=0)n.animation.current=void 0,n.dom.redrawNow();else{var a=(o=i)<.5?4*o*o*o:(o-1)*(2*o-2)*(2*o-2)+1;for(var s in r.plan.anims){var u=r.plan.anims[s];u[2]=u[0]*a,u[3]=u[1]*a}n.dom.redrawNow(!0),v.raf(function(e){return void 0===e&&(e=c.now()),t(n,e)})}}else n.dom.destroyed||n.dom.redrawNow()}(t,c.now())}return r}(e,t):r(e,t)},n.render=r;var c=void 0!==window.performance?window.performance:Date;function s(e){for(var t in e)return!1;return!0}},{"./util":17}],3:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var o=e("./board"),i=e("./fen"),a=e("./config"),s=e("./anim"),u=e("./drag"),c=e("./explosion");n.start=function(r,e){function n(){o.toggleOrientation(r),e()}return{set:function(t){t.orientation&&t.orientation!==r.orientation&&n(),(t.fen?s.anim:s.render)(function(e){return a.configure(e,t)},r)},state:r,getFen:function(){return i.write(r.pieces)},toggleOrientation:n,setPieces:function(t){s.anim(function(e){return o.setPieces(e,t)},r)},selectSquare:function(t,n){t?s.anim(function(e){return o.selectSquare(e,t,n)},r):r.selected&&(o.unselect(r),r.dom.redraw())},move:function(t,n){s.anim(function(e){return o.baseMove(e,t,n)},r)},newPiece:function(t,n){s.anim(function(e){return o.baseNewPiece(e,t,n)},r)},playPremove:function(){if(r.premovable.current){if(s.anim(o.playPremove,r))return!0;r.dom.redraw()}return!1},playPredrop:function(e){if(r.predroppable.current){var t=o.playPredrop(r,e);return r.dom.redraw(),t}return!1},cancelPremove:function(){s.render(o.unsetPremove,r)},cancelPredrop:function(){s.render(o.unsetPredrop,r)},cancelMove:function(){s.render(function(e){o.cancelMove(e),u.cancel(e)},r)},stop:function(){s.render(function(e){o.stop(e),u.cancel(e)},r)},explode:function(e){c.default(r,e)},setAutoShapes:function(t){s.render(function(e){return e.drawable.autoShapes=t},r)},setShapes:function(t){s.render(function(e){return e.drawable.shapes=t},r)},getKeyAtDomPos:function(e){return o.getKeyAtDomPos(e,"white"===r.orientation,r.dom.bounds())},redrawAll:e,dragNewPiece:function(e,t,n){u.dragNewPiece(r,e,t,n)},destroy:function(){o.stop(r),r.dom.unbind&&r.dom.unbind(),r.dom.destroyed=!0}}}},{"./anim":2,"./board":4,"./config":6,"./drag":7,"./explosion":10,"./fen":11}],4:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var d=e("./util"),h=e("./premove");function g(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];e&&setTimeout(function(){return e.apply(void 0,t)},1)}function m(e){e.premovable.current&&(e.premovable.current=void 0,g(e.premovable.events.unset))}function b(e){var t=e.predroppable;t.current&&(t.current=void 0,g(t.events.unset))}function o(e,t,n){if(t===n||!e.pieces[t])return!1;var r=e.pieces[n]&&e.pieces[n].color!==e.pieces[t].color?e.pieces[n]:void 0;return n==e.selected&&E(e),g(e.events.move,t,n,r),function(e,t,n){if(!e.autoCastle)return!1;var r=e.pieces[t];if("king"!==r.role)return!1;var o=d.key2pos(t);if(5!==o[0])return!1;if(1!==o[1]&&8!==o[1])return!1;var i,a,s,u=d.key2pos(n);if(7===u[0]||8===u[0])i=d.pos2key([8,o[1]]),a=d.pos2key([6,o[1]]),s=d.pos2key([7,o[1]]);else{if(3!==u[0]&&1!==u[0])return!1;i=d.pos2key([1,o[1]]),a=d.pos2key([4,o[1]]),s=d.pos2key([3,o[1]])}var c=e.pieces[i];return"rook"===c.role&&(delete e.pieces[t],delete e.pieces[i],e.pieces[s]=r,e.pieces[a]=c,!0)}(e,t,n)||(e.pieces[n]=e.pieces[t],delete e.pieces[t]),e.lastMove=[t,n],e.check=void 0,g(e.events.change),r||!0}function y(e,t,n,r){if(e.pieces[n]){if(!r)return!1;delete e.pieces[n]}return g(e.events.dropNewPiece,t,n),e.pieces[n]=t,e.lastMove=[n],e.check=void 0,g(e.events.change),e.movable.dests=void 0,e.turnColor=d.opposite(e.turnColor),!0}function v(e,t,n){var r=o(e,t,n);return r&&(e.movable.dests=void 0,e.turnColor=d.opposite(e.turnColor),e.animation.current=void 0),r}function r(e,t,n){if(P(e,t,n)){var r=v(e,t,n);if(r){var o=e.hold.stop();E(e);var i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:o};return!0!==r&&(i.captured=r),g(e.movable.events.after,t,n,i),!0}}else l=e,(f=t)!==(p=n)&&C(l,f)&&d.containsX(h.default(l.pieces,f,l.premovable.castle),p)?(s=t,u=n,c={ctrlKey:(a=e).stats.ctrlKey},b(a),a.premovable.current=[s,u],g(a.premovable.events.set,s,u,c),E(e)):k(e,n)||C(e,n)?(w(e,n),e.hold.start()):E(e);var a,s,u,c,l,f,p;return!1}function w(e,t){e.selected=t,C(e,t)?e.premovable.dests=h.default(e.pieces,t,e.premovable.castle):e.premovable.dests=void 0}function E(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function k(e,t){var n=e.pieces[t];return n&&("both"===e.movable.color||e.movable.color===n.color&&e.turnColor===n.color)}function P(e,t,n){return t!==n&&k(e,t)&&(e.movable.free||!!e.movable.dests&&d.containsX(e.movable.dests[t],n))}function C(e,t){var n=e.pieces[t];return n&&e.premovable.enabled&&e.movable.color===n.color&&e.turnColor!==n.color}function i(e){m(e),b(e),E(e)}n.callUserFunction=g,n.toggleOrientation=function(e){e.orientation=d.opposite(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0},n.reset=function(e){e.lastMove=void 0,E(e),m(e),b(e)},n.setPieces=function(e,t){for(var n in t){var r=t[n];r?e.pieces[n]=r:delete e.pieces[n]}},n.setCheck=function(e,t){if(!0===t&&(t=e.turnColor),t)for(var n in e.pieces)"king"===e.pieces[n].role&&e.pieces[n].color===t&&(e.check=n);else e.check=void 0},n.unsetPremove=m,n.unsetPredrop=b,n.baseMove=o,n.baseNewPiece=y,n.userMove=r,n.dropNewPiece=function(e,t,n,r){if(d=t,h=n,(v=(p=e).pieces[d])&&h&&(d===h||!p.pieces[h])&&("both"===p.movable.color||p.movable.color===v.color&&p.turnColor===v.color)||r){var o=e.pieces[t];delete e.pieces[t],y(e,o,n,r),g(e.movable.events.afterNewPiece,o.role,n,{predrop:!1})}else c=t,l=n,(f=(u=e).pieces[c])&&l&&(!u.pieces[l]||u.pieces[l].color!==u.movable.color)&&u.predroppable.enabled&&("pawn"!==f.role||"1"!==l[1]&&"8"!==l[1])&&u.movable.color===f.color&&u.turnColor!==f.color?(a=(i=e).pieces[t].role,s=n,m(i),i.predroppable.current={role:a,key:s},g(i.predroppable.events.set,a,s)):(m(e),b(e));var i,a,s,u,c,l,f,p,d,h,v;delete e.pieces[t],E(e)},n.selectSquare=function(e,t,n){e.selected?e.selected!==t||e.draggable.enabled?(e.selectable.enabled||n)&&e.selected!==t?r(e,e.selected,t)&&(e.stats.dragged=!1):e.hold.start():(E(e),e.hold.cancel()):(k(e,t)||C(e,t))&&(w(e,t),e.hold.start()),g(e.events.select,t)},n.setSelected=w,n.unselect=E,n.canMove=P,n.isDraggable=function(e,t){var n=e.pieces[t];return n&&e.draggable.enabled&&("both"===e.movable.color||e.movable.color===n.color&&(e.turnColor===n.color||e.premovable.enabled))},n.playPremove=function(e){var t=e.premovable.current;if(!t)return!1;var n=t[0],r=t[1],o=!1;if(P(e,n,r)){var i=v(e,n,r);if(i){var a={premove:!0};!0!==i&&(a.captured=i),g(e.movable.events.after,n,r,a),o=!0}}return m(e),o},n.playPredrop=function(e,t){var n=e.predroppable.current,r=!1;return!!n&&(t(n)&&y(e,{role:n.role,color:e.movable.color},n.key)&&(g(e.movable.events.afterNewPiece,n.role,n.key,{predrop:!0}),r=!0),b(e),r)},n.cancelMove=i,n.stop=function(e){e.movable.color=e.movable.dests=e.animation.current=void 0,i(e)},n.getKeyAtDomPos=function(e,t,n){var r=Math.ceil((e[0]-n.left)/n.width*8);t||(r=9-r);var o=Math.ceil(8-(e[1]-n.top)/n.height*8);return t||(o=9-o),0<r&&r<9&&0<o&&o<9?d.pos2key([r,o]):void 0}},{"./premove":12,"./util":17}],5:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=e("./api"),o=e("./config"),i=e("./state"),l=e("./wrap"),f=e("./events"),p=e("./render"),d=e("./svg"),h=e("./util");n.Chessground=function(s,e){var u=i.defaults();function c(){var e=u.dom&&u.dom.unbind;s.classList.add("cg-board-wrap");var t,n,r=h.memo(function(){return s.getBoundingClientRect()}),o=u.viewOnly&&!u.drawable.visible,i=l.default(s,u,o?void 0:r()),a=function(e){p.default(u),!e&&i.svg&&d.renderSvg(u,i.svg)};u.dom={elements:i,bounds:r,redraw:(t=a,n=!1,function(){n||(n=!0,h.raf(function(){t(),n=!1}))}),redrawNow:a,unbind:e,relative:o},u.drawable.prevSvgHash="",a(!1),f.bindBoard(u),e||(u.dom.unbind=f.bindDocument(u,c))}return o.configure(u,e||{}),c(),r.start(u,c)}},{"./api":3,"./config":6,"./events":9,"./render":13,"./state":14,"./svg":15,"./util":17,"./wrap":18}],6:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var i=e("./board"),a=e("./fen");function s(e){return"object"===_typeof(e)}n.configure=function(e,t){if(t.movable&&t.movable.dests&&(e.movable.dests=void 0),function e(t,n){for(var r in n)s(t[r])&&s(n[r])?e(t[r],n[r]):t[r]=n[r]}(e,t),t.fen&&(e.pieces=a.read(t.fen),e.drawable.shapes=[]),t.hasOwnProperty("check")&&i.setCheck(e,t.check||!1),t.hasOwnProperty("lastMove")&&!t.lastMove?e.lastMove=void 0:t.lastMove&&(e.lastMove=t.lastMove),e.selected&&i.setSelected(e,e.selected),(!e.animation.duration||e.animation.duration<100)&&(e.animation.enabled=!1),!e.movable.rookCastle&&e.movable.dests){var n="white"===e.movable.color?1:8,r="e"+n,o=e.movable.dests[r];if(!o||"king"!==e.pieces[r].role)return;e.movable.dests[r]=o.filter(function(e){return!(e==="a"+n&&-1!==o.indexOf("c"+n)||e==="h"+n&&-1!==o.indexOf("g"+n))})}}},{"./board":4,"./fen":11}],7:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var h=e("./board"),v=e("./util"),g=e("./draw"),m=e("./anim");function b(a){v.raf(function(){var e=a.draggable.current;if(e){a.animation.current&&a.animation.current.plan.anims[e.orig]&&(a.animation.current=void 0);var t=a.pieces[e.orig];if(t&&v.samePiece(t,e.piece)){if(!e.started&&v.distanceSq(e.epos,e.rel)>=Math.pow(a.draggable.distance,2)&&(e.started=!0),e.started){if("function"==typeof e.element){var n=e.element();if(!n)return;e.element=n,e.element.cgDragging=!0,e.element.classList.add("dragging")}var r="white"===a.orientation,o=a.dom.bounds();e.pos=[e.epos[0]-e.rel[0],e.epos[1]-e.rel[1]];var i=v.posToTranslateAbs(o)(e.origPos,r);i[0]+=e.pos[0]+e.dec[0],i[1]+=e.pos[1]+e.dec[1],v.translateAbs(e.element,i)}}else s(a);b(a)}})}function s(e){var t=e.draggable.current;t&&(t.newPiece&&delete e.pieces[t.orig],e.draggable.current=void 0,h.unselect(e),i(e),e.dom.redraw())}function i(e){var t=e.dom.elements;t.ghost&&v.setVisible(t.ghost,!1)}function y(e,t,n){var r=v.key2pos(e);return t||(r[0]=9-r[0],r[1]=9-r[1]),{left:n.left+n.width*(r[0]-1)/8,top:n.top+n.height*(8-r[1])/8,width:n.width/8,height:n.height/8}}function w(e,t){for(var n=e.dom.elements.board.firstChild;n;){if(n.cgKey===t&&"PIECE"===n.tagName)return n;n=n.nextSibling}}n.start=function(e,t){if(!(void 0!==t.button&&0!==t.button||t.touches&&1<t.touches.length)){t.preventDefault();var n="white"===e.orientation,r=e.dom.bounds(),o=v.eventPosition(t),i=h.getKeyAtDomPos(o,n,r);if(i){var a=e.pieces[i],s=e.selected;s||!e.drawable.enabled||!e.drawable.eraseOnClick&&a&&a.color===e.turnColor||g.clear(e);var u=!!e.premovable.current,c=!!e.predroppable.current;e.stats.ctrlKey=t.ctrlKey,e.selected&&h.canMove(e,e.selected,i)?m.anim(function(e){return h.selectSquare(e,i)},e):h.selectSquare(e,i);var l=e.selected===i,f=w(e,i);if(a&&f&&l&&h.isDraggable(e,i)){var p=y(i,n,r);e.draggable.current={orig:i,origPos:v.key2pos(i),piece:a,rel:o,epos:o,pos:[0,0],dec:e.draggable.centerPiece?[o[0]-(p.left+p.width/2),o[1]-(p.top+p.height/2)]:[0,0],started:e.draggable.autoDistance&&e.stats.dragged,element:f,previouslySelected:s,originTarget:t.target},f.cgDragging=!0,f.classList.add("dragging");var d=e.dom.elements.ghost;d&&(d.className="ghost "+a.color+" "+a.role,v.translateAbs(d,v.posToTranslateAbs(r)(v.key2pos(i),n)),v.setVisible(d,!0)),b(e)}else u&&h.unsetPremove(e),c&&h.unsetPredrop(e);e.dom.redraw()}}},n.dragNewPiece=function(e,t,n,r){var o="a0";e.pieces.a0=t,e.dom.redraw();var i=v.eventPosition(n),a="white"===e.orientation,s=e.dom.bounds(),u=y(o,a,s),c=[(a?0:7)*u.width+s.left,(a?8:-1)*u.height+s.top];e.draggable.current={orig:o,origPos:v.key2pos(o),piece:t,rel:c,epos:i,pos:[i[0]-c[0],i[1]-c[1]],dec:[-u.width/2,-u.height/2],started:!0,element:function(){return w(e,o)},originTarget:n.target,newPiece:!0,force:r||!1},b(e)},n.move=function(e,t){e.draggable.current&&(!t.touches||t.touches.length<2)&&(e.draggable.current.epos=v.eventPosition(t))},n.end=function(e,t){var n=e.draggable.current;if(n)if("touchend"!==t.type||!n||n.originTarget===t.target||n.newPiece){h.unsetPremove(e),h.unsetPredrop(e);var r=v.eventPosition(t)||n.epos,o=h.getKeyAtDomPos(r,"white"===e.orientation,e.dom.bounds());o&&n.started?n.newPiece?h.dropNewPiece(e,n.orig,o,n.force):(e.stats.ctrlKey=t.ctrlKey,h.userMove(e,n.orig,o)&&(e.stats.dragged=!0)):n.newPiece?delete e.pieces[n.orig]:e.draggable.deleteOnDropOff&&(delete e.pieces[n.orig],h.callUserFunction(e.events.change)),(!n||n.orig!==n.previouslySelected||n.orig!==o&&o)&&e.selectable.enabled||h.unselect(e),i(e),e.draggable.current=void 0,e.dom.redraw()}else e.draggable.current=void 0},n.cancel=s},{"./anim":2,"./board":4,"./draw":8,"./util":17}],8:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var s=e("./board"),u=e("./util"),c=["green","red","blue","yellow"];function l(n){u.raf(function(){var e=n.drawable.current;if(e){var t=s.getKeyAtDomPos(e.pos,"white"===n.orientation,n.dom.bounds());t!==e.mouseSq&&(e.mouseSq=t,e.dest=t!==e.orig?t:void 0,n.dom.redrawNow()),l(n)}})}function f(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function p(e){e.onChange&&e.onChange(e.shapes)}n.start=function(e,t){if(!(t.touches&&1<t.touches.length)){t.stopPropagation(),t.preventDefault(),t.ctrlKey?s.unselect(e):s.cancelMove(e);var n,r,o,i=u.eventPosition(t),a=s.getKeyAtDomPos(i,"white"===e.orientation,e.dom.bounds());a&&(e.drawable.current={orig:a,pos:i,brush:(n=t,r=n.shiftKey&&u.isRightButton(n)?1:0,o=n.altKey?2:0,c[r+o])},l(e))}},n.processDraw=l,n.move=function(e,t){e.drawable.current&&(e.drawable.current.pos=u.eventPosition(t))},n.end=function(e){var t=e.drawable.current;t&&(t.mouseSq&&(n=e.drawable,r=t,i=function(e){return e.orig===r.orig&&e.dest===r.dest},a=n.shapes.filter(i)[0],a&&(n.shapes=n.shapes.filter((o=i,function(e){return!o(e)}))),a&&a.brush===r.brush||n.shapes.push(r),p(n)),f(e));var n,r,o,i,a},n.cancel=f,n.clear=function(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),p(e.drawable))}},{"./board":4,"./util":17}],9:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var a=e("./drag"),s=e("./draw"),u=e("./util");function c(e,t,n,r){return e.addEventListener(t,n,r),function(){return e.removeEventListener(t,n)}}function l(t,n,r){return function(e){e.shiftKey||u.isRightButton(e)?t.drawable.enabled&&r(t,e):t.viewOnly||n(t,e)}}n.bindBoard=function(e){if(!e.viewOnly){var t,n=e.dom.elements.board,r=(t=e,function(e){t.draggable.current?a.cancel(t):t.drawable.current?s.cancel(t):e.shiftKey||u.isRightButton(e)?t.drawable.enabled&&s.start(t,e):t.viewOnly||a.start(t,e)});n.addEventListener("touchstart",r),n.addEventListener("mousedown",r),(e.disableContextMenu||e.drawable.enabled)&&n.addEventListener("contextmenu",function(e){return e.preventDefault()})}},n.bindDocument=function(e,t){var n=[];!e.dom.relative&&e.resizable&&n.push(c(document.body,"chessground.resize",function(){e.dom.bounds.clear(),u.raf(t)}));if(!e.viewOnly){var r=l(e,a.move,s.move),o=l(e,a.end,s.end);["touchmove","mousemove"].forEach(function(e){return n.push(c(document,e,r))}),["touchend","mouseup"].forEach(function(e){return n.push(c(document,e,o))});var i=function(){return e.dom.bounds.clear()};n.push(c(window,"scroll",i,{passive:!0})),n.push(c(window,"resize",i,{passive:!0}))}return function(){return n.forEach(function(e){return e()})}}},{"./drag":7,"./draw":8,"./util":17}],10:[function(e,t,n){function r(e,t){e.exploding&&(t?e.exploding.stage=t:e.exploding=void 0,e.dom.redraw())}Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){e.exploding={stage:1,keys:t},e.dom.redraw(),setTimeout(function(){r(e,2),setTimeout(function(){return r(e,void 0)},120)},120)}},{}],11:[function(e,t,c){Object.defineProperty(c,"__esModule",{value:!0});var l=e("./util"),i=e("./types");c.initial="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";var f={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},a={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};c.read=function(e){"start"===e&&(e=c.initial);for(var t={},n=8,r=0,o=0,i=e;o<i.length;o++){var a=i[o];switch(a){case" ":return t;case"/":if(0==--n)return t;r=0;break;case"~":t[l.pos2key([r,n])].promoted=!0;break;default:var s=a.charCodeAt(0);if(s<57)r+=s-48;else{++r;var u=a.toLowerCase();t[l.pos2key([r,n])]={role:f[u],color:a===u?"black":"white"}}}}return t},c.write=function(n){var r,o;return l.invRanks.map(function(t){return i.ranks.map(function(e){return(r=n[l.pos2key([e,t])])?(o=a[r.role],"white"===r.color?o.toUpperCase():o):"1"}).join("")}).join("/").replace(/1{2,}/g,function(e){return e.length.toString()})}},{"./types":16,"./util":17}],12:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var d=e("./util");function h(e,t){return Math.abs(e-t)}var v=function(e,t,n,r){var o=h(e,n),i=h(t,r);return 1===o&&2===i||2===o&&1===i},g=function(e,t,n,r){return h(e,n)===h(t,r)},m=function(e,t,n,r){return e===n||t===r},b=function(e,t,n,r){return g(e,t,n,r)||m(e,t,n,r)};n.default=function(e,t,n){var r,o,i,a,s,u,c,l,f=e[t],p=d.key2pos(t);switch(f.role){case"pawn":l=f.color,r=function(e,t,n,r){return h(e,n)<2&&("white"===l?r===t+1||t<=2&&r===t+2&&e===n:r===t-1||7<=t&&r===t-2&&e===n)};break;case"knight":r=v;break;case"bishop":r=g;break;case"rook":r=m;break;case"queen":r=b;break;case"king":o=f.color,s=e,u=f.color,i=Object.keys(s).filter(function(e){return(c=s[e])&&c.color===u&&"rook"===c.role}).map(function(e){return d.key2pos(e)[0]}),a=n,r=function(e,t,n,r){return h(e,n)<2&&h(t,r)<2||a&&t===r&&t===("white"===o?1:8)&&(5===e&&(3===n||7===n)||d.containsX(i,n))}}return d.allKeys.map(d.key2pos).filter(function(e){return(p[0]!==e[0]||p[1]!==e[1])&&r(p[0],p[1],e[0],e[1])}).map(d.pos2key)}},{"./util":17}],13:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var R=e("./util"),I=e("./util");function q(e,t){for(var n in t)e.dom.elements.board.removeChild(t[n])}function K(e,t){var n=2+8*(e[1]-1)+(8-e[0]);return t&&(n=67-n),n+""}function U(e){return e.color+" "+e.role}function F(e,t,n){e[t]?e[t]+=" "+n:e[t]=n}n.default=function(e){var t,n,r,o,i,a,s,u,c,l,f,p="white"===e.orientation,d=e.dom.relative?I.posToTranslateRel:I.posToTranslateAbs(e.dom.bounds()),h=e.dom.relative?I.translateRel:I.translateAbs,v=e.dom.elements.board,g=e.pieces,m=e.animation.current,b=m?m.plan.anims:{},y=m?m.plan.fadings:{},w=e.draggable.current,E=function(e){var t,n,r={};if(e.lastMove&&e.highlight.lastMove)for(t in e.lastMove)F(r,e.lastMove[t],"last-move");if(e.check&&e.highlight.check&&F(r,e.check,"check"),e.selected&&(F(r,e.selected,"selected"),e.movable.showDests)){var o=e.movable.dests&&e.movable.dests[e.selected];if(o)for(t in o)n=o[t],F(r,n,"move-dest"+(e.pieces[n]?" oc":""));var i=e.premovable.dests;if(i)for(t in i)n=i[t],F(r,n,"premove-dest"+(e.pieces[n]?" oc":""))}var a=e.premovable.current;if(a)for(t in a)F(r,a[t],"current-premove");else e.predroppable.current&&F(r,e.predroppable.current.key,"current-premove");var s=e.exploding;if(s)for(t in s.keys)F(r,s.keys[t],"exploding"+s.stage);return r}(e),k={},P={},C={},S={},x=Object.keys(g);for(r=v.firstChild;r;){if(t=r.cgKey,"PIECE"===r.tagName)o=g[t],a=b[t],s=y[t],i=r.cgPiece,!r.cgDragging||w&&w.orig===t||(r.classList.remove("dragging"),h(r,d(R.key2pos(t),p)),r.cgDragging=!1),!s&&r.cgFading&&(r.cgFading=!1,r.classList.remove("fading")),o?(a&&r.cgAnimating&&i===U(o)?((j=R.key2pos(t))[0]+=a[2],j[1]+=a[3],r.classList.add("anim"),h(r,d(j,p))):r.cgAnimating&&(r.cgAnimating=!1,r.classList.remove("anim"),h(r,d(R.key2pos(t),p)),e.addPieceZIndex&&(r.style.zIndex=K(R.key2pos(t),p))),i!==U(o)||s&&r.cgFading?s&&i===U(s)?(r.classList.add("fading"),r.cgFading=!0):C[i]?C[i].push(r):C[i]=[r]:k[t]=!0):C[i]?C[i].push(r):C[i]=[r];else if("SQUARE"===r.tagName){var _=r.className;E[t]===_?P[t]=!0:S[_]?S[_].push(r):S[_]=[r]}r=r.nextSibling}for(var A in E)if(!P[A]){f=(l=S[E[A]])&&l.pop();var T=d(R.key2pos(A),p);if(f)f.cgKey=A,h(f,T);else{var O=R.createEl("square",E[A]);O.cgKey=A,h(O,T),v.insertBefore(O,v.firstChild)}}for(var N in x)if(n=g[t=x[N]],a=b[t],!k[t])if(c=(u=C[U(n)])&&u.pop()){c.cgKey=t,c.cgFading&&(c.classList.remove("fading"),c.cgFading=!1);var j=R.key2pos(t);e.addPieceZIndex&&(c.style.zIndex=K(j,p)),a&&(c.cgAnimating=!0,c.classList.add("anim"),j[0]+=a[2],j[1]+=a[3]),h(c,d(j,p))}else{var M=U(n),D=R.createEl("piece",M);j=R.key2pos(t),D.cgPiece=M,D.cgKey=t,a&&(D.cgAnimating=!0,j[0]+=a[2],j[1]+=a[3]),h(D,d(j,p)),e.addPieceZIndex&&(D.style.zIndex=K(j,p)),v.appendChild(D)}for(var L in C)q(e,C[L]);for(var L in S)q(e,S[L])}},{"./util":17}],14:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=e("./fen"),o=e("./util");n.defaults=function(){return{pieces:r.read(r.initial),orientation:"white",turnColor:"white",coordinates:!0,autoCastle:!0,viewOnly:!1,disableContextMenu:!1,resizable:!0,addPieceZIndex:!1,pieceKey:!1,highlight:{lastMove:!0,check:!0},animation:{enabled:!0,duration:200},movable:{free:!0,color:"both",showDests:!0,events:{},rookCastle:!0},premovable:{enabled:!0,showDests:!0,castle:!0,events:{}},predroppable:{enabled:!1,events:{}},draggable:{enabled:!0,distance:3,autoDistance:!0,centerPiece:!0,showGhost:!0,deleteOnDropOff:!1},selectable:{enabled:!0},stats:{dragged:!("ontouchstart"in window)},events:{},drawable:{enabled:!0,visible:!0,eraseOnClick:!0,shapes:[],autoShapes:[],brushes:{green:{key:"g",color:"#15781B",opacity:1,lineWidth:10},red:{key:"r",color:"#882020",opacity:1,lineWidth:10},blue:{key:"b",color:"#003088",opacity:1,lineWidth:10},yellow:{key:"y",color:"#e68f00",opacity:1,lineWidth:10},paleBlue:{key:"pb",color:"#003088",opacity:.4,lineWidth:15},paleGreen:{key:"pg",color:"#15781B",opacity:.4,lineWidth:15},paleRed:{key:"pr",color:"#882020",opacity:.4,lineWidth:15},paleGrey:{key:"pgr",color:"#4a4a4a",opacity:.35,lineWidth:15}},pieces:{baseUrl:"https://lichess1.org/assets/piece/cburnett/"},prevSvgHash:""},hold:o.timer()}}},{"./fen":11,"./util":17}],15:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var Q,z=e("./util");function H(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function c(e,t,n){var r,o,i=e.orig,a=e.dest,s=e.brush,u=e.piece,c=e.modifiers;return[n,i,a,s,a&&1<t[a],u&&(o=u,[o.color,o.role,o.scale].filter(function(e){return e}).join("")),c&&(r=c,""+(r.lineWidth||""))].filter(function(e){return e}).join("")}function l(e){var t=W(H("marker"),{id:"arrowhead-"+e.key,orient:"auto",markerWidth:4,markerHeight:8,refX:2.05,refY:2.01});return t.appendChild(W(H("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),t.setAttribute("cgKey",e.key),t}function W(e,t){for(var n in t)e.setAttribute(n,t[n]);return e}function Z(e,t){return"white"===t?e:[9-e[0],9-e[1]]}function V(e,t){var n={color:e.color,opacity:Math.round(10*e.opacity)/10,lineWidth:Math.round(t.lineWidth||e.lineWidth)};return n.key=[e.key,t.lineWidth].filter(function(e){return e}).join(""),n}function X(e,t){return(e.opacity||1)*(t?.9:1)}function G(e,t){return[(e[0]-.5)*t.width/8,(8.5-e[1])*t.height/8]}n.createElement=H,n.renderSvg=function(e,t){var n=e.drawable,r=n.current,o=r&&r.mouseSq?r:void 0,i={};n.shapes.concat(n.autoShapes).concat(o?[o]:[]).forEach(function(e){e.dest&&(i[e.dest]=(i[e.dest]||0)+1)});var a=n.shapes.concat(n.autoShapes).map(function(e){return{shape:e,current:!1,hash:c(e,i,!1)}});o&&a.push({shape:o,current:!0,hash:c(o,i,!0)});var s=a.map(function(e){return e.hash}).join("");if(s!==e.drawable.prevSvgHash){e.drawable.prevSvgHash=s;var u=t.firstChild;!function(t,e,n){var r,o={};e.forEach(function(e){e.shape.dest&&(r=t.brushes[e.shape.brush],e.shape.modifiers&&(r=V(r,e.shape.modifiers)),o[r.key]=r)});for(var i={},a=n.firstChild;a;)i[a.getAttribute("cgKey")]=!0,a=a.nextSibling;for(var s in o)i[s]||n.appendChild(l(o[s]))}(n,a,u),function(t,e,n,r,o,i){void 0===Q&&(Q=z.computeIsTrident());var a=t.dom.bounds(),s={},u=[];e.forEach(function(e){s[e.hash]=!1});for(var c,l=i.nextSibling;l;)c=l.getAttribute("cgHash"),s.hasOwnProperty(c)?s[c]=!0:u.push(l),l=l.nextSibling;u.forEach(function(e){return o.removeChild(e)}),e.forEach(function(e){s[e.hash]||o.appendChild(function(e,t,n,r,o){var i,a,s,u,c,l,f,p,d,h,v,g,m,b,y,w,E,k,P,C,S,x,_,A,T,O,N,j,M,D,L,R,I,q,K=t.shape,U=t.current,F=t.hash;if(K.piece)j=e.drawable.pieces.baseUrl,M=Z(z.key2pos(K.orig),e.orientation),D=K.piece,R=G(M,L=o),I=L.width/8*(D.scale||1),q=D.color[0]+("knight"===D.role?"n":D.role[0]).toUpperCase(),i=W(H("image"),{className:D.role+" "+D.color,x:R[0]-I/2,y:R[1]-I/2,width:I,height:I,href:j+q+".svg"});else{var B=Z(z.key2pos(K.orig),e.orientation);if(K.orig&&K.dest){var $=n[K.brush];K.modifiers&&($=V($,K.modifiers)),d=$,h=B,v=Z(z.key2pos(K.dest),e.orientation),g=U,m=1<r[K.dest],_=b=o,A=m&&!g,y=Q?0:(A?20:10)/512*_.width,w=G(h,b),E=G(v,b),k=E[0]-w[0],P=E[1]-w[1],C=Math.atan2(P,k),S=Math.cos(C)*y,x=Math.sin(C)*y,i=W(H("line"),{stroke:d.color,"stroke-width":(T=d,O=g,N=b,(T.lineWidth||10)*(O?.85:1)/512*N.width),"stroke-linecap":"round","marker-end":Q?void 0:"url(#arrowhead-"+d.key+")",opacity:X(d,g),x1:w[0],y1:w[1],x2:E[0]-S,y2:E[1]-x})}else a=n[K.brush],s=U,c=G(B,u=o),p=u.width/512,l=[3*p,4*p],f=(u.width+u.height)/32,i=W(H("circle"),{stroke:a.color,"stroke-width":l[s?0:1],fill:"none",opacity:X(a,s),cx:c[0],cy:c[1],r:f-l[1]/2})}return i.setAttribute("cgHash",F),i}(t,e,n,r,a))})}(e,a,n.brushes,i,t,u)}}},{"./util":17}],16:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.files=["a","b","c","d","e","f","g","h"],n.ranks=[1,2,3,4,5,6,7,8]},{}],17:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=e("./types");n.colors=["white","black"],n.invRanks=[8,7,6,5,4,3,2,1],n.allKeys=(o=Array.prototype).concat.apply(o,r.files.map(function(t){return r.ranks.map(function(e){return t+e})})),n.pos2key=function(e){return n.allKeys[8*e[0]+e[1]-9]},n.key2pos=function(e){return[e.charCodeAt(0)-96,e.charCodeAt(1)-48]},n.memo=function(e){var t,n=function(){return void 0===t&&(t=e()),t};return n.clear=function(){t=void 0},n},n.timer=function(){var t;return{start:function(){t=Date.now()},cancel:function(){t=void 0},stop:function(){if(!t)return 0;var e=Date.now()-t;return t=void 0,e}}},n.opposite=function(e){return"white"===e?"black":"white"},n.containsX=function(e,t){return void 0!==e&&-1!==e.indexOf(t)},n.distanceSq=function(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)},n.samePiece=function(e,t){return e.role===t.role&&e.color===t.color},n.computeIsTrident=function(){return-1<window.navigator.userAgent.indexOf("Trident/")};var o,i=function(e,t,n,r){return[(t?e[0]-1:8-e[0])*n,(t?8-e[1]:e[1]-1)*r]};n.posToTranslateAbs=function(e){var n=e.width/8,r=e.height/8;return function(e,t){return i(e,t,n,r)}},n.posToTranslateRel=function(e,t){return i(e,t,12.5,12.5)},n.translateAbs=function(e,t){e.style.transform="translate("+t[0]+"px,"+t[1]+"px)"},n.translateRel=function(e,t){e.style.left=t[0]+"%",e.style.top=t[1]+"%"},n.setVisible=function(e,t){e.style.visibility=t?"visible":"hidden"},n.eventPosition=function(e){return e.clientX||0===e.clientX?[e.clientX,e.clientY]:e.touches&&e.targetTouches[0]?[e.targetTouches[0].clientX,e.targetTouches[0].clientY]:void 0},n.isRightButton=function(e){return 2===e.buttons||2===e.button},n.createEl=function(e,t){var n=document.createElement(e);return t&&(n.className=t),n},n.raf=(window.requestAnimationFrame||window.setTimeout).bind(window)},{"./types":16}],18:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var s=e("./util"),u=e("./types"),c=e("./svg");function l(e,t){var n,r=s.createEl("coords",t);for(var o in e)(n=s.createEl("coord")).textContent=e[o],r.appendChild(n);return r}n.default=function(t,n,e){t.innerHTML="",t.classList.add("cg-board-wrap"),s.colors.forEach(function(e){t.classList.toggle("orientation-"+e,n.orientation===e)}),t.classList.toggle("manipulable",!n.viewOnly);var r,o,i=s.createEl("div","cg-board");if(t.appendChild(i),n.drawable.visible&&e&&((r=c.createElement("svg")).appendChild(c.createElement("defs")),t.appendChild(r)),n.coordinates){var a="black"===n.orientation?" black":"";t.appendChild(l(u.ranks,"ranks"+a)),t.appendChild(l(u.files,"files"+a))}return e&&n.draggable.showGhost&&(o=s.createEl("piece","ghost"),s.setVisible(o,!1),t.appendChild(o)),{board:i,ghost:o,svg:r}}},{"./svg":15,"./types":16,"./util":17}],19:[function(e,t,n){var i,r=function(){var a,s,u,r,c,n,o=[],l=o.slice,i=o.filter,f=window.document,p={},t={},d={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},h=/^\s*<(\w+|!)[^>]*>/,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,g=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,m=/^(?:body|html)$/i,b=/([A-Z])/g,y=["val","css","html","text","data","width","height","offset"],e=f.createElement("table"),w=f.createElement("tr"),E={tr:f.createElement("tbody"),tbody:e,thead:e,tfoot:e,td:w,th:w,"*":f.createElement("div")},k=/complete|loaded|interactive/,P=/^[\w-]*$/,C={},S=C.toString,x={},_=f.createElement("div"),A={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},T=Array.isArray||function(e){return e instanceof Array};function O(e){return null==e?String(e):C[S.call(e)]||"object"}function N(e){return"function"==O(e)}function j(e){return null!=e&&e==e.window}function M(e){return null!=e&&e.nodeType==e.DOCUMENT_NODE}function D(e){return"object"==O(e)}function L(e){return D(e)&&!j(e)&&Object.getPrototypeOf(e)==Object.prototype}function R(e){return"number"==typeof e.length}function I(e){return e.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function q(e){return e in t?t[e]:t[e]=new RegExp("(^|\\s)"+e+"(\\s|$)")}function K(e,t){return"number"!=typeof t||d[I(e)]?t:t+"px"}function U(e){return"children"in e?l.call(e.children):u.map(e.childNodes,function(e){if(1==e.nodeType)return e})}function F(e,t){return null==t?u(e):u(e).filter(t)}function B(e,t,n,r){return N(t)?t.call(e,n,r):t}function $(e,t,n){null==n?e.removeAttribute(t):e.setAttribute(t,n)}function Q(e,t){var n=e.className||"",r=n&&n.baseVal!==a;if(t===a)return r?n.baseVal:n;r?n.baseVal=t:e.className=t}function z(t){try{return t?"true"==t||"false"!=t&&("null"==t?null:+t+""==t?+t:/^[\[\{]/.test(t)?u.parseJSON(t):t):t}catch(e){return t}}return x.matches=function(e,t){if(!t||!e||1!==e.nodeType)return!1;var n=e.webkitMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.matchesSelector;if(n)return n.call(e,t);var r,o=e.parentNode,i=!o;return i&&(o=_).appendChild(e),r=~x.qsa(o,t).indexOf(e),i&&_.removeChild(e),r},c=function(e){return e.replace(/-+(.)?/g,function(e,t){return t?t.toUpperCase():""})},n=function(n){return i.call(n,function(e,t){return n.indexOf(e)==t})},x.fragment=function(e,t,n){var r,o,i;return v.test(e)&&(r=u(f.createElement(RegExp.$1))),r||(e.replace&&(e=e.replace(g,"<$1></$2>")),t===a&&(t=h.test(e)&&RegExp.$1),t in E||(t="*"),(i=E[t]).innerHTML=""+e,r=u.each(l.call(i.childNodes),function(){i.removeChild(this)})),L(n)&&(o=u(r),u.each(n,function(e,t){-1<y.indexOf(e)?o[e](t):o.attr(e,t)})),r},x.Z=function(e,t){return(e=e||[]).__proto__=u.fn,e.selector=t||"",e},x.isZ=function(e){return e instanceof x.Z},x.init=function(e,t){var n,r;if(!e)return x.Z();if("string"==typeof e)if("<"==(e=e.trim())[0]&&h.test(e))n=x.fragment(e,RegExp.$1,t),e=null;else{if(t!==a)return u(t).find(e);n=x.qsa(f,e)}else{if(N(e))return u(f).ready(e);if(x.isZ(e))return e;if(T(e))r=e,n=i.call(r,function(e){return null!=e});else if(D(e))n=[e],e=null;else if(h.test(e))n=x.fragment(e.trim(),RegExp.$1,t),e=null;else{if(t!==a)return u(t).find(e);n=x.qsa(f,e)}}return x.Z(n,e)},(u=function(e,t){return x.init(e,t)}).extend=function(t){var n,e=l.call(arguments,1);return"boolean"==typeof t&&(n=t,t=e.shift()),e.forEach(function(e){!function e(t,n,r){for(s in n)r&&(L(n[s])||T(n[s]))?(L(n[s])&&!L(t[s])&&(t[s]={}),T(n[s])&&!T(t[s])&&(t[s]=[]),e(t[s],n[s],r)):n[s]!==a&&(t[s]=n[s])}(t,e,n)}),t},x.qsa=function(e,t){var n,r="#"==t[0],o=!r&&"."==t[0],i=r||o?t.slice(1):t,a=P.test(i);return M(e)&&a&&r?(n=e.getElementById(i))?[n]:[]:1!==e.nodeType&&9!==e.nodeType?[]:l.call(a&&!r?o?e.getElementsByClassName(i):e.getElementsByTagName(t):e.querySelectorAll(t))},u.contains=f.documentElement.contains?function(e,t){return e!==t&&e.contains(t)}:function(e,t){for(;t&&(t=t.parentNode);)if(t===e)return!0;return!1},u.type=O,u.isFunction=N,u.isWindow=j,u.isArray=T,u.isPlainObject=L,u.isEmptyObject=function(e){var t;for(t in e)return!1;return!0},u.inArray=function(e,t,n){return o.indexOf.call(t,e,n)},u.camelCase=c,u.trim=function(e){return null==e?"":String.prototype.trim.call(e)},u.uuid=0,u.support={},u.expr={},u.map=function(e,t){var n,r,o,i,a=[];if(R(e))for(r=0;r<e.length;r++)null!=(n=t(e[r],r))&&a.push(n);else for(o in e)null!=(n=t(e[o],o))&&a.push(n);return 0<(i=a).length?u.fn.concat.apply([],i):i},u.each=function(e,t){var n,r;if(R(e)){for(n=0;n<e.length;n++)if(!1===t.call(e[n],n,e[n]))return e}else for(r in e)if(!1===t.call(e[r],r,e[r]))return e;return e},u.grep=function(e,t){return i.call(e,t)},window.JSON&&(u.parseJSON=JSON.parse),u.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){C["[object "+t+"]"]=t.toLowerCase()}),u.fn={forEach:o.forEach,reduce:o.reduce,push:o.push,sort:o.sort,indexOf:o.indexOf,concat:o.concat,map:function(n){return u(u.map(this,function(e,t){return n.call(e,t,e)}))},slice:function(){return u(l.apply(this,arguments))},ready:function(e){return k.test(f.readyState)&&f.body?e(u):f.addEventListener("DOMContentLoaded",function(){e(u)},!1),this},get:function(e){return e===a?l.call(this):this[0<=e?e:e+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){null!=this.parentNode&&this.parentNode.removeChild(this)})},each:function(n){return o.every.call(this,function(e,t){return!1!==n.call(e,t,e)}),this},filter:function(t){return N(t)?this.not(this.not(t)):u(i.call(this,function(e){return x.matches(e,t)}))},add:function(e,t){return u(n(this.concat(u(e,t))))},is:function(e){return 0<this.length&&x.matches(this[0],e)},not:function(t){var n=[];if(N(t)&&t.call!==a)this.each(function(e){t.call(this,e)||n.push(this)});else{var r="string"==typeof t?this.filter(t):R(t)&&N(t.item)?l.call(t):u(t);this.forEach(function(e){r.indexOf(e)<0&&n.push(e)})}return u(n)},has:function(e){return this.filter(function(){return D(e)?u.contains(this,e):u(this).find(e).size()})},eq:function(e){return-1===e?this.slice(e):this.slice(e,+e+1)},first:function(){var e=this[0];return e&&!D(e)?e:u(e)},last:function(){var e=this[this.length-1];return e&&!D(e)?e:u(e)},find:function(e){var n=this;return e?"object"==_typeof(e)?u(e).filter(function(){var t=this;return o.some.call(n,function(e){return u.contains(e,t)})}):1==this.length?u(x.qsa(this[0],e)):this.map(function(){return x.qsa(this,e)}):u()},closest:function(e,t){var n=this[0],r=!1;for("object"==_typeof(e)&&(r=u(e));n&&!(r?0<=r.indexOf(n):x.matches(n,e));)n=n!==t&&!M(n)&&n.parentNode;return u(n)},parents:function(e){for(var t=[],n=this;0<n.length;)n=u.map(n,function(e){if((e=e.parentNode)&&!M(e)&&t.indexOf(e)<0)return t.push(e),e});return F(t,e)},parent:function(e){return F(n(this.pluck("parentNode")),e)},children:function(e){return F(this.map(function(){return U(this)}),e)},contents:function(){return this.map(function(){return l.call(this.childNodes)})},siblings:function(e){return F(this.map(function(e,t){return i.call(U(t.parentNode),function(e){return e!==t})}),e)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(t){return u.map(this,function(e){return e[t]})},show:function(){return this.each(function(){var e,t,n;"none"==this.style.display&&(this.style.display=""),"none"==getComputedStyle(this,"").getPropertyValue("display")&&(this.style.display=(e=this.nodeName,p[e]||(t=f.createElement(e),f.body.appendChild(t),n=getComputedStyle(t,"").getPropertyValue("display"),t.parentNode.removeChild(t),"none"==n&&(n="block"),p[e]=n),p[e]))})},replaceWith:function(e){return this.before(e).remove()},wrap:function(t){var n=N(t);if(this[0]&&!n)var r=u(t).get(0),o=r.parentNode||1<this.length;return this.each(function(e){u(this).wrapAll(n?t.call(this,e):o?r.cloneNode(!0):r)})},wrapAll:function(e){if(this[0]){var t;for(u(this[0]).before(e=u(e));(t=e.children()).length;)e=t.first();u(e).append(this)}return this},wrapInner:function(o){var i=N(o);return this.each(function(e){var t=u(this),n=t.contents(),r=i?o.call(this,e):o;n.length?n.wrapAll(r):t.append(r)})},unwrap:function(){return this.parent().each(function(){u(this).replaceWith(u(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(t){return this.each(function(){var e=u(this);(t===a?"none"==e.css("display"):t)?e.show():e.hide()})},prev:function(e){return u(this.pluck("previousElementSibling")).filter(e||"*")},next:function(e){return u(this.pluck("nextElementSibling")).filter(e||"*")},html:function(n){return 0 in arguments?this.each(function(e){var t=this.innerHTML;u(this).empty().append(B(this,n,e,t))}):0 in this?this[0].innerHTML:null},text:function(n){return 0 in arguments?this.each(function(e){var t=B(this,n,e,this.textContent);this.textContent=null==t?"":""+t}):0 in this?this[0].textContent:null},attr:function(t,n){var e;return"string"!=typeof t||1 in arguments?this.each(function(e){if(1===this.nodeType)if(D(t))for(s in t)$(this,s,t[s]);else $(this,t,B(this,n,e,this.getAttribute(t)))}):this.length&&1===this[0].nodeType?!(e=this[0].getAttribute(t))&&t in this[0]?this[0][t]:e:a},removeAttr:function(e){return this.each(function(){1===this.nodeType&&e.split(" ").forEach(function(e){$(this,e)},this)})},prop:function(t,n){return t=A[t]||t,1 in arguments?this.each(function(e){this[t]=B(this,n,e,this[t])}):this[0]&&this[0][t]},data:function(e,t){var n="data-"+e.replace(b,"-$1").toLowerCase(),r=1 in arguments?this.attr(n,t):this.attr(n);return null!==r?z(r):a},val:function(t){return 0 in arguments?this.each(function(e){this.value=B(this,t,e,this.value)}):this[0]&&(this[0].multiple?u(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value)},offset:function(i){if(i)return this.each(function(e){var t=u(this),n=B(this,i,e,t.offset()),r=t.offsetParent().offset(),o={top:n.top-r.top,left:n.left-r.left};"static"==t.css("position")&&(o.position="relative"),t.css(o)});if(!this.length)return null;var e=this[0].getBoundingClientRect();return{left:e.left+window.pageXOffset,top:e.top+window.pageYOffset,width:Math.round(e.width),height:Math.round(e.height)}},css:function(e,t){if(arguments.length<2){var n,r=this[0];if(!r)return;if(n=getComputedStyle(r,""),"string"==typeof e)return r.style[c(e)]||n.getPropertyValue(e);if(T(e)){var o={};return u.each(e,function(e,t){o[t]=r.style[c(t)]||n.getPropertyValue(t)}),o}}var i="";if("string"==O(e))t||0===t?i=I(e)+":"+K(e,t):this.each(function(){this.style.removeProperty(I(e))});else for(s in e)e[s]||0===e[s]?i+=I(s)+":"+K(s,e[s])+";":this.each(function(){this.style.removeProperty(I(s))});return this.each(function(){this.style.cssText+=";"+i})},index:function(e){return e?this.indexOf(u(e)[0]):this.parent().children().indexOf(this[0])},hasClass:function(e){return!!e&&o.some.call(this,function(e){return this.test(Q(e))},q(e))},addClass:function(n){return n?this.each(function(e){if("className"in this){r=[];var t=Q(this);B(this,n,e,t).split(/\s+/g).forEach(function(e){u(this).hasClass(e)||r.push(e)},this),r.length&&Q(this,t+(t?" ":"")+r.join(" "))}}):this},removeClass:function(t){return this.each(function(e){if("className"in this){if(t===a)return Q(this,"");r=Q(this),B(this,t,e,r).split(/\s+/g).forEach(function(e){r=r.replace(q(e)," ")}),Q(this,r.trim())}})},toggleClass:function(n,r){return n?this.each(function(e){var t=u(this);B(this,n,e,Q(this)).split(/\s+/g).forEach(function(e){(r===a?!t.hasClass(e):r)?t.addClass(e):t.removeClass(e)})}):this},scrollTop:function(e){if(this.length){var t="scrollTop"in this[0];return e===a?t?this[0].scrollTop:this[0].pageYOffset:this.each(t?function(){this.scrollTop=e}:function(){this.scrollTo(this.scrollX,e)})}},scrollLeft:function(e){if(this.length){var t="scrollLeft"in this[0];return e===a?t?this[0].scrollLeft:this[0].pageXOffset:this.each(t?function(){this.scrollLeft=e}:function(){this.scrollTo(e,this.scrollY)})}},position:function(){if(this.length){var e=this[0],t=this.offsetParent(),n=this.offset(),r=m.test(t[0].nodeName)?{top:0,left:0}:t.offset();return n.top-=parseFloat(u(e).css("margin-top"))||0,n.left-=parseFloat(u(e).css("margin-left"))||0,r.top+=parseFloat(u(t[0]).css("border-top-width"))||0,r.left+=parseFloat(u(t[0]).css("border-left-width"))||0,{top:n.top-r.top,left:n.left-r.left}}},offsetParent:function(){return this.map(function(){for(var e=this.offsetParent||f.body;e&&!m.test(e.nodeName)&&"static"==u(e).css("position");)e=e.offsetParent;return e})}},u.fn.detach=u.fn.remove,["width","height"].forEach(function(r){var o=r.replace(/./,function(e){return e[0].toUpperCase()});u.fn[r]=function(t){var e,n=this[0];return t===a?j(n)?n["inner"+o]:M(n)?n.documentElement["scroll"+o]:(e=this.offset())&&e[r]:this.each(function(e){(n=u(this)).css(r,B(this,t,e,n[r]()))})}}),["after","prepend","before","append"].forEach(function(t,a){var s=a%2;u.fn[t]=function(){var t,r,o=u.map(arguments,function(e){return"object"==(t=O(e))||"array"==t||null==e?e:x.fragment(e)}),i=1<this.length;return o.length<1?this:this.each(function(e,t){r=s?t:t.parentNode,t=0==a?t.nextSibling:1==a?t.firstChild:2==a?t:null;var n=u.contains(f.documentElement,r);o.forEach(function(e){if(i)e=e.cloneNode(!0);else if(!r)return u(e).remove();r.insertBefore(e,t),n&&function e(t,n){n(t);for(var r=0,o=t.childNodes.length;r<o;r++)e(t.childNodes[r],n)}(e,function(e){null==e.nodeName||"SCRIPT"!==e.nodeName.toUpperCase()||e.type&&"text/javascript"!==e.type||e.src||window.eval.call(window,e.innerHTML)})})})},u.fn[s?t+"To":"insert"+(a?"Before":"After")]=function(e){return u(e)[t](this),this}}),x.Z.prototype=u.fn,x.uniq=n,x.deserializeValue=z,u.zepto=x,u}();window.Zepto=r,void 0===window.$&&(window.$=r),n.Zepto=window.Zepto,n.$=window.$,function(l){var f,t=1,c=Array.prototype.slice,p=l.isFunction,d=function(e){return"string"==typeof e},h={},i={},n="onfocusin"in window,r={focus:"focusin",blur:"focusout"},v={mouseenter:"mouseover",mouseleave:"mouseout"};function g(e){return e._zid||(e._zid=t++)}function a(e,t,n,r){if((t=m(t)).ns)var o=(i=t.ns,new RegExp("(?:^| )"+i.replace(" "," .* ?")+"(?: |$)"));var i;return(h[g(e)]||[]).filter(function(e){return e&&(!t.e||e.e==t.e)&&(!t.ns||o.test(e.ns))&&(!n||g(e.fn)===g(n))&&(!r||e.sel==r)})}function m(e){var t=(""+e).split(".");return{e:t[0],ns:t.slice(1).sort().join(" ")}}function b(e,t){return e.del&&!n&&e.e in r||!!t}function y(e){return v[e]||n&&r[e]||e}function w(o,e,t,i,a,s,u){var n=g(o),c=h[n]||(h[n]=[]);e.split(/\s/).forEach(function(e){if("ready"==e)return l(document).ready(t);var n=m(e);n.fn=t,n.sel=a,n.e in v&&(t=function(e){var t=e.relatedTarget;if(!t||t!==this&&!l.contains(this,t))return n.fn.apply(this,arguments)});var r=(n.del=s)||t;n.proxy=function(e){if(!(e=P(e)).isImmediatePropagationStopped()){e.data=i;var t=r.apply(o,e._args==f?[e]:[e].concat(e._args));return!1===t&&(e.preventDefault(),e.stopPropagation()),t}},n.i=c.length,c.push(n),"addEventListener"in o&&o.addEventListener(y(n.e),n.proxy,b(n,u))})}function E(t,e,n,r,o){var i=g(t);(e||"").split(/\s/).forEach(function(e){a(t,e,n,r).forEach(function(e){delete h[i][e.i],"removeEventListener"in t&&t.removeEventListener(y(e.e),e.proxy,b(e,o))})})}i.click=i.mousedown=i.mouseup=i.mousemove="MouseEvents",l.event={add:w,remove:E},l.proxy=function(e,t){var n=2 in arguments&&c.call(arguments,2);if(p(e)){var r=function(){return e.apply(t,n?n.concat(c.call(arguments)):arguments)};return r._zid=g(e),r}if(d(t))return n?(n.unshift(e[t],e),l.proxy.apply(null,n)):l.proxy(e[t],e);throw new TypeError("expected function")},l.fn.bind=function(e,t,n){return this.on(e,t,n)},l.fn.unbind=function(e,t){return this.off(e,t)},l.fn.one=function(e,t,n,r){return this.on(e,t,n,r,1)};var s=function(){return!0},k=function(){return!1},o=/^([A-Z]|returnValue$|layer[XY]$)/,e={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};function P(r,o){return!o&&r.isDefaultPrevented||(o||(o=r),l.each(e,function(e,t){var n=o[e];r[e]=function(){return this[t]=s,n&&n.apply(o,arguments)},r[t]=k}),(o.defaultPrevented!==f?o.defaultPrevented:"returnValue"in o?!1===o.returnValue:o.getPreventDefault&&o.getPreventDefault())&&(r.isDefaultPrevented=s)),r}function C(e){var t,n={originalEvent:e};for(t in e)o.test(t)||e[t]===f||(n[t]=e[t]);return P(n,e)}l.fn.delegate=function(e,t,n){return this.on(t,e,n)},l.fn.undelegate=function(e,t,n){return this.off(t,e,n)},l.fn.live=function(e,t){return l(document.body).delegate(this.selector,e,t),this},l.fn.die=function(e,t){return l(document.body).undelegate(this.selector,e,t),this},l.fn.on=function(t,o,n,i,a){var s,u,r=this;return t&&!d(t)?(l.each(t,function(e,t){r.on(e,o,n,t,a)}),r):(d(o)||p(i)||!1===i||(i=n,n=o,o=f),(p(n)||!1===n)&&(i=n,n=f),!1===i&&(i=k),r.each(function(e,r){a&&(s=function(e){return E(r,e.type,i),i.apply(this,arguments)}),o&&(u=function(e){var t,n=l(e.target).closest(o,r).get(0);if(n&&n!==r)return t=l.extend(C(e),{currentTarget:n,liveFired:r}),(s||i).apply(n,[t].concat(c.call(arguments,1)))}),w(r,t,i,n,o,u||s)}))},l.fn.off=function(e,n,t){var r=this;return e&&!d(e)?(l.each(e,function(e,t){r.off(e,n,t)}),r):(d(n)||p(t)||!1===t||(t=n,n=f),!1===t&&(t=k),r.each(function(){E(this,e,t,n)}))},l.fn.trigger=function(e,t){return(e=d(e)||l.isPlainObject(e)?l.Event(e):P(e))._args=t,this.each(function(){e.type in r&&"function"==typeof this[e.type]?this[e.type]():"dispatchEvent"in this?this.dispatchEvent(e):l(this).triggerHandler(e,t)})},l.fn.triggerHandler=function(n,r){var o,i;return this.each(function(e,t){(o=C(d(n)?l.Event(n):n))._args=r,o.target=t,l.each(a(t,n.type||n),function(e,t){if(i=t.proxy(o),o.isImmediatePropagationStopped())return!1})}),i},"focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(t){l.fn[t]=function(e){return 0 in arguments?this.bind(t,e):this.trigger(t)}}),l.Event=function(e,t){d(e)||(e=(t=e).type);var n=document.createEvent(i[e]||"Events"),r=!0;if(t)for(var o in t)"bubbles"==o?r=!!t[o]:n[o]=t[o];return n.initEvent(e,r,!0),P(n)}}(r),function(g){var m,b,l=0,y=window.document,u=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,w=/^(?:text|application)\/javascript/i,E=/^(?:text|application)\/xml/i,k="application/json",P="text/html",C=/^\s*$/,S=y.createElement("a");function x(e,t,n,r){if(e.global)return o=t||y,i=n,a=r,s=g.Event(i),g(o).trigger(s,a),!s.isDefaultPrevented();var o,i,a,s}function _(e,t){var n=t.context;if(!1===t.beforeSend.call(n,e,t)||!1===x(t,n,"ajaxBeforeSend",[e,t]))return!1;x(t,n,"ajaxSend",[e,t])}function A(e,t,n,r){var o=n.context,i="success";n.success.call(o,e,i,t),r&&r.resolveWith(o,[e,i,t]),x(n,o,"ajaxSuccess",[t,n,e]),a(i,t,n)}function T(e,t,n,r,o){var i=r.context;r.error.call(i,n,t,e),o&&o.rejectWith(i,[n,t,e]),x(r,i,"ajaxError",[n,r,e||t]),a(t,n,r)}function a(e,t,n){var r,o=n.context;n.complete.call(o,t,e),x(n,o,"ajaxComplete",[t,n]),(r=n).global&&!--g.active&&x(r,null,"ajaxStop")}function O(){}function N(e,t){return""==t?e:(e+"&"+t).replace(/[&?]{1,2}/,"?")}function c(e,t,n,r){return g.isFunction(t)&&(r=n,n=t,t=void 0),g.isFunction(n)||(r=n,n=void 0),{url:e,data:t,success:n,dataType:r}}S.href=window.location.href,g.active=0,g.ajaxJSONP=function(n,r){if(!("type"in n))return g.ajax(n);var o,i,e=n.jsonpCallback,a=(g.isFunction(e)?e():e)||"jsonp"+ ++l,s=y.createElement("script"),u=window[a],t=function(e){g(s).triggerHandler("error",e||"abort")},c={abort:t};return r&&r.promise(c),g(s).on("load error",function(e,t){clearTimeout(i),g(s).off().remove(),"error"!=e.type&&o?A(o[0],c,n,r):T(null,t||"error",c,n,r),window[a]=u,o&&g.isFunction(u)&&u(o[0]),u=o=void 0}),!1===_(c,n)?t("abort"):(window[a]=function(){o=arguments},s.src=n.url.replace(/\?(.+)=\?/,"?$1="+a),y.head.appendChild(s),0<n.timeout&&(i=setTimeout(function(){t("timeout")},n.timeout))),c},g.ajaxSettings={type:"GET",beforeSend:O,success:O,error:O,complete:O,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:k,xml:"application/xml, text/xml",html:P,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0},g.ajax=function(e){var t,n,r,o=g.extend({},e||{}),i=g.Deferred&&g.Deferred();for(m in g.ajaxSettings)void 0===o[m]&&(o[m]=g.ajaxSettings[m]);(n=o).global&&0==g.active++&&x(n,null,"ajaxStart"),o.crossDomain||((t=y.createElement("a")).href=o.url,t.href=t.href,o.crossDomain=S.protocol+"//"+S.host!=t.protocol+"//"+t.host),o.url||(o.url=window.location.toString()),(r=o).processData&&r.data&&"string"!=g.type(r.data)&&(r.data=g.param(r.data,r.traditional)),!r.data||r.type&&"GET"!=r.type.toUpperCase()||(r.url=N(r.url,r.data),r.data=void 0);var a=o.dataType,s=/\?.+=\?/.test(o.url);if(s&&(a="jsonp"),!1!==o.cache&&(e&&!0===e.cache||"script"!=a&&"jsonp"!=a)||(o.url=N(o.url,"_="+Date.now())),"jsonp"==a)return s||(o.url=N(o.url,o.jsonp?o.jsonp+"=?":!1===o.jsonp?"":"callback=?")),g.ajaxJSONP(o,i);var u,c=o.accepts[a],l={},f=function(e,t){l[e.toLowerCase()]=[e,t]},p=/^([\w-]+:)\/\//.test(o.url)?RegExp.$1:window.location.protocol,d=o.xhr(),h=d.setRequestHeader;if(i&&i.promise(d),o.crossDomain||f("X-Requested-With","XMLHttpRequest"),f("Accept",c||"*/*"),(c=o.mimeType||c)&&(-1<c.indexOf(",")&&(c=c.split(",",2)[0]),d.overrideMimeType&&d.overrideMimeType(c)),(o.contentType||!1!==o.contentType&&o.data&&"GET"!=o.type.toUpperCase())&&f("Content-Type",o.contentType||"application/x-www-form-urlencoded"),o.headers)for(b in o.headers)f(b,o.headers[b]);if(d.setRequestHeader=f,!(d.onreadystatechange=function(){if(4==d.readyState){d.onreadystatechange=O,clearTimeout(u);var e,t=!1;if(200<=d.status&&d.status<300||304==d.status||0==d.status&&"file:"==p){a=a||((n=o.mimeType||d.getResponseHeader("content-type"))&&(n=n.split(";",2)[0]),n&&(n==P?"html":n==k?"json":w.test(n)?"script":E.test(n)&&"xml")||"text"),e=d.responseText;try{"script"==a?(0,eval)(e):"xml"==a?e=d.responseXML:"json"==a&&(e=C.test(e)?null:g.parseJSON(e))}catch(e){t=e}t?T(t,"parsererror",d,o,i):A(e,d,o,i)}else T(d.statusText||null,d.status?"error":"abort",d,o,i)}var n})===_(d,o))return d.abort(),T(null,"abort",d,o,i),d;if(o.xhrFields)for(b in o.xhrFields)d[b]=o.xhrFields[b];var v=!("async"in o)||o.async;for(b in d.open(o.type,o.url,v,o.username,o.password),l)h.apply(d,l[b]);return 0<o.timeout&&(u=setTimeout(function(){d.onreadystatechange=O,d.abort(),T(null,"timeout",d,o,i)},o.timeout)),d.send(o.data?o.data:null),d},g.get=function(){return g.ajax(c.apply(null,arguments))},g.post=function(){var e=c.apply(null,arguments);return e.type="POST",g.ajax(e)},g.getJSON=function(){var e=c.apply(null,arguments);return e.dataType="json",g.ajax(e)},g.fn.load=function(e,t,n){if(!this.length)return this;var r,o=this,i=e.split(/\s/),a=c(e,t,n),s=a.success;return 1<i.length&&(a.url=i[0],r=i[1]),a.success=function(e){o.html(r?g("<div>").html(e.replace(u,"")).find(r):e),s&&s.apply(o,arguments)},g.ajax(a),this};var r=encodeURIComponent;g.param=function(e,t){var n=[];return n.add=function(e,t){g.isFunction(t)&&(t=t()),null==t&&(t=""),this.push(r(e)+"="+r(t))},function n(r,e,o,i){var a,s=g.isArray(e),u=g.isPlainObject(e);g.each(e,function(e,t){a=g.type(t),i&&(e=o?i:i+"["+(u||"object"==a||"array"==a?e:"")+"]"),!i&&s?r.add(t.name,t.value):"array"==a||!o&&"object"==a?n(r,t,o,e):r.add(e,t)})}(n,e,t),n.join("&").replace(/%20/g,"+")}}(r),(i=r).fn.serializeArray=function(){var n,r,o=[];return this[0]&&i.each(this[0].elements,function(e,t){r=t.type,(n=t.name)&&"fieldset"!=t.nodeName.toLowerCase()&&!t.disabled&&"submit"!=r&&"reset"!=r&&"button"!=r&&"file"!=r&&("radio"!=r&&"checkbox"!=r||t.checked)&&function e(t){if(t.forEach)return t.forEach(e);o.push({name:n,value:t})}(i(t).val())}),o},i.fn.serialize=function(){var t=[];return this.serializeArray().forEach(function(e){t.push(encodeURIComponent(e.name)+"="+encodeURIComponent(e.value))}),t.join("&")},i.fn.submit=function(e){if(0 in arguments)this.bind("submit",e);else if(this.length){var t=i.Event("submit");this.eq(0).trigger(t),t.isDefaultPrevented()||this.get(0).submit()}return this},function(n){"__proto__"in{}||n.extend(n.zepto,{Z:function(e,t){return e=e||[],n.extend(e,n.fn),e.selector=t||"",e.__Z=!0,e},isZ:function(e){return"array"===n.type(e)&&"__Z"in e}});try{getComputedStyle(void 0)}catch(e){var t=getComputedStyle;window.getComputedStyle=function(e){try{return t(e)}catch(e){return null}}}}(r)},{}],20:[function(e,t,n){var u=e("zepto-browserify").$,c=e("chess.js").Chess,r=e("chessground").Chessground,a="4k3/8/8/8/8/8/8/4K3 w - - 0 1";function o(e,t){for(var n="",r=0;r<t;r++)n+=e;return n}function i(e,t){return e.split(t).length-1}function l(e){var t=e.fen().split(/\s+/);return t[4]="0",t[5]="1",t.join(" ")}function s(e){var r=this;this.events={},this.position=new c(e||a),this.flipped=!1,this.editMode=!1,window.addEventListener("popstate",function(e){if(e.state&&e.state.fen){var t=new c(e.state.fen);e.state.lastMove&&t.move(e.state.lastMove),r.setPosition(t)}else{location.search.substr(1).split("&").forEach(function(e){var t=e.split("=");if("fen"==t[0]){var n=decodeURIComponent(t[1]).replace(/_/g," ");r.setPosition(new c(n))}})}})}function f(n){var t=this,o=this.ground=r(document.getElementById("board"),{fen:n.position.fen(),autoCastle:!1,movable:{free:!0,color:"both",showDests:!0},selectable:{enabled:!1},draggable:{deleteOnDropOff:!0},events:{move:function(e,t){n.editMode||n.pushMove(e,t)},dropNewPiece:function(n,e){if("king"===n.role){var t=Object.keys(o.state.pieces).find(function(e){var t=o.state.pieces[e];return"king"===t.role&&t.color===n.color}),r={};t&&(r[t]=null),r[e]=n,o.setPieces(r)}},change:function(){var e=l(n.position).split(/\s/);e[0]=t.fenPart=t.ground.getFen(),n.push(new c(e.join(" ")))}}});u(".spare piece").on("touchstart mousedown",function(e){e.preventDefault(),o.dragNewPiece({color:u(this).attr("data-color"),role:u(this).attr("data-role")},e,!0)}),this.setPosition(n.position),n.bind("positionChanged",function(e){return t.setPosition(e)}),n.bind("flipped",function(e){return t.setFlipped(e)}),n.bind("editMode",function(e){o.set({movable:{showDests:!e}})})}function p(n){var t=this;u("#btn-white").click(function(e){e.preventDefault();var t=l(n.position).split(/\s/);t[1]="w",n.push(new c(t.join(" ")))}),u("#btn-black").click(function(e){e.preventDefault();var t=l(n.position).split(/\s/);t[1]="b",n.push(new c(t.join(" ")))}),this.setPosition(n.position),n.bind("positionChanged",function(e){return t.setPosition(e)})}function d(r){var t=this;function n(e){var t=e.trim().split(/[\s_]+/);""===t[0]&&(t[0]=a.split(/\s/)[0]),1===t.length&&t.push(r.position.turn()),2===t.length&&t.push("-"),3===t.length&&t.push("-"),4===t.length&&t.push("0"),5===t.length&&t.push("1");var n=new c;if(n.load(t.join(" ")))return n}var o=document.getElementById("fen");o.setCustomValidity&&(o.oninput=o.onchange=function(){o.setCustomValidity(n(o.value)?"":"Invalid FEN")}),u("#form-set-fen").submit(function(e){e.preventDefault();var t=n(o.value);t?r.push(t):o.setCustomValidity||o.focus()}),this.setPosition(r.position),r.bind("positionChanged",function(e){return t.setPosition(e)})}function h(i){u("#btn-flip-board").click(function(){return i.toggleFlipped()}),i.bind("flipped",function(e){return u("#btn-flip-board").toggleClass("active",e)}),u("#btn-clear-board").click(function(e){e.preventDefault();var t=l(i.position).split(/\s/),n=a.split(/\s/)[0]+" "+t[1]+" - - 0 1";i.push(new c(n))}),u("#btn-swap-colors").click(function(e){e.preventDefault();for(var t=l(i.position).split(/\s/),n="",r=0;r<t[0].length;r++)t[0][r]===t[0][r].toLowerCase()?n+=t[0][r].toUpperCase():n+=t[0][r].toLowerCase();t[0]=n,t[2]="-",t[3]="-",i.push(new c(t.join(" ")))}),u("#btn-mirror-horizontal").click(function(e){e.preventDefault();for(var t=l(i.position).split(/\s/),n=t[0].split(/\//),r=0;r<n.length;r++)n[r]=n[r].split("").reverse().join("");var o=n.join("/")+" "+t[1]+" - - 0 1";i.push(new c(o))}),u("#btn-mirror-vertical").click(function(e){e.preventDefault();var t=l(i.position).split(/\s/),n=t[0].split(/\//);n.reverse();var r=n.join("/")+" "+t[1]+" - - 0 1";i.push(new c(r))}),u("#btn-edit").click(function(){return i.toggleEditMode()}),i.bind("editMode",function(e){u("#btn-edit").toggleClass("active",e)})}function v(a,s){function r(e){e.click(function(e){e.preventDefault();var t=u(this).attr("data-uci"),n=u(this).attr("data-fen"),r=t.substr(0,2),o=t.substr(2,2),i=t[4];a.pushMove(r,o,i)||a.push(new c(n)),s.unsetHovering()}).mouseenter(function(){s.setHovering(u(this).attr("data-uci"))}).mouseleave(function(){return s.unsetHovering()})}r(u("a.list-group-item")),a.bind("positionChanged",function(e){u(".right-side > .inner").html('<div class="spinner"><div class="double-bounce1"></div><div class="double-bounce2"></div></div>').load("/?fen="+encodeURIComponent(l(e))+"&xhr=probe",function(e,t,n){"error"!==t?r(u("a.list-group-item")):u(".right-side > .inner").empty().append(u("<section>").append(u('<h2 id="status"></h2>').text("Network error "+n.status)).append(u('<div id="info"></div>').text(n.statusText)))})})}function g(e){e.bind("positionChanged",function(e){var t=e.fen().split(/\s/)[0];document.title=o("K",i(t,"K"))+o("Q",i(t,"Q"))+o("R",i(t,"R"))+o("B",i(t,"B"))+o("N",i(t,"N"))+o("P",i(t,"P"))+"v"+o("K",i(t,"k"))+o("Q",i(t,"q"))+o("R",i(t,"r"))+o("B",i(t,"b"))+o("N",i(t,"n"))+o("P",i(t,"p"))+" – Syzygy endgame tablebases"})}s.prototype.bind=function(e,t){this.events[e]=this.events[e]||[],this.events[e].push(t)},s.prototype.trigger=function(e){var t=this,n=arguments;(this.events[e]||[]).forEach(function(e){e.apply(t,Array.prototype.slice.call(n,1))})},s.prototype.toggleFlipped=function(){this.flipped=!this.flipped,this.trigger("flipped",this.flipped)},s.prototype.toggleEditMode=function(){this.editMode=!this.editMode,this.trigger("editMode",this.editMode)},s.prototype.push=function(e){var t=l(e);if(l(this.position)!=t&&"pushState"in history){var n=e.undo();history.pushState({fen:e.fen(),lastMove:n},null,"/?fen="+t.replace(/\s/g,"_")),n&&e.move(n)}this.setPosition(e)},s.prototype.pushMove=function(t,n,r){var e=new c(this.position.fen()),o=e.moves({verbose:!0}).filter(function(e){return e.from==t&&e.to===n&&e.promotion==r});return 1===o.length&&(e.move(o[0]),this.push(e),!0)},s.prototype.setPosition=function(e){l(this.position)!=l(e)&&(this.position=e,this.trigger("positionChanged",e))},f.prototype.setPosition=function(n){var e=n.history({verbose:!0}).map(function(e){return[e.from,e.to]}),r={};n.SQUARES.forEach(function(e){var t=n.moves({square:e,verbose:!0}).map(function(e){return e.to});t.length&&(r[e]=t)});var t="w"===n.turn()?"white":"black";this.ground.set({lastMove:e[e.length-1],fen:n.fen(),turnColor:t,check:!!n.in_check()&&t,movable:{dests:r}})},f.prototype.setFlipped=function(e){var t=e?"white":"black";t===this.ground.state.orientation&&this.ground.toggleOrientation(),u(".spare.bottom piece").attr("data-color",this.ground.state.orientation),u(".spare.bottom piece").toggleClass("white","white"===this.ground.state.orientation),u(".spare.bottom piece").toggleClass("black","black"===this.ground.state.orientation),u(".spare.top piece").attr("data-color",t),u(".spare.top piece").toggleClass("white","white"===t),u(".spare.top piece").toggleClass("black","black"===t)},f.prototype.unsetHovering=function(){this.ground.setAutoShapes([])},f.prototype.setHovering=function(e){this.ground.setAutoShapes([{orig:e.substr(0,2),dest:e.substr(2,2),brush:"green"}])},p.prototype.setPosition=function(e){u("#btn-white").toggleClass("active","w"===e.turn()),u("#btn-black").toggleClass("active","b"===e.turn())},d.prototype.setPosition=function(e){var t=l(e);u("#fen").val(t===a?"":t)},u(function(){var e=new s(u("#board").attr("data-fen")),t=new f(e);new p(e),new d(e),new h(e,t),new g(e),new v(e,t)})},{"chess.js":1,chessground:5,"zepto-browserify":19}]},{},[20]);