X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FZen.js;h=ff562d0adce48426a5d6e7769a5e4ca969ac5342;hb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;hp=f5bff8ffd40c8a63d217c80827c1c0db3df9e87b;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/variants/Zen.js b/client/src/variants/Zen.js index f5bff8ff..ff562d0a 100644 --- a/client/src/variants/Zen.js +++ b/client/src/variants/Zen.js @@ -1,6 +1,6 @@ import { ChessRules } from "@/base_rules"; -export const VariantRules = class ZenRules extends ChessRules { +export class ZenRules extends ChessRules { // NOTE: enPassant, if enabled, would need to redefine carefully getEpSquare static get HasEnpassant() { return false; @@ -28,7 +28,7 @@ export const VariantRules = class ZenRules extends ChessRules { // if met piece is opponent and same movement (asA): eat it! findCaptures_aux([x, y], asA) { const color = this.getColor(x, y); - var moves = []; + let moves = []; const steps = asA != V.PAWN ? asA == V.QUEEN @@ -43,7 +43,7 @@ export const VariantRules = class ZenRules extends ChessRules { [1, -1], [1, 1] ]; - const oneStep = asA == V.KNIGHT || asA == V.PAWN; //we don't capture king + const oneStep = [V.KNIGHT,V.PAWN].includes(asA); //we don't capture king const lastRank = color == "w" ? 0 : V.size.x - 1; const promotionPieces = [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN]; outerLoop: for (let loop = 0; loop < steps.length; loop++) { @@ -88,44 +88,14 @@ export const VariantRules = class ZenRules extends ChessRules { return moves; } - getPotentialPawnMoves([x, y]) { - const color = this.getColor(x, y); - let moves = []; - const sizeY = V.size.y; - const shift = color == "w" ? -1 : 1; - const startRank = color == "w" ? sizeY - 2 : 1; - const firstRank = color == "w" ? sizeY - 1 : 0; - const lastRank = color == "w" ? 0 : sizeY - 1; - - if (x + shift != lastRank) { - // Normal moves - if (this.board[x + shift][y] == V.EMPTY) { - moves.push(this.getBasicMove([x, y], [x + shift, y])); - if ( - [startRank, firstRank].includes(x) && - this.board[x + 2 * shift][y] == V.EMPTY - ) { - //two squares jump - moves.push(this.getBasicMove([x, y], [x + 2 * shift, y])); - } - } - } //promotion - else { - let promotionPieces = [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN]; - promotionPieces.forEach(p => { - // Normal move - if (this.board[x + shift][y] == V.EMPTY) - moves.push( - this.getBasicMove([x, y], [x + shift, y], { c: color, p: p }) - ); - }); - } - - // No en passant here + canTake(sq1, sq2) { + return false; //captures handled separately + } + getPotentialPawnMoves([x, y]) { + let moves = super.getPotentialPawnMoves([x, y]); // Add "zen" captures Array.prototype.push.apply(moves, this.findCaptures([x, y])); - return moves; } @@ -175,7 +145,7 @@ export const VariantRules = class ZenRules extends ChessRules { return "0-0"; } - // Translate initial square (because pieces may fly unusually in this variant!) + // Translate initial square (because pieces may fly unusually!) const initialSquare = V.CoordsToSquare(move.start); // Translate final square