X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FZen.js;h=eb6748d0d8761f1188932a3c9c5f678435950db7;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=0424e07f089f22c5cd8a0c00a4df8e64e4dd7c0c;hpb=ffeaef854d80445ef87f2cdf4fe71d60347a81bf;p=vchess.git diff --git a/client/src/variants/Zen.js b/client/src/variants/Zen.js index 0424e07f..eb6748d0 100644 --- a/client/src/variants/Zen.js +++ b/client/src/variants/Zen.js @@ -1,6 +1,7 @@ import { ChessRules } from "@/base_rules"; export class ZenRules extends ChessRules { + getEpSquare(moveOrSquare) { if (!moveOrSquare) return undefined; if (typeof moveOrSquare === "string") { @@ -66,6 +67,7 @@ export class ZenRules extends ChessRules { 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]; + const oppCol = V.GetOppCol(color); outerLoop: for (let loop = 0; loop < steps.length; loop++) { const step = steps[loop]; let i = x + step[0]; @@ -77,7 +79,7 @@ export class ZenRules extends ChessRules { } if ( V.OnBoard(i, j) && - this.getColor(i, j) == V.GetOppCol(color) && + this.getColor(i, j) == oppCol && this.getPiece(i, j) == asA ) { // eat! @@ -98,13 +100,11 @@ export class ZenRules extends ChessRules { // Find possible captures from a square: look in every direction! findCaptures(sq) { let moves = []; - Array.prototype.push.apply(moves, this.findCaptures_aux(sq, V.PAWN)); Array.prototype.push.apply(moves, this.findCaptures_aux(sq, V.ROOK)); Array.prototype.push.apply(moves, this.findCaptures_aux(sq, V.KNIGHT)); Array.prototype.push.apply(moves, this.findCaptures_aux(sq, V.BISHOP)); Array.prototype.push.apply(moves, this.findCaptures_aux(sq, V.QUEEN)); - return moves; } @@ -112,49 +112,8 @@ export class ZenRules extends ChessRules { 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; - } - - getPotentialRookMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.ROOK]); - let captures = this.findCaptures(sq); - return noCaptures.concat(captures); - } - - getPotentialKnightMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep"); - let captures = this.findCaptures(sq); - return noCaptures.concat(captures); - } - - getPotentialBishopMoves(sq) { - let noCaptures = this.getSlideNJumpMoves(sq, V.steps[V.BISHOP]); - let captures = this.findCaptures(sq); - return noCaptures.concat(captures); - } - - getPotentialQueenMoves(sq) { - let noCaptures = this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]) - ); - let captures = this.findCaptures(sq); - return noCaptures.concat(captures); - } - - getPotentialKingMoves(sq) { - // Initialize with normal moves - let noCaptures = this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); - let captures = this.findCaptures(sq); - return noCaptures.concat(captures).concat(this.getCastleMoves(sq)); + getPotentialMovesFrom(sq) { + return super.getPotentialMovesFrom(sq).concat(this.findCaptures(sq)); } getNotation(move) { @@ -175,15 +134,16 @@ export class ZenRules extends ChessRules { const piece = this.getPiece(move.start.x, move.start.y); if (piece == V.PAWN) { // pawn move (TODO: enPassant indication) - if (move.vanish.length > 1) { + if (move.vanish.length == 2) { // capture notation = initialSquare + "x" + finalSquare; - } //no capture + } else notation = finalSquare; if (piece != move.appear[0].p) //promotion notation += "=" + move.appear[0].p.toUpperCase(); - } else { + } + else { // Piece movement notation = piece.toUpperCase(); if (move.vanish.length > 1) notation += initialSquare + "x"; @@ -202,4 +162,5 @@ export class ZenRules extends ChessRules { k: 1000 }; } + };