From: Benjamin Auder Date: Sun, 15 Mar 2020 16:19:48 +0000 (+0100) Subject: Fix Benedict rules for flipped colors when castling: seems more logical now X-Git-Url: https://git.auder.net/doc/html/vendor/current/scripts/R.css?a=commitdiff_plain;h=bf7e5f3669a4c0bfa2756921d15d3fd055d4cfd2;p=vchess.git Fix Benedict rules for flipped colors when castling: seems more logical now --- 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);