setFlags(fenflags) {
super.setFlags(fenflags); //castleFlags
this.pawnFlags = {
- w: [...Array(8).fill(true)], //pawns can move 2 squares?
- b: [...Array(8).fill(true)]
+ w: [...Array(8)], //pawns can move 2 squares?
+ b: [...Array(8)]
};
const flags = fenflags.substr(4); //skip first 4 letters, for castle
for (let c of ["w", "b"]) {
// 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;
}
getCurrentScore() {
- if (this.atLeastOneMove())
- // game not over
- return "*";
-
+ if (this.atLeastOneMove()) return "*";
const color = this.turn;
// Artifically change turn, for checkered pawns
this.turn = V.GetOppCol(this.turn);
}
static ParseFen(fen) {
- return Object.assign({}, ChessRules.ParseFen(fen), {
- cmove: fen.split(" ")[5]
- });
+ return Object.assign(
+ ChessRules.ParseFen(fen),
+ { cmove: fen.split(" ")[5] }
+ );
}
getFen() {
const L = this.cmoves.length;
- const cmoveFen = !this.cmoves[L - 1]
- ? "-"
- : ChessRules.CoordsToSquare(this.cmoves[L - 1].start) +
- ChessRules.CoordsToSquare(this.cmoves[L - 1].end);
+ const cmoveFen =
+ !this.cmoves[L - 1]
+ ? "-"
+ : ChessRules.CoordsToSquare(this.cmoves[L - 1].start) +
+ ChessRules.CoordsToSquare(this.cmoves[L - 1].end);
return super.getFen() + " " + cmoveFen;
}
getFlagsFen() {
let fen = super.getFlagsFen();
// Add pawns flags
- for (let c of ["w", "b"]) {
- for (let i = 0; i < 8; i++) fen += this.pawnFlags[c][i] ? "1" : "0";
- }
+ for (let c of ["w", "b"])
+ for (let i = 0; i < 8; i++) fen += (this.pawnFlags[c][i] ? "1" : "0");
return fen;
}
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;
}
};