X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBenedict.js;h=f0d4f2ba64bdc57574655c358e8d97596be49d0c;hb=c583ef1c1dfd19aee88b22c2175202fbdf4dc1c0;hp=e87827f48e83a86b0bc4032140ef2ef2fd5ab354;hpb=e9b736ee3e72e2ddb9bf4da0c0f1e22a70f7448f;p=vchess.git diff --git a/client/src/variants/Benedict.js b/client/src/variants/Benedict.js index e87827f4..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); @@ -152,10 +123,10 @@ export const VariantRules = class BenedictRules extends ChessRules { castleSide < 2; castleSide++ //large, then small ) { - if (!this.castleFlags[c][castleSide]) continue; + if (this.castleFlags[c][castleSide] >= 8) continue; // If this code is reached, rooks and king are on initial position - const rookPos = this.INIT_COL_ROOK[c][castleSide]; + const rookPos = this.castleFlags[c][castleSide]; if (this.getColor(x, rookPos) != c) // Rook is here but changed color continue; @@ -176,7 +147,7 @@ export const VariantRules = class BenedictRules extends ChessRules { // Nothing on the path to the rook? step = castleSide == 0 ? -1 : 1; - for (i = y + step; i != this.INIT_COL_ROOK[c][castleSide]; i += step) { + for (i = y + step; i != rookPos; i += step) { if (this.board[x][i] != V.EMPTY) continue castlingCheck; } @@ -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 + // 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); @@ -290,4 +266,15 @@ export const VariantRules = class BenedictRules extends ChessRules { // Stalemate: return "1/2"; } + + getNotation(move) { + // Just remove flips: + const basicMove = { + appear: [move.appear[0]], + vanish: [move.vanish[0]], + start: move.start, + end: move.end + }; + return super.getNotation(basicMove); + } };