-
- getPGN(mycolor, score, fenStart, mode)
- {
- let pgn = "";
- pgn += '[Site "vchess.club"]<br>';
- const opponent = mode=="human" ? "Anonymous" : "Computer";
- pgn += '[Variant "' + variant + '"]<br>';
- pgn += '[Date "' + getDate(new Date()) + '"]<br>';
- pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
- pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';
- pgn += '[FenStart "' + fenStart + '"]<br>';
- pgn += '[Fen "' + this.getFen() + '"]<br>';
- pgn += '[Result "' + score + '"]<br><br>';
-
- 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 += "<br><br>";
-
- // "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;
- }