X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=e405cbaa4e595da56210f09a7e0920c27c406be1;hp=5763af7e1d0f86e40789ff7c9467ce66a3bd1334;hb=b6487fb9c41705187cf97215fc9e8f86a59057c7;hpb=7931e479adf93c87771ded1892a0873af72ae46d diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 5763af7e..e405cbaa 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -31,92 +31,61 @@ class Move // NOTE: x coords = top to bottom; y = left to right (from white player perspective) class ChessRules { + ////////////// + // MISC UTILS + + static get HasFlags() { return true; } //some variants don't have flags + + static get HasEnpassant() { return true; } //some variants don't have ep. + // Path to pieces static getPpath(b) { return b; //usual pieces in pieces/ folder } + // Turn "wb" into "B" (for FEN) static board2fen(b) { return b[0]=='w' ? b[1].toUpperCase() : b[1]; } + // Turn "p" into "bp" (for board) static fen2board(f) { return f.charCodeAt()<=90 ? "w"+f.toLowerCase() : "b"+f; } - ///////////////// - // INITIALIZATION - - // fen == "position flags" - constructor(fen, moves) - { - this.moves = moves; - // Use fen string to initialize variables, flags, turn and board - const fenParts = fen.split(" "); - this.board = V.GetBoard(fenParts[0]); - this.setFlags(fenParts[1]); //NOTE: fenParts[1] might be undefined - this.setTurn(fenParts[2]); //Same note - this.initVariables(fen); - } - - // Some additional variables from FEN (variant dependant) - initVariables(fen) + // Check if FEN describe a position + static IsGoodFen(fen) { - this.INIT_COL_KING = {'w':-1, 'b':-1}; - this.INIT_COL_ROOK = {'w':[-1,-1], 'b':[-1,-1]}; - this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; //squares of white and black king - const fenParts = fen.split(" "); - const position = fenParts[0].split("/"); - for (let i=0; i= 0)) + return false; + // 4) Check flags + if (V.HasFlags && (!fenParsed.flags || !V.IsGoodFlags(fenParsed.flags))) + return false; + // 5) Check enpassant + if (V.HasEnpassant && + (!fenParsed.enpassant || !V.IsGoodEnpassant(fenParsed.enpassant))) { - let k = 0; //column index on board - for (let j=0; j 0 ? this.getEpSquare(this.lastMove) : undefined); - this.epSquares = [ epSq ]; + return true; } - // Check if FEN describe a position - static IsGoodFen(fen) + // Is position part of the FEN a priori correct? + static IsGoodPosition(position) { - const fenParts = fen.split(" "); - if (fenParts.length== 0 || fenParts.length > 3) + if (position.length == 0) return false; - // 1) Check position - const position = fenParts[0]; const rows = position.split("/"); if (rows.length != V.size.x) return false; @@ -138,31 +107,273 @@ class ChessRules if (sumElts != V.size.y) return false; } - // 2) Check flags (if present) - if (fenParts.length >= 2) + return true; + } + + // For FEN checking + static IsGoodTurn(turn) + { + return ["w","b"].includes(turn); + } + + // For FEN checking + static IsGoodFlags(flags) + { + return !!flags.match(/^[01]{4,4}$/); + } + + static IsGoodEnpassant(enpassant) + { + if (enpassant != "-") { - if (!V.IsGoodFlags(fenParts[1])) + const ep = V.SquareToCoords(fenParsed.enpassant); + if (isNaN(ep.x) || !V.OnBoard(ep)) return false; } - // 3) Check turn (if present) - if (fenParts.length == 3) + return true; + } + + // 3 --> d (column number to letter) + static CoordToColumn(colnum) + { + return String.fromCharCode(97 + colnum); + } + + // d --> 3 (column letter to number) + static ColumnToCoord(column) + { + return column.charCodeAt(0) - 97; + } + + // a4 --> {x:3,y:0} + static SquareToCoords(sq) + { + return { + // NOTE: column is always one char => max 26 columns + // row is counted from black side => subtraction + x: V.size.x - parseInt(sq.substr(1)), + y: sq[0].charCodeAt() - 97 + }; + } + + // {x:0,y:4} --> e8 + static CoordsToSquare(coords) + { + return V.CoordToColumn(coords.y) + (V.size.x - coords.x); + } + + // Aggregates flags into one object + aggregateFlags() + { + return this.castleFlags; + } + + // Reverse operation + disaggregateFlags(flags) + { + this.castleFlags = flags; + } + + // En-passant square, if any + getEpSquare(moveOrSquare) + { + if (!moveOrSquare) + return undefined; + if (typeof moveOrSquare === "string") { - if (!["w","b"].includes(fenParts[2])) - return false; + const square = moveOrSquare; + if (square == "-") + return undefined; + return V.SquareToCoords(square); } - return true; + // Argument is a move: + const move = moveOrSquare; + const [sx,sy,ex] = [move.start.x,move.start.y,move.end.x]; + // TODO: next conditions are first for Atomic, and third for Checkered + if (move.appear.length > 0 && move.appear[0].p == V.PAWN && ["w","b"].includes(move.appear[0].c) && Math.abs(sx - ex) == 2) + { + return { + x: (sx + ex)/2, + y: sy + }; + } + return undefined; //default } - // For FEN checking - static IsGoodFlags(flags) + // Can thing on square1 take thing on square2 + canTake([x1,y1], [x2,y2]) { - return !!flags.match(/^[01]{4,4}$/); + return this.getColor(x1,y1) !== this.getColor(x2,y2); } - // Turn diagram fen into double array ["wb","wp","bk",...] - static GetBoard(fen) + // Is (x,y) on the chessboard? + static OnBoard(x,y) + { + return (x>=0 && x=0 && y 0) + { + // Add empty squares in-between + position += emptyCount; + emptyCount = 0; + } + position += V.board2fen(this.board[i][j]); + } + } + if (emptyCount > 0) + { + // "Flush remainder" + position += emptyCount; + } + if (i < V.size.x - 1) + position += "/"; //separate rows + } + return position; + } + + getTurnFen() + { + return this.turn; + } + + // Flags part of the FEN string + getFlagsFen() + { + let flags = ""; + // Add castling flags + for (let i of ['w','b']) + { + for (let j=0; j<2; j++) + flags += (this.castleFlags[i][j] ? '1' : '0'); + } + return flags; + } + + // Enpassant part of the FEN string + getEnpassantFen() + { + const L = this.epSquares.length; + if (!this.epSquares[L-1]) + return "-"; //no en-passant + return V.CoordsToSquare(this.epSquares[L-1]); + } + + // Turn position fen into double array ["wb","wp","bk",...] + static GetBoard(position) + { + const rows = position.split("/"); let board = doubleArray(V.size.x, V.size.y, ""); for (let i=0; i0 ? this.moves[L-1] : null); + // Get opponent color + getOppCol(color) + { + return (color=="w" ? "b" : "w"); } - // Pieces codes + // Pieces codes (for a clearer code) static get PAWN() { return 'p'; } static get ROOK() { return 'r'; } static get KNIGHT() { return 'n'; } @@ -223,15 +512,17 @@ class ChessRules static get KING() { return 'k'; } // For FEN checking: - static get PIECES() { + static get PIECES() + { return [V.PAWN,V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN,V.KING]; } // Empty square - static get EMPTY() { return ''; } + static get EMPTY() { return ""; } // Some pieces movements - static get steps() { + static get steps() + { return { 'r': [ [-1,0],[1,0],[0,-1],[0,1] ], 'n': [ [-1,-2],[-1,2],[1,-2],[1,2],[-2,-1],[-2,1],[2,-1],[2,1] ], @@ -239,38 +530,7 @@ class ChessRules }; } - // Aggregates flags into one object - get flags() { - return this.castleFlags; - } - - // Reverse operation - parseFlags(flags) - { - this.castleFlags = flags; - } - - // En-passant square, if any - getEpSquare(move) - { - const [sx,sy,ex] = [move.start.x,move.start.y,move.end.x]; - if (this.getPiece(sx,sy) == V.PAWN && Math.abs(sx - ex) == 2) - { - return { - x: (sx + ex)/2, - y: sy - }; - } - return undefined; //default - } - - // Can thing on square1 take thing on square2 - canTake([x1,y1], [x2,y2]) - { - return this.getColor(x1,y1) !== this.getColor(x2,y2); - } - - /////////////////// + //////////////////// // MOVES GENERATION // All possible moves from selected square (assumption: color is OK) @@ -293,7 +553,8 @@ class ChessRules } } - // Build a regular move from its initial and destination squares; tr: transformation + // Build a regular move from its initial and destination squares. + // tr: transformation getBasicMove([sx,sy], [ex,ey], tr) { let mv = new Move({ @@ -330,13 +591,8 @@ class ChessRules return mv; } - // Is (x,y) on the chessboard? - static OnBoard(x,y) - { - return (x>=0 && x=0 && y= 0 && x+shift < sizeX && x+shift != lastRank) + // NOTE: next condition is generally true (no pawn on last rank) + if (x+shiftX >= 0 && x+shiftX < sizeX) { - // Normal moves - if (this.board[x+shift][y] == V.EMPTY) + const finalPieces = x + shiftX == lastRank + ? [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN] + : [V.PAWN] + // One square forward + if (this.board[x+shiftX][y] == V.EMPTY) { - moves.push(this.getBasicMove([x,y], [x+shift,y])); - // Next condition because variants with pawns on 1st rank allow them to jump - if ([startRank,firstRank].includes(x) && this.board[x+2*shift][y] == V.EMPTY) + for (let piece of finalPieces) + { + moves.push(this.getBasicMove([x,y], [x+shiftX,y], + {c:pawnColor,p:piece})); + } + // Next condition because pawns on 1st rank can generally jump + if ([startRank,firstRank].includes(x) + && this.board[x+2*shiftX][y] == V.EMPTY) { // Two squares jump - moves.push(this.getBasicMove([x,y], [x+2*shift,y])); + moves.push(this.getBasicMove([x,y], [x+2*shiftX,y])); } } // Captures - if (y>0 && this.board[x+shift][y-1] != V.EMPTY - && this.canTake([x,y], [x+shift,y-1])) + for (let shiftY of [-1,1]) { - moves.push(this.getBasicMove([x,y], [x+shift,y-1])); - } - if (y { - // Normal move - if (this.board[x+shift][y] == V.EMPTY) - moves.push(this.getBasicMove([x,y], [x+shift,y], {c:pawnColor,p:p})); - // Captures - if (y>0 && this.board[x+shift][y-1] != V.EMPTY - && this.canTake([x,y], [x+shift,y-1])) + if (y + shiftY >= 0 && y + shiftY < sizeY + && this.board[x+shiftX][y+shiftY] != V.EMPTY + && this.canTake([x,y], [x+shiftX,y+shiftY])) { - moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:pawnColor,p:p})); - } - if (y0 ? this.epSquares[Lep-1] : undefined); - if (!!epSquare && epSquare.x == x+shift && Math.abs(epSquare.y - y) == 1) + if (V.HasEnpassant) { - const epStep = epSquare.y - y; - let enpassantMove = this.getBasicMove([x,y], [x+shift,y+epStep]); - enpassantMove.vanish.push({ - x: x, - y: y+epStep, - p: 'p', - c: this.getColor(x,y+epStep) - }); - moves.push(enpassantMove); + // En passant + const Lep = this.epSquares.length; + const epSquare = this.epSquares[Lep-1]; //always at least one element + if (!!epSquare && epSquare.x == x+shiftX && Math.abs(epSquare.y - y) == 1) + { + let enpassantMove = this.getBasicMove([x,y], [epSquare.x,epSquare.y]); + enpassantMove.vanish.push({ + x: x, + y: epSquare.y, + p: 'p', + c: this.getColor(x,epSquare.y) + }); + moves.push(enpassantMove); + } } return moves; @@ -460,7 +708,8 @@ class ChessRules // What are the queen moves from square x,y ? getPotentialQueenMoves(sq) { - return this.getSlideNJumpMoves(sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP])); + return this.getSlideNJumpMoves(sq, + V.steps[V.ROOK].concat(V.steps[V.BISHOP])); } // What are the king moves from square x,y ? @@ -490,13 +739,15 @@ class ChessRules continue; // If this code is reached, rooks and king are on initial position - // Nothing on the path of the king (and no checks; OK also if y==finalSquare)? + // Nothing on the path of the king ? + // (And no checks; OK also if y==finalSquare) let step = finalSquares[castleSide][0] < y ? -1 : 1; for (i=y; i!=finalSquares[castleSide][0]; i+=step) { if (this.isAttacked([x,i], [oppCol]) || (this.board[x][i] != V.EMPTY && // NOTE: next check is enough, because of chessboard constraints - (this.getColor(x,i) != c || ![V.KING,V.ROOK].includes(this.getPiece(x,i))))) + (this.getColor(x,i) != c + || ![V.KING,V.ROOK].includes(this.getPiece(x,i))))) { continue castlingCheck; } @@ -539,17 +790,12 @@ class ChessRules return moves; } - /////////////////// + //////////////////// // MOVES VALIDATION - canIplay(side, [x,y]) - { - return (this.turn == side && this.getColor(x,y) == side); - } - + // For the interface: possible moves for the current turn from square sq getPossibleMovesFrom(sq) { - // Assuming color is right (already checked) return this.filterValid( this.getPotentialMovesFrom(sq) ); } @@ -558,10 +804,17 @@ class ChessRules { if (moves.length == 0) return []; - return moves.filter(m => { return !this.underCheck(m); }); + const color = this.turn; + return moves.filter(m => { + this.play(m); + const res = !this.underCheck(color); + this.undo(m); + return res; + }); } - // Search for all valid moves considering current turn (for engine and game end) + // Search for all valid moves considering current turn + // (for engine and game end) getAllValidMoves() { const color = this.turn; @@ -571,13 +824,14 @@ class ChessRules { for (let j=0; j= 1) + { + // Usual case, something is moved + piece = move.vanish[0].p; + c = move.vanish[0].c; + } + else + { + // Crazyhouse-like variants + piece = move.appear[0].p; + c = move.appear[0].c; + } + if (c == "c") //if (!["w","b"].includes(c)) + { + // 'c = move.vanish[0].c' doesn't work for Checkered + c = this.getOppCol(this.turn); + } const firstRank = (c == "w" ? V.size.x-1 : 0); // Update king position + flags @@ -744,27 +1002,32 @@ class ChessRules { this.kingPos[c][0] = move.appear[0].x; this.kingPos[c][1] = move.appear[0].y; - this.castleFlags[c] = [false,false]; + if (V.HasFlags) + this.castleFlags[c] = [false,false]; return; } - const oppCol = this.getOppCol(c); - const oppFirstRank = (V.size.x-1) - firstRank; - if (move.start.x == firstRank //our rook moves? - && this.INIT_COL_ROOK[c].includes(move.start.y)) - { - const flagIdx = (move.start.y == this.INIT_COL_ROOK[c][0] ? 0 : 1); - this.castleFlags[c][flagIdx] = false; - } - else if (move.end.x == oppFirstRank //we took opponent rook? - && this.INIT_COL_ROOK[oppCol].includes(move.end.y)) + if (V.HasFlags) { - const flagIdx = (move.end.y == this.INIT_COL_ROOK[oppCol][0] ? 0 : 1); - this.castleFlags[oppCol][flagIdx] = false; + // Update castling flags if rooks are moved + const oppCol = this.getOppCol(c); + const oppFirstRank = (V.size.x-1) - firstRank; + if (move.start.x == firstRank //our rook moves? + && this.INIT_COL_ROOK[c].includes(move.start.y)) + { + const flagIdx = (move.start.y == this.INIT_COL_ROOK[c][0] ? 0 : 1); + this.castleFlags[c][flagIdx] = false; + } + else if (move.end.x == oppFirstRank //we took opponent rook? + && this.INIT_COL_ROOK[oppCol].includes(move.end.y)) + { + const flagIdx = (move.end.y == this.INIT_COL_ROOK[oppCol][0] ? 0 : 1); + this.castleFlags[oppCol][flagIdx] = false; + } } } - // After move is undo-ed, un-update variables (flags are reset) - // TODO: more symmetry, by storing flags increment in move... + // After move is undo-ed *and flags resetted*, un-update other variables + // TODO: more symmetry, by storing flags increment in move (?!) unupdateVariables(move) { // (Potentially) Reset king position @@ -773,74 +1036,54 @@ class ChessRules this.kingPos[c] = [move.start.x, move.start.y]; } - // Hash of position+flags+turn after a move is played (to detect repetitions) - getHashState() - { - return hex_md5(this.getFen()); - } - play(move, ingame) { // DEBUG: // if (!this.states) this.states = []; -// if (!ingame) this.states.push(JSON.stringify(this.board)); +// if (!ingame) this.states.push(this.getFen()); if (!!ingame) - move.notation = [this.getNotation(move), this.getLongNotation(move)]; + move.notation = this.getNotation(move); - move.flags = JSON.stringify(this.flags); //save flags (for undo) - this.updateVariables(move); - this.moves.push(move); - this.epSquares.push( this.getEpSquare(move) ); + if (V.HasFlags) + move.flags = JSON.stringify(this.aggregateFlags()); //save flags (for undo) + if (V.HasEnpassant) + this.epSquares.push( this.getEpSquare(move) ); V.PlayOnBoard(this.board, move); + this.turn = this.getOppCol(this.turn); + this.movesCount++; + this.updateVariables(move); if (!!ingame) - move.hash = this.getHashState(); + { + // Hash of current game state *after move*, to detect repetitions + move.hash = hex_md5(this.getFen()); + } } undo(move) { + if (V.HasEnpassant) + this.epSquares.pop(); + if (V.HasFlags) + this.disaggregateFlags(JSON.parse(move.flags)); V.UndoOnBoard(this.board, move); - this.epSquares.pop(); - this.moves.pop(); + this.turn = this.getOppCol(this.turn); + this.movesCount--; this.unupdateVariables(move); - this.parseFlags(JSON.parse(move.flags)); // DEBUG: -// if (JSON.stringify(this.board) != this.states[this.states.length-1]) +// if (this.getFen() != this.states[this.states.length-1]) // debugger; // this.states.pop(); } - ////////////// + /////////////// // END OF GAME - // Check for 3 repetitions (position + flags + turn) - checkRepetition() - { - if (!this.hashStates) - this.hashStates = {}; - const startIndex = - Object.values(this.hashStates).reduce((a,b) => { return a+b; }, 0) - // Update this.hashStates with last move (or all moves if continuation) - // NOTE: redundant storage, but faster and moderate size - for (let i=startIndex; i { return (elt >= 3); }); - } - // Is game over ? And if yes, what is the score ? checkGameOver() { - if (this.checkRepetition()) - return "1/2"; - if (this.atLeastOneMove()) // game not over return "*"; @@ -856,14 +1099,15 @@ class ChessRules if (!this.isAttacked(this.kingPos[color], [this.getOppCol(color)])) return "1/2"; // OK, checkmate - return color == "w" ? "0-1" : "1-0"; + return (color == "w" ? "0-1" : "1-0"); } - //////// - //ENGINE + /////////////// + // ENGINE PLAY // Pieces values - static get VALUES() { + static get VALUES() + { return { 'p': 1, 'r': 5, @@ -874,18 +1118,14 @@ class ChessRules }; } - static get INFINITY() { - return 9999; //"checkmate" (unreachable eval) - } + // "Checkmate" (unreachable eval) + static get INFINITY() { return 9999; } - static get THRESHOLD_MATE() { - // At this value or above, the game is over - return V.INFINITY; - } + // At this value or above, the game is over + static get THRESHOLD_MATE() { return V.INFINITY; } - static get SEARCH_DEPTH() { - return 3; //2 for high branching factor, 4 for small (Loser chess) - } + // Search depth: 2 for high branching factor, 4 for small (Loser chess, eg.) + static get SEARCH_DEPTH() { return 3; } // Assumption: at least one legal move // NOTE: works also for extinction chess because depth is 3... @@ -904,7 +1144,7 @@ class ChessRules let finish = (Math.abs(this.evalPosition()) >= V.THRESHOLD_MATE); if (!finish && !this.atLeastOneMove()) { - // Try mate (for other variants) + // Test mate (for other variants) const score = this.checkGameEnd(); if (score != "1/2") finish = true; @@ -917,12 +1157,14 @@ class ChessRules // Rank moves using a min-max at depth 2 for (let i=0; i eval2)) + if ((color == "w" && evalPos < eval2) + || (color=="b" && evalPos > eval2)) + { eval2 = evalPos; + } this.undo(moves2[j]); } } @@ -955,7 +1200,6 @@ class ChessRules this.undo(moves1[i]); } moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); - //console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; })); let candidates = [0]; //indices of candidates moves for (let j=1; j { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); + moves1.sort( (a,b) => { + return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); } else return currentBest; - //console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; })); +// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; })); candidates = [0]; for (let j=1; j 0) - { - // Add empty squares in-between - fen += emptyCount; - emptyCount = 0; - } - fen += V.board2fen(this.board[i][j]); - } - } - if (emptyCount > 0) - { - // "Flush remainder" - fen += emptyCount; - } - if (i < V.size.x - 1) - fen += "/"; //separate rows - } - return fen; - } - - // Flags part of the FEN string - getFlagsFen() - { - let fen = ""; - // Add castling flags - for (let i of ['w','b']) - { - for (let j=0; j<2; j++) - fen += (this.castleFlags[i][j] ? '1' : '0'); - } - return fen; - } + ///////////////////////// + // MOVES + GAME NOTATION + ///////////////////////// // Context: just before move is played, turn hasn't changed + // TODO: un-ambiguous notation (switch on piece type, check directions...) getNotation(move) { if (move.appear.length == 2 && move.appear[0].p == V.KING) //castle return (move.end.y < move.start.y ? "0-0-0" : "0-0"); // Translate final square - const finalSquare = String.fromCharCode(97 + move.end.y) + (V.size.x-move.end.x); + const finalSquare = V.CoordsToSquare(move.end); const piece = this.getPiece(move.start.x, move.start.y); if (piece == V.PAWN) @@ -1179,12 +1321,12 @@ class ChessRules if (move.vanish.length > move.appear.length) { // Capture - const startColumn = String.fromCharCode(97 + move.start.y); + const startColumn = V.CoordToColumn(move.start.y); notation = startColumn + "x" + finalSquare; } else //no capture notation = finalSquare; - if (move.appear.length > 0 && piece != move.appear[0].p) //promotion + if (move.appear.length > 0 && move.appear[0].p != V.PAWN) //promotion notation += "=" + move.appear[0].p.toUpperCase(); return notation; } @@ -1200,46 +1342,38 @@ class ChessRules // Complete the usual notation, may be required for de-ambiguification getLongNotation(move) { - const startSquare = - String.fromCharCode(97 + move.start.y) + (V.size.x-move.start.x); - const finalSquare = String.fromCharCode(97 + move.end.y) + (V.size.x-move.end.x); - return startSquare + finalSquare; //not encoding move. But short+long is enough + // Not encoding move. But short+long is enough + return V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end); } // The score is already computed when calling this function - getPGN(mycolor, score, fenStart, mode) + getPGN(moves, mycolor, score, fenStart, mode) { - const zeroPad = x => { return (x<10 ? "0" : "") + x; }; let pgn = ""; - pgn += '[Site "vchess.club"]
'; - const d = new Date(); + pgn += '[Site "vchess.club"]\n'; const opponent = mode=="human" ? "Anonymous" : "Computer"; - pgn += '[Variant "' + variant + '"]
'; - pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + - '-' + zeroPad(d.getDate()) + '"]
'; - pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]
'; - pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]
'; - pgn += '[FenStart "' + fenStart + '"]
'; - pgn += '[Fen "' + this.getFen() + '"]
'; - pgn += '[Result "' + score + '"]

'; - - // Standard PGN - for (let i=0; i