// Does m2 un-do m1 ? (to disallow undoing checkered moves)
oppositeMoves(m1, m2) {
return (
- m1 &&
+ !!m1 &&
m2.appear[0].c == "c" &&
m2.appear.length == 1 &&
m2.vanish.length == 1 &&
}
isAttackedByBishop(sq, colors) {
- return this.isAttackedBySlideNJump(sq, colors, V.BISHOP, V.steps[V.BISHOP]);
+ return this.isAttackedBySlideNJump(
+ sq, colors, V.BISHOP, V.steps[V.BISHOP]);
}
isAttackedByQueen(sq, colors) {
"c"
]);
let res = kingAttacked
- ? [JSON.parse(JSON.stringify(this.kingPos[color]))] //need to duplicate!
+ ? [JSON.parse(JSON.stringify(this.kingPos[color]))]
: [];
this.turn = color;
return res;
return "0-0";
}
- // Translate final square
const finalSquare = V.CoordsToSquare(move.end);
-
const piece = this.getPiece(move.start.x, move.start.y);
+ let notation = "";
if (piece == V.PAWN) {
// Pawn move
- let notation = "";
if (move.vanish.length > 1) {
// Capture
const startColumn = V.CoordToColumn(move.start.y);
- notation =
- startColumn +
- "x" +
- finalSquare +
- "=" +
- move.appear[0].p.toUpperCase();
- } //no capture
- else {
- notation = finalSquare;
- if (move.appear.length > 0 && piece != move.appear[0].p)
- //promotion
- notation += "=" + move.appear[0].p.toUpperCase();
- }
- return notation;
+ notation = startColumn + "x" + finalSquare;
+ } else notation = finalSquare;
+ } else {
+ // Piece movement
+ notation =
+ piece.toUpperCase() +
+ (move.vanish.length > 1 ? "x" : "") +
+ finalSquare;
}
- // Piece movement
- return (
- piece.toUpperCase() +
- (move.vanish.length > 1 ? "x" : "") +
- finalSquare +
- (move.vanish.length > 1 ? "=" + move.appear[0].p.toUpperCase() : "")
- );
+ if (move.appear[0].p != move.vanish[0].p)
+ notation += "=" + move.appear[0].p.toUpperCase();
+ return notation;
}
};