X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMarseille.js;h=6e72a23609152ec29d1475a5a03ac47c0ce5bbfc;hb=1b61a94dbd13f6a37a89e62216615d2496c760a2;hp=02daa22b8d416ba7ca131e14dbf6ec7700b98c97;hpb=5915f72002ae63b04620cebe47adf778174b1bee;p=vchess.git diff --git a/public/javascripts/variants/Marseille.js b/public/javascripts/variants/Marseille.js index 02daa22b..6e72a236 100644 --- a/public/javascripts/variants/Marseille.js +++ b/public/javascripts/variants/Marseille.js @@ -148,10 +148,12 @@ class MarseilleRules extends ChessRules play(move, ingame) { -// console.log("play " + this.getNotation(move)); -// console.log(this.turn + " "+ this.subTurn); if (!!ingame) + { move.notation = [this.getNotation(move), this.getLongNotation(move)]; + // In this special case, we also need the "move color": + move.color = this.turn; + } move.flags = JSON.stringify(this.aggregateFlags()); let lastEpsq = this.epSquares[this.epSquares.length-1]; const epSq = this.getEpSquare(move); @@ -185,7 +187,6 @@ class MarseilleRules extends ChessRules this.updateVariables(move); if (!!ingame) move.hash = hex_md5(this.getFen()); - //console.log(move.checkOnSubturn1 + " " +this.turn + " "+ this.subTurn); } undo(move) @@ -220,8 +221,6 @@ class MarseilleRules extends ChessRules } this.moves.pop(); this.unupdateVariables(move); -// console.log("UNDO " + this.getNotation(move)); -// console.log(this.turn + " "+ this.subTurn); } // NOTE: GenRandInitFen() is OK, @@ -315,6 +314,55 @@ class MarseilleRules extends ChessRules return selected[0]; return selected; } + + getPGN(mycolor, score, fenStart, mode) + { + let pgn = ""; + pgn += '[Site "vchess.club"]
'; + const opponent = mode=="human" ? "Anonymous" : "Computer"; + pgn += '[Variant "' + variant + '"]
'; + pgn += '[Date "' + getDate(new Date()) + '"]
'; + pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]
'; + pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]
'; + pgn += '[FenStart "' + fenStart + '"]
'; + pgn += '[Fen "' + this.getFen() + '"]
'; + pgn += '[Result "' + score + '"]

'; + + let counter = 1; + let i = 0; + while (i < this.moves.length) + { + pgn += (counter++) + "."; + for (let color of ["w","b"]) + { + let move = ""; + while (i < this.moves.length && this.moves[i].color == color) + move += this.moves[i++].notation[0] + ","; + move = move.slice(0,-1); //remove last comma + pgn += move + (i < this.moves.length-1 ? " " : ""); + } + } + pgn += "

"; + + // "Complete moves" PGN (helping in ambiguous cases) + counter = 1; + i = 0; + while (i < this.moves.length) + { + pgn += (counter++) + "."; + for (let color of ["w","b"]) + { + let move = ""; + while (i < this.moves.length && this.moves[i].color == color) + move += this.moves[i++].notation[1] + ","; + move = move.slice(0,-1); //remove last comma + pgn += move + (i < this.moves.length-1 ? " " : ""); + } + } + + return pgn; + } + } const VariantRules = MarseilleRules;