if (piece == V.PAWN)
{
// Pawn move
+ const finalSquare = V.CoordsToSquare(move.end);
let notation = "";
if (move.vanish.length == 2) //capture
- notation = finalSquare;
+ notation = "Px" + finalSquare;
else
{
- // No capture
- const startColumn = V.CoordToColumn(move.start.y);
- notation = startColumn + "x" + finalSquare;
+ // No capture: indicate the initial square for potential ambiguity
+ const startSquare = V.CoordsToSquare(move.start);
+ notation = startSquare + finalSquare;
}
if (move.appear[0].p != V.PAWN) //promotion
notation += "=" + move.appear[0].p.toUpperCase();
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);
this.updateVariables(move);
if (!!ingame)
move.hash = hex_md5(this.getFen());
- //console.log(move.checkOnSubturn1 + " " +this.turn + " "+ this.subTurn);
}
undo(move)
}
this.moves.pop();
this.unupdateVariables(move);
-// console.log("UNDO " + this.getNotation(move));
-// console.log(this.turn + " "+ this.subTurn);
}
// NOTE: GenRandInitFen() is OK,
return selected[0];
return selected;
}
+
+ 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;
+ }
+
}
const VariantRules = MarseilleRules;