- ID da verificação
- 7a178435-891b-4b09-ae97-bc107b43c84eConcluído
- URL enviado:
- https://cdn.jsdelivr.net/npm/chess.js
- Relatório concluído:
Links · 0 encontrado(s)
Os links de saída identificados na página
Variáveis JavaScript · 3 encontrada(s)
Variáveis JavaScript globais carregadas no objeto janela de uma página são variáveis declaradas fora das funções e acessíveis de qualquer lugar no código dentro do escopo atual
Nome | Tipo |
---|---|
onbeforetoggle | object |
documentPictureInPicture | object |
onscrollend | object |
Mensagens de registro do console · 0 encontrada(s)
Mensagens registradas no console web
HTML
O corpo HTML bruto da página
<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/**
* Minified by jsDelivr using Terser v5.19.2.
* Original file: /npm/[email protected]/dist/cjs/chess.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
"use strict";
/**
* @license
* Copyright (c) 2023, Jeff Hlywa ([email protected])
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.Chess=exports.validateFen=exports.SQUARES=exports.DEFAULT_POSITION=exports.KING=exports.QUEEN=exports.ROOK=exports.BISHOP=exports.KNIGHT=exports.PAWN=exports.BLACK=exports.WHITE=void 0,exports.WHITE="w",exports.BLACK="b",exports.PAWN="p",exports.KNIGHT="n",exports.BISHOP="b",exports.ROOK="r",exports.QUEEN="q",exports.KING="k",exports.DEFAULT_POSITION="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";const EMPTY=-1,FLAGS={NORMAL:"n",CAPTURE:"c",BIG_PAWN:"b",EP_CAPTURE:"e",PROMOTION:"p",KSIDE_CASTLE:"k",QSIDE_CASTLE:"q"};exports.SQUARES=["a8","b8","c8","d8","e8","f8","g8","h8","a7","b7","c7","d7","e7","f7","g7","h7","a6","b6","c6","d6","e6","f6","g6","h6","a5","b5","c5","d5","e5","f5","g5","h5","a4","b4","c4","d4","e4","f4","g4","h4","a3","b3","c3","d3","e3","f3","g3","h3","a2","b2","c2","d2","e2","f2","g2","h2","a1","b1","c1","d1","e1","f1","g1","h1"];const BITS={NORMAL:1,CAPTURE:2,BIG_PAWN:4,EP_CAPTURE:8,PROMOTION:16,KSIDE_CASTLE:32,QSIDE_CASTLE:64},Ox88={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},PAWN_OFFSETS={b:[16,32,17,15],w:[-16,-32,-17,-15]},PIECE_OFFSETS={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]},ATTACKS=[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],RAYS=[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],PIECE_MASKS={p:1,n:2,b:4,r:8,q:16,k:32},SYMBOLS="pnbrqkPNBRQK",PROMOTIONS=[exports.KNIGHT,exports.BISHOP,exports.ROOK,exports.QUEEN],RANK_1=7,RANK_2=6,RANK_7=1,RANK_8=0,SIDES={[exports.KING]:BITS.KSIDE_CASTLE,[exports.QUEEN]:BITS.QSIDE_CASTLE},ROOKS={w:[{square:Ox88.a1,flag:BITS.QSIDE_CASTLE},{square:Ox88.h1,flag:BITS.KSIDE_CASTLE}],b:[{square:Ox88.a8,flag:BITS.QSIDE_CASTLE},{square:Ox88.h8,flag:BITS.KSIDE_CASTLE}]},SECOND_RANK={b:1,w:6},TERMINATION_MARKERS=["1-0","0-1","1/2-1/2","*"];function rank(t){return t>>4}function file(t){return 15&t}function isDigit(t){return-1!=="0123456789".indexOf(t)}function algebraic(t){const e=file(t),s=rank(t);return"abcdefgh".substring(e,e+1)+"87654321".substring(s,s+1)}function swapColor(t){return t===exports.WHITE?exports.BLACK:exports.WHITE}function validateFen(t){const e=t.split(/\s+/);if(6!==e.length)return{ok:!1,error:"Invalid FEN: must contain six space-delimited fields"};const s=parseInt(e[5],10);if(isNaN(s)||s<=0)return{ok:!1,error:"Invalid FEN: move number must be a positive integer"};const o=parseInt(e[4],10);if(isNaN(o)||o<0)return{ok:!1,error:"Invalid FEN: half move counter number must be a non-negative integer"};if(!/^(-|[abcdefgh][36])$/.test(e[3]))return{ok:!1,error:"Invalid FEN: en-passant square is invalid"};if(/[^kKqQ-]/.test(e[2]))return{ok:!1,error:"Invalid FEN: castling availability is invalid"};if(!/^(w|b)$/.test(e[1]))return{ok:!1,error:"Invalid FEN: side-to-move is invalid"};const r=e[0].split("/");if(8!==r.length)return{ok:!1,error:"Invalid FEN: piece data does not contain 8 '/'-delimited rows"};for(let t=0;t<r.length;t++){let e=0,s=!1;for(let o=0;o<r[t].length;o++)if(isDigit(r[t][o])){if(s)return{ok:!1,error:"Invalid FEN: piece data is invalid (consecutive number)"};e+=parseInt(r[t][o],10),s=!0}else{if(!/^[prnbqkPRNBQK]$/.test(r[t][o]))return{ok:!1,error:"Invalid FEN: piece data is invalid (invalid piece)"};e+=1,s=!1}if(8!==e)return{ok:!1,error:"Invalid FEN: piece data is invalid (too many squares in rank)"}}if("3"==e[3][1]&&"w"==e[1]||"6"==e[3][1]&&"b"==e[1])return{ok:!1,error:"Invalid FEN: illegal en-passant square"};const i=[{color:"white",regex:/K/g},{color:"black",regex:/k/g}];for(const{color:t,regex:s}of i){if(!s.test(e[0]))return{ok:!1,error:`Invalid FEN: missing ${t} king`};if((e[0].match(s)||[]).length>1)return{ok:!1,error:`Invalid FEN: too many ${t} kings`}}return Array.from(r[0]+r[7]).some((t=>"P"===t.toUpperCase()))?{ok:!1,error:"Invalid FEN: some pawns are on the edge rows"}:{ok:!0}}function getDisambiguator(t,e){const s=t.from,o=t.to,r=t.piece;let i=0,n=0,a=0;for(let t=0,h=e.length;t<h;t++){const h=e[t].from,l=e[t].to;r===e[t].piece&&s!==h&&o===l&&(i++,rank(s)===rank(h)&&n++,file(s)===file(h)&&a++)}return i>0?n>0&&a>0?algebraic(s):a>0?algebraic(s).charAt(1):algebraic(s).charAt(0):""}function addMove(t,e,s,o,r,i=void 0,n=BITS.NORMAL){const a=rank(o);if(r!==exports.PAWN||7!==a&&0!==a)t.push({color:e,from:s,to:o,piece:r,captured:i,flags:n});else for(let a=0;a<PROMOTIONS.length;a++){const h=PROMOTIONS[a];t.push({color:e,from:s,to:o,piece:r,captured:i,promotion:h,flags:n|BITS.PROMOTION})}}function inferPieceType(t){let e=t.charAt(0);if(e>="a"&&e<="h"){if(t.match(/[a-h]\d.*[a-h]\d/))return;return exports.PAWN}return e=e.toLowerCase(),"o"===e?exports.KING:e}function strippedSan(t){return t.replace(/=/,"").replace(/[+#]?[?!]*$/,"")}function trimFen(t){return t.split(" ").slice(0,4).join(" ")}exports.validateFen=validateFen;class Chess{_board=new Array(128);_turn=exports.WHITE;_header={};_kings={w:-1,b:-1};_epSquare=-1;_halfMoves=0;_moveNumber=0;_history=[];_comments={};_castling={w:0,b:0};_positionCount={};constructor(t=exports.DEFAULT_POSITION){this.load(t)}clear({preserveHeaders:t=!1}={}){this._board=new Array(128),this._kings={w:-1,b:-1},this._turn=exports.WHITE,this._castling={w:0,b:0},this._epSquare=-1,this._halfMoves=0,this._moveNumber=1,this._history=[],this._comments={},this._header=t?this._header:{},this._positionCount={},delete this._header.SetUp,delete this._header.FEN}removeHeader(t){t in this._header&&delete this._header[t]}load(t,{skipValidation:e=!1,preserveHeaders:s=!1}={}){let o=t.split(/\s+/);if(o.length>=2&&o.length<6){const e=["-","-","0","1"];t=o.concat(e.slice(-(6-o.length))).join(" ")}if(o=t.split(/\s+/),!e){const{ok:e,error:s}=validateFen(t);if(!e)throw new Error(s)}const r=o[0];let i=0;this.clear({preserveHeaders:s});for(let t=0;t<r.length;t++){const e=r.charAt(t);if("/"===e)i+=8;else if(isDigit(e))i+=parseInt(e,10);else{const t=e<"a"?exports.WHITE:exports.BLACK;this._put({type:e.toLowerCase(),color:t},algebraic(i)),i++}}this._turn=o[1],o[2].indexOf("K")>-1&&(this._castling.w|=BITS.KSIDE_CASTLE),o[2].indexOf("Q")>-1&&(this._castling.w|=BITS.QSIDE_CASTLE),o[2].indexOf("k")>-1&&(this._castling.b|=BITS.KSIDE_CASTLE),o[2].indexOf("q")>-1&&(this._castling.b|=BITS.QSIDE_CASTLE),this._epSquare="-"===o[3]?-1:Ox88[o[3]],this._halfMoves=parseInt(o[4],10),this._moveNumber=parseInt(o[5],10),this._updateSetup(t),this._incPositionCount(t)}fen(){let t=0,e="";for(let s=Ox88.a8;s<=Ox88.h1;s++){if(this._board[s]){t>0&&(e+=t,t=0);const{color:o,type:r}=this._board[s];e+=o===exports.WHITE?r.toUpperCase():r.toLowerCase()}else t++;s+1&136&&(t>0&&(e+=t),s!==Ox88.h1&&(e+="/"),t=0,s+=8)}let s="";this._castling[exports.WHITE]&BITS.KSIDE_CASTLE&&(s+="K"),this._castling[exports.WHITE]&BITS.QSIDE_CASTLE&&(s+="Q"),this._castling[exports.BLACK]&BITS.KSIDE_CASTLE&&(s+="k"),this._castling[exports.BLACK]&BITS.QSIDE_CASTLE&&(s+="q"),s=s||"-";let o="-";if(-1!==this._epSquare){const t=this._epSquare+(this._turn===exports.WHITE?16:-16),e=[t+1,t-1];for(const t of e){if(136&t)continue;const e=this._turn;if(this._board[t]?.color===e&&this._board[t]?.type===exports.PAWN){this._makeMove({color:e,from:t,to:this._epSquare,piece:exports.PAWN,captured:exports.PAWN,flags:BITS.EP_CAPTURE});const s=!this._isKingAttacked(e);if(this._undoMove(),s){o=algebraic(this._epSquare);break}}}}return[e,this._turn,s,o,this._halfMoves,this._moveNumber].join(" ")}_updateSetup(t){this._history.length>0||(t!==exports.DEFAULT_POSITION?(this._header.SetUp="1",this._header.FEN=t):(delete this._header.SetUp,delete this._header.FEN))}reset(){this.load(exports.DEFAULT_POSITION)}get(t){return this._board[Ox88[t]]||!1}put({type:t,color:e},s){return!!this._put({type:t,color:e},s)&&(this._updateCastlingRights(),this._updateEnPassantSquare(),this._updateSetup(this.fen()),!0)}_put({type:t,color:e},s){if(-1===SYMBOLS.indexOf(t.toLowerCase()))return!1;if(!(s in Ox88))return!1;const o=Ox88[s];if(t==exports.KING&&-1!=this._kings[e]&&this._kings[e]!=o)return!1;const r=this._board[o];return r&&r.type===exports.KING&&(this._kings[r.color]=-1),this._board[o]={type:t,color:e},t===exports.KING&&(this._kings[e]=o),!0}remove(t){const e=this.get(t);return delete this._board[Ox88[t]],e&&e.type===exports.KING&&(this._kings[e.color]=-1),this._updateCastlingRights(),this._updateEnPassantSquare(),this._updateSetup(this.fen()),e}_updateCastlingRights(){const t=this._board[Ox88.e1]?.type===exports.KING&&this._board[Ox88.e1]?.color===exports.WHITE,e=this._board[Ox88.e8]?.type===exports.KING&&this._board[Ox88.e8]?.color===exports.BLACK;t&&this._board[Ox88.a1]?.type===exports.ROOK&&this._board[Ox88.a1]?.color===exports.WHITE||(this._castling.w&=~BITS.QSIDE_CASTLE),t&&this._board[Ox88.h1]?.type===exports.ROOK&&this._board[Ox88.h1]?.color===exports.WHITE||(this._castling.w&=~BITS.KSIDE_CASTLE),e&&this._board[Ox88.a8]?.type===exports.ROOK&&this._board[Ox88.a8]?.color===exports.BLACK||(this._castling.b&=~BITS.QSIDE_CASTLE),e&&this._board[Ox88.h8]?.type===exports.ROOK&&this._board[Ox88.h8]?.color===exports.BLACK||(this._castling.b&=~BITS.KSIDE_CASTLE)}_updateEnPassantSquare(){if(-1===this._epSquare)return;const t=this._epSquare+(this._turn===exports.WHITE?-16:16),e=this._epSquare+(this._turn===exports.WHITE?16:-16),s=[e+1,e-1];if(null!==this._board[t]||null!==this._board[this._epSquare]||this._board[e]?.color!==swapColor(this._turn)||this._board[e]?.type!==exports.PAWN)return void(this._epSquare=-1);s.some((t=>!(136&t)&&this._board[t]?.color===this._turn&&this._board[t]?.type===exports.PAWN))||(this._epSquare=-1)}_attacked(t,e){for(let s=Ox88.a8;s<=Ox88.h1;s++){if(136&s){s+=7;continue}if(void 0===this._board[s]||this._board[s].color!==t)continue;const o=this._board[s],r=s-e;if(0===r)continue;const i=r+119;if(ATTACKS[i]&PIECE_MASKS[o.type]){if(o.type===exports.PAWN){if(r>0){if(o.color===exports.WHITE)return!0}else if(o.color===exports.BLACK)return!0;continue}if("n"===o.type||"k"===o.type)return!0;const t=RAYS[i];let n=s+t,a=!1;for(;n!==e;){if(null!=this._board[n]){a=!0;break}n+=t}if(!a)return!0}}return!1}_isKingAttacked(t){const e=this._kings[t];return-1!==e&&this._attacked(swapColor(t),e)}isAttacked(t,e){return this._attacked(e,Ox88[t])}isCheck(){return this._isKingAttacked(this._turn)}inCheck(){return this.isCheck()}isCheckmate(){return this.isCheck()&&0===this._moves().length}isStalemate(){return!this.isCheck()&&0===this._moves().length}isInsufficientMaterial(){const t={b:0,n:0,r:0,q:0,k:0,p:0},e=[];let s=0,o=0;for(let r=Ox88.a8;r<=Ox88.h1;r++){if(o=(o+1)%2,136&r){r+=7;continue}const i=this._board[r];i&&(t[i.type]=i.type in t?t[i.type]+1:1,i.type===exports.BISHOP&&e.push(o),s++)}if(2===s)return!0;if(3===s&&(1===t[exports.BISHOP]||1===t[exports.KNIGHT]))return!0;if(s===t[exports.BISHOP]+2){let t=0;const s=e.length;for(let o=0;o<s;o++)t+=e[o];if(0===t||t===s)return!0}return!1}isThreefoldRepetition(){return this._getPositionCount(this.fen())>=3}isDraw(){return this._halfMoves>=100||this.isStalemate()||this.isInsufficientMaterial()||this.isThreefoldRepetition()}isGameOver(){return this.isCheckmate()||this.isStalemate()||this.isDraw()}moves({verbose:t=!1,square:e,piece:s}={}){const o=this._moves({square:e,piece:s});return t?o.map((t=>this._makePretty(t))):o.map((t=>this._moveToSan(t,o)))}_moves({legal:t=!0,piece:e,square:s}={}){const o=s?s.toLowerCase():void 0,r=e?.toLowerCase(),i=[],n=this._turn,a=swapColor(n);let h=Ox88.a8,l=Ox88.h1,p=!1;if(o){if(!(o in Ox88))return[];h=l=Ox88[o],p=!0}for(let t=h;t<=l;t++){if(136&t){t+=7;continue}if(!this._board[t]||this._board[t].color===a)continue;const{type:e}=this._board[t];let s;if(e===exports.PAWN){if(r&&r!==e)continue;s=t+PAWN_OFFSETS[n][0],this._board[s]||(addMove(i,n,t,s,exports.PAWN),s=t+PAWN_OFFSETS[n][1],SECOND_RANK[n]!==rank(t)||this._board[s]||addMove(i,n,t,s,exports.PAWN,void 0,BITS.BIG_PAWN));for(let e=2;e<4;e++)s=t+PAWN_OFFSETS[n][e],136&s||(this._board[s]?.color===a?addMove(i,n,t,s,exports.PAWN,this._board[s].type,BITS.CAPTURE):s===this._epSquare&&addMove(i,n,t,s,exports.PAWN,exports.PAWN,BITS.EP_CAPTURE))}else{if(r&&r!==e)continue;for(let o=0,r=PIECE_OFFSETS[e].length;o<r;o++){const r=PIECE_OFFSETS[e][o];for(s=t;s+=r,!(136&s);){if(this._board[s]){if(this._board[s].color===n)break;addMove(i,n,t,s,e,this._board[s].type,BITS.CAPTURE);break}if(addMove(i,n,t,s,e),e===exports.KNIGHT||e===exports.KING)break}}}}if(!(void 0!==r&&r!==exports.KING||p&&l!==this._kings[n])){if(this._castling[n]&BITS.KSIDE_CASTLE){const t=this._kings[n],e=t+2;this._board[t+1]||this._board[e]||this._attacked(a,this._kings[n])||this._attacked(a,t+1)||this._attacked(a,e)||addMove(i,n,this._kings[n],e,exports.KING,void 0,BITS.KSIDE_CASTLE)}if(this._castling[n]&BITS.QSIDE_CASTLE){const t=this._kings[n],e=t-2;this._board[t-1]||this._board[t-2]||this._board[t-3]||this._attacked(a,this._kings[n])||this._attacked(a,t-1)||this._attacked(a,e)||addMove(i,n,this._kings[n],e,exports.KING,void 0,BITS.QSIDE_CASTLE)}}if(!t||-1===this._kings[n])return i;const _=[];for(let t=0,e=i.length;t<e;t++)this._makeMove(i[t]),this._isKingAttacked(n)||_.push(i[t]),this._undoMove();return _}move(t,{strict:e=!1}={}){let s=null;if("string"==typeof t)s=this._moveFromSan(t,e);else if("object"==typeof t){const e=this._moves();for(let o=0,r=e.length;o<r;o++)if(t.from===algebraic(e[o].from)&&t.to===algebraic(e[o].to)&&(!("promotion"in e[o])||t.promotion===e[o].promotion)){s=e[o];break}}if(!s)throw"string"==typeof t?new Error(`Invalid move: ${t}`):new Error(`Invalid move: ${JSON.stringify(t)}`);const o=this._makePretty(s);return this._makeMove(s),this._incPositionCount(o.after),o}_push(t){this._history.push({move:t,kings:{b:this._kings.b,w:this._kings.w},turn:this._turn,castling:{b:this._castling.b,w:this._castling.w},epSquare:this._epSquare,halfMoves:this._halfMoves,moveNumber:this._moveNumber})}_makeMove(t){const e=this._turn,s=swapColor(e);if(this._push(t),this._board[t.to]=this._board[t.from],delete this._board[t.from],t.flags&BITS.EP_CAPTURE&&(this._turn===exports.BLACK?delete this._board[t.to-16]:delete this._board[t.to+16]),t.promotion&&(this._board[t.to]={type:t.promotion,color:e}),this._board[t.to].type===exports.KING){if(this._kings[e]=t.to,t.flags&BITS.KSIDE_CASTLE){const e=t.to-1,s=t.to+1;this._board[e]=this._board[s],delete this._board[s]}else if(t.flags&BITS.QSIDE_CASTLE){const e=t.to+1,s=t.to-2;this._board[e]=this._board[s],delete this._board[s]}this._castling[e]=0}if(this._castling[e])for(let s=0,o=ROOKS[e].length;s<o;s++)if(t.from===ROOKS[e][s].square&&this._castling[e]&ROOKS[e][s].flag){this._castling[e]^=ROOKS[e][s].flag;break}if(this._castling[s])for(let e=0,o=ROOKS[s].length;e<o;e++)if(t.to===ROOKS[s][e].square&&this._castling[s]&ROOKS[s][e].flag){this._castling[s]^=ROOKS[s][e].flag;break}t.flags&BITS.BIG_PAWN?e===exports.BLACK?this._epSquare=t.to-16:this._epSquare=t.to+16:this._epSquare=-1,t.piece===exports.PAWN||t.flags&(BITS.CAPTURE|BITS.EP_CAPTURE)?this._halfMoves=0:this._halfMoves++,e===exports.BLACK&&this._moveNumber++,this._turn=s}undo(){const t=this._undoMove();if(t){const e=this._makePretty(t);return this._decPositionCount(e.after),e}return null}_undoMove(){const t=this._history.pop();if(void 0===t)return null;const e=t.move;this._kings=t.kings,this._turn=t.turn,this._castling=t.castling,this._epSquare=t.epSquare,this._halfMoves=t.halfMoves,this._moveNumber=t.moveNumber;const s=this._turn,o=swapColor(s);if(this._board[e.from]=this._board[e.to],this._board[e.from].type=e.piece,delete this._board[e.to],e.captured)if(e.flags&BITS.EP_CAPTURE){let t;t=s===exports.BLACK?e.to-16:e.to+16,this._board[t]={type:exports.PAWN,color:o}}else this._board[e.to]={type:e.captured,color:o};if(e.flags&(BITS.KSIDE_CASTLE|BITS.QSIDE_CASTLE)){let t,s;e.flags&BITS.KSIDE_CASTLE?(t=e.to+1,s=e.to-1):(t=e.to-2,s=e.to+1),this._board[t]=this._board[s],delete this._board[s]}return e}pgn({newline:t="\n",maxWidth:e=0}={}){const s=[];let o=!1;for(const e in this._header)s.push("["+e+' "'+this._header[e]+'"]'+t),o=!0;o&&this._history.length&&s.push(t);const r=t=>{const e=this._comments[this.fen()];if(void 0!==e){t=`${t}${t.length>0?" ":""}{${e}}`}return t},i=[];for(;this._history.length>0;)i.push(this._undoMove());const n=[];let a="";for(0===i.length&&n.push(r(""));i.length>0;){a=r(a);const t=i.pop();if(!t)break;if(this._history.length||"b"!==t.color)"w"===t.color&&(a.length&&n.push(a),a=this._moveNumber+".");else{const t=`${this._moveNumber}. ...`;a=a?`${a} ${t}`:t}a=a+" "+this._moveToSan(t,this._moves({legal:!0})),this._makeMove(t)}if(a.length&&n.push(r(a)),void 0!==this._header.Result&&n.push(this._header.Result),0===e)return s.join("")+n.join(" ");const h=function(){return s.length>0&&" "===s[s.length-1]&&(s.pop(),!0)},l=function(o,r){for(const i of r.split(" "))if(i){if(o+i.length>e){for(;h();)o--;s.push(t),o=0}s.push(i),o+=i.length,s.push(" "),o++}return h()&&o--,o};let p=0;for(let o=0;o<n.length;o++)p+n[o].length>e&&n[o].includes("{")?p=l(p,n[o]):(p+n[o].length>e&&0!==o?(" "===s[s.length-1]&&s.pop(),s.push(t),p=0):0!==o&&(s.push(" "),p++),s.push(n[o]),p+=n[o].length);return s.join("")}header(...t){for(let e=0;e<t.length;e+=2)"string"==typeof t[e]&&"string"==typeof t[e+1]&&(this._header[t[e]]=t[e+1]);return this._header}loadPgn(t,{strict:e=!1,newlineChar:s="\r?\n"}={}){function o(t){return t.replace(/\\/g,"\\")}t=t.trim();const r=new RegExp("^(\\[((?:"+o(s)+")|.)*\\])((?:\\s*"+o(s)+"){2}|(?:\\s*"+o(s)+")*$)").exec(t),i=r&&r.length>=2?r[1]:"";this.reset();const n=function(t){const e={},r=t.split(new RegExp(o(s)));let i="",n="";for(let t=0;t<r.length;t++){const s=/^\s*\[\s*([A-Za-z]+)\s*"(.*)"\s*\]\s*$/;i=r[t].replace(s,"$1"),n=r[t].replace(s,"$2"),i.trim().length>0&&(e[i]=n)}return e}(i);let a="";for(const t in n)"fen"===t.toLowerCase()&&(a=n[t]),this.header(t,n[t]);if(e){if("1"===n.SetUp){if(!("FEN"in n))throw new Error("Invalid PGN: FEN tag must be supplied with SetUp tag");this.load(n.FEN,{preserveHeaders:!0})}}else a&&this.load(a,{preserveHeaders:!0});const h=function(t){return`{${function(t){return Array.from(t).map((function(t){return t.charCodeAt(0)<128?t.charCodeAt(0).toString(16):encodeURIComponent(t).replace(/%/g,"").toLowerCase()})).join("")}((t=t.replace(new RegExp(o(s),"g")," ")).slice(1,t.length-1))}}`},l=function(t){if(t.startsWith("{")&&t.endsWith("}"))return function(t){return 0==t.length?"":decodeURIComponent("%"+(t.match(/.{1,2}/g)||[]).join("%"))}(t.slice(1,t.length-1))};let p=t.replace(i,"").replace(new RegExp(`({[^}]*})+?|;([^${o(s)}]*)`,"g"),(function(t,e,s){return void 0!==e?h(e):" "+h(`{${s.slice(1)}}`)})).replace(new RegExp(o(s),"g")," ");const _=/(\([^()]+\))+?/g;for(;_.test(p);)p=p.replace(_,"");p=p.replace(/\d+\.(\.\.)?/g,""),p=p.replace(/\.\.\./g,""),p=p.replace(/\$\d+/g,"");let c=p.trim().split(new RegExp(/\s+/));c=c.filter((t=>""!==t));let u="";for(let t=0;t<c.length;t++){const s=l(c[t]);if(void 0!==s){this._comments[this.fen()]=s;continue}const o=this._moveFromSan(c[t],e);if(null==o){if(!(TERMINATION_MARKERS.indexOf(c[t])>-1))throw new Error(`Invalid move in PGN: ${c[t]}`);u=c[t]}else u="",this._makeMove(o),this._incPositionCount(this.fen())}u&&Object.keys(this._header).length&&!this._header.Result&&this.header("Result",u)}_moveToSan(t,e){let s="";if(t.flags&BITS.KSIDE_CASTLE)s="O-O";else if(t.flags&BITS.QSIDE_CASTLE)s="O-O-O";else{if(t.piece!==exports.PAWN){const o=getDisambiguator(t,e);s+=t.piece.toUpperCase()+o}t.flags&(BITS.CAPTURE|BITS.EP_CAPTURE)&&(t.piece===exports.PAWN&&(s+=algebraic(t.from)[0]),s+="x"),s+=algebraic(t.to),t.promotion&&(s+="="+t.promotion.toUpperCase())}return this._makeMove(t),this.isCheck()&&(this.isCheckmate()?s+="#":s+="+"),this._undoMove(),s}_moveFromSan(t,e=!1){const s=strippedSan(t);let o,r,i,n,a,h=inferPieceType(s),l=this._moves({legal:!0,piece:h});for(let t=0,e=l.length;t<e;t++)if(s===strippedSan(this._moveToSan(l[t],l)))return l[t];if(e)return null;let p=!1;if(r=s.match(/([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/),r?(o=r[1],i=r[2],n=r[3],a=r[4],1==i.length&&(p=!0)):(r=s.match(/([pnbrqkPNBRQK])?([a-h]?[1-8]?)x?-?([a-h][1-8])([qrbnQRBN])?/),r&&(o=r[1],i=r[2],n=r[3],a=r[4],1==i.length&&(p=!0))),h=inferPieceType(s),l=this._moves({legal:!0,piece:o||h}),!n)return null;for(let t=0,e=l.length;t<e;t++)if(i){if(!(o&&o.toLowerCase()!=l[t].piece||Ox88[i]!=l[t].from||Ox88[n]!=l[t].to||a&&a.toLowerCase()!=l[t].promotion))return l[t];if(p){const e=algebraic(l[t].from);if(!(o&&o.toLowerCase()!=l[t].piece||Ox88[n]!=l[t].to||i!=e[0]&&i!=e[1]||a&&a.toLowerCase()!=l[t].promotion))return l[t]}}else if(s===strippedSan(this._moveToSan(l[t],l)).replace("x",""))return l[t];return null}ascii(){let t=" +------------------------+\n";for(let e=Ox88.a8;e<=Ox88.h1;e++){if(0===file(e)&&(t+=" "+"87654321"[rank(e)]+" |"),this._board[e]){const s=this._board[e].type;t+=" "+(this._board[e].color===exports.WHITE?s.toUpperCase():s.toLowerCase())+" "}else t+=" . ";e+1&136&&(t+="|\n",e+=8)}return t+=" +------------------------+\n",t+=" a b c d e f g h",t}perft(t){const e=this._moves({legal:!1});let s=0;const o=this._turn;for(let r=0,i=e.length;r<i;r++)this._makeMove(e[r]),this._isKingAttacked(o)||(t-1>0?s+=this.perft(t-1):s++),this._undoMove();return s}_makePretty(t){const{color:e,piece:s,from:o,to:r,flags:i,captured:n,promotion:a}=t;let h="";for(const t in BITS)BITS[t]&i&&(h+=FLAGS[t]);const l=algebraic(o),p=algebraic(r),_={color:e,piece:s,from:l,to:p,san:this._moveToSan(t,this._moves({legal:!0})),flags:h,lan:l+p,before:this.fen(),after:""};return this._makeMove(t),_.after=this.fen(),this._undoMove(),n&&(_.captured=n),a&&(_.promotion=a,_.lan+=a),_}turn(){return this._turn}board(){const t=[];let e=[];for(let s=Ox88.a8;s<=Ox88.h1;s++)null==this._board[s]?e.push(null):e.push({square:algebraic(s),type:this._board[s].type,color:this._board[s].color}),s+1&136&&(t.push(e),e=[],s+=8);return t}squareColor(t){if(t in Ox88){const e=Ox88[t];return(rank(e)+file(e))%2==0?"light":"dark"}return null}history({verbose:t=!1}={}){const e=[],s=[];for(;this._history.length>0;)e.push(this._undoMove());for(;;){const o=e.pop();if(!o)break;t?s.push(this._makePretty(o)):s.push(this._moveToSan(o,this._moves())),this._makeMove(o)}return s}_getPositionCount(t){const e=trimFen(t);return this._positionCount[e]||0}_incPositionCount(t){const e=trimFen(t);void 0===this._positionCount[e]&&(this._positionCount[e]=0),this._positionCount[e]+=1}_decPositionCount(t){const e=trimFen(t);1===this._positionCount[e]?delete this._positionCount[e]:this._positionCount[e]-=1}_pruneComments(){const t=[],e={},s=t=>{t in this._comments&&(e[t]=this._comments[t])};for(;this._history.length>0;)t.push(this._undoMove());for(s(this.fen());;){const e=t.pop();if(!e)break;this._makeMove(e),s(this.fen())}this._comments=e}getComment(){return this._comments[this.fen()]}setComment(t){this._comments[this.fen()]=t.replace("{","[").replace("}","]")}deleteComment(){const t=this._comments[this.fen()];return delete this._comments[this.fen()],t}getComments(){return this._pruneComments(),Object.keys(this._comments).map((t=>({fen:t,comment:this._comments[t]})))}deleteComments(){return this._pruneComments(),Object.keys(this._comments).map((t=>{const e=this._comments[t];return delete this._comments[t],{fen:t,comment:e}}))}setCastlingRights(t,e){for(const s of[exports.KING,exports.QUEEN])void 0!==e[s]&&(e[s]?this._castling[t]|=SIDES[s]:this._castling[t]&=~SIDES[s]);this._updateCastlingRights();const s=this.getCastlingRights(t);return!(void 0!==e[exports.KING]&&e[exports.KING]!==s[exports.KING]||void 0!==e[exports.QUEEN]&&e[exports.QUEEN]!==s[exports.QUEEN])}getCastlingRights(t){return{[exports.KING]:0!=(this._castling[t]&SIDES[exports.KING]),[exports.QUEEN]:0!=(this._castling[t]&SIDES[exports.QUEEN])}}moveNumber(){return this._moveNumber}}exports.Chess=Chess;
//# sourceMappingURL=/sm/69881c8bff6b0f37a66684c058fbc23a5013f9afcfa3de6ada9cb22532fe8b05.map</pre></body></html>