X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered.js;h=79ea63c44a3fc6bd24b71aebf4d2511031d41d12;hb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;hp=882a32ac8a465ea49092dcc40f99898da47a5df7;hpb=6f2f94374f1e73c375edf732d9425e575e81fff7;p=vchess.git diff --git a/client/src/variants/Checkered.js b/client/src/variants/Checkered.js index 882a32ac..79ea63c4 100644 --- a/client/src/variants/Checkered.js +++ b/client/src/variants/Checkered.js @@ -71,8 +71,8 @@ export class CheckeredRules extends ChessRules { 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"]) { @@ -303,7 +303,8 @@ export class CheckeredRules extends ChessRules { } 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) { @@ -337,7 +338,7 @@ export class CheckeredRules extends ChessRules { "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; @@ -402,19 +403,19 @@ export class CheckeredRules extends ChessRules { 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; } @@ -429,37 +430,25 @@ export class CheckeredRules extends ChessRules { 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; } };