X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBenedict.js;h=73a55088f60ddd3983a4731ab00075cf978cf715;hb=bf7e5f3669a4c0bfa2756921d15d3fd055d4cfd2;hp=eb6214629af473e0e36439efd8a1c6352640ece9;hpb=e5a5d33164bcba11c1dc07555f327fa98b9db511;p=vchess.git diff --git a/client/src/variants/Benedict.js b/client/src/variants/Benedict.js index eb621462..73a55088 100644 --- a/client/src/variants/Benedict.js +++ b/client/src/variants/Benedict.js @@ -225,27 +225,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 + // 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); }); - const pipoV = new PiPo({ - x:sq[0], - y:sq[1], - c:oppCol, - p:piece - }); - 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);