X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBenedict.js;h=f0d4f2ba64bdc57574655c358e8d97596be49d0c;hb=c583ef1c1dfd19aee88b22c2175202fbdf4dc1c0;hp=eb6214629af473e0e36439efd8a1c6352640ece9;hpb=3a2a7b5fd3c6bfd0752838094c27e1fb6172d109;p=vchess.git diff --git a/client/src/variants/Benedict.js b/client/src/variants/Benedict.js index eb621462..f0d4f2ba 100644 --- a/client/src/variants/Benedict.js +++ b/client/src/variants/Benedict.js @@ -103,35 +103,6 @@ export const VariantRules = class BenedictRules extends ChessRules { return moves; } - getPotentialRookMoves(sq) { - return this.getSlideNJumpMoves(sq, V.steps[V.ROOK]); - } - - getPotentialKnightMoves(sq) { - return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep"); - } - - getPotentialBishopMoves(sq) { - return this.getSlideNJumpMoves(sq, V.steps[V.BISHOP]); - } - - getPotentialQueenMoves(sq) { - return this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]) - ); - } - - getPotentialKingMoves(sq) { - // Initialize with normal (non-capturing) moves - let noCaptures = this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); - return noCaptures.concat(this.getCastleMoves(sq)); - } - // No "under check" verifications: getCastleMoves([x, y]) { const c = this.getColor(x, y); @@ -225,27 +196,32 @@ export const VariantRules = class BenedictRules extends ChessRules { let newAppear = []; let newVanish = []; V.PlayOnBoard(this.board, m); - // If castling, m.appear has 2 elements: - m.appear.forEach(a => { - const flipped = this.findCaptures([a.x, a.y]); - flipped.forEach(sq => { - const piece = this.getPiece(sq[0],sq[1]); - const pipoA = new PiPo({ - x:sq[0], - y:sq[1], - c:color, - p:piece - }); - const pipoV = new PiPo({ - x:sq[0], - y:sq[1], - c:oppCol, - p:piece + // If castling, m.appear has 2 elements. + // In this case, consider the attacks of moving units only. + // (Sometimes the king or rook doesn't move). + for (let i = 0; i < m.appear.length; i++) { + const a = m.appear[i]; + if (m.vanish[i].x != a.x || m.vanish[i].y != a.y) { + const flipped = this.findCaptures([a.x, a.y]); + flipped.forEach(sq => { + const piece = this.getPiece(sq[0],sq[1]); + const pipoA = new PiPo({ + x:sq[0], + y:sq[1], + c:color, + p:piece + }); + const pipoV = new PiPo({ + x:sq[0], + y:sq[1], + c:oppCol, + p:piece + }); + newAppear.push(pipoA); + newVanish.push(pipoV); }); - newAppear.push(pipoA); - newVanish.push(pipoV); - }); - }); + } + } Array.prototype.push.apply(m.appear, newAppear); Array.prototype.push.apply(m.vanish, newVanish); V.UndoOnBoard(this.board, m);