X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=0a5c0e72e5e8d7f6f7e3597a8b4eb913b23be8f5;hb=dfb4afc10d56715b80f753b1273738bd11a309dd;hp=576bdd9b0eb1b47cb4287ab977529a4531f85279;hpb=772d7245d92f65c0b27c6c4aaaf64dc2fe9a9057;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 576bdd9b..0a5c0e72 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -47,9 +47,9 @@ class ChessRules // INITIALIZATION // fen = "position flags epSquare movesCount" - constructor(fen) + constructor(fen, moves) { - this.moves = []; + this.moves = moves; // Use fen string to initialize variables, flags and board this.initVariables(fen); this.flags = VariantRules.GetFlags(fen); @@ -665,12 +665,15 @@ class ChessRules move.flags = JSON.stringify(this.flags); //TODO: less costly this.updateVariables(move); + if (!!ingame) + { + move.notation = this.getNotation(move); + this.moves.push(move); + } + this.epSquares.push( this.getEpSquare(move) ); VariantRules.PlayOnBoard(this.board, move); this.movesCount++; - - if (!!ingame) - this.moves.push(move); } undo(move) @@ -1007,4 +1010,26 @@ class ChessRules return piece.toUpperCase() + (move.vanish.length > 1 ? "x" : "") + finalSquare; } } + + // The score is already computed when calling this function + getPGN(mycolor, score) + { + let pgn = ""; + pgn += '[Site "vchess.club"]
'; + const d = new Date(); + pgn += '[Date "' + d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate() + '"]
'; + pgn += '[White "' + (mycolor=='w'?'Myself':'Anonymous') + '"]
'; + pgn += '[Black "' + (mycolor=='b'?'Myself':'Anonymous') + '"]
'; + pgn += '[Result "' + score + '"]
'; + + for (let i=0; i