From: Benjamin Auder Date: Thu, 26 May 2022 15:06:36 +0000 (+0200) Subject: Fix castling prevention when passing on attacked squares X-Git-Url: https://git.auder.net/pieces/Cwda/current/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=082e639a3ed0a38a91fbe8d0e8bfa7b262b5227d;p=xogo.git Fix castling prevention when passing on attacked squares --- diff --git a/base_rules.js b/base_rules.js index df49f84..07084bf 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1521,26 +1521,29 @@ export default class ChessRules { if (specialAttack) findAddMoves("attack", stepSpec.attack); findAddMoves(specialAttack ? "moveonly" : "all", stepSpec.moves); - if (this.options["zen"]) - Array.prototype.push.apply(moves, this.findCapturesOn([x, y], true)); + if (this.options["zen"]) { + Array.prototype.push.apply(moves, + this.findCapturesOn([x, y], {zen: true})); + } return moves; } - findCapturesOn([x, y], zen) { + // Search for enemy (or not) pieces attacking [x, y] + findCapturesOn([x, y], args) { let moves = []; - // Find reverse captures (opponent takes) - const color = this.getColor(x, y); - const oppCol = C.GetOppCol(color); + if (!args.oppCol) + args.oppCol = C.GetOppCol(this.getColor(x, y) || this.turn); for (let i=0; i= 1); + return ( + this.findCapturesOn([x, y], {oppCol: oppCol, one: true}).length >= 1 + ); } // Stop at first king found (TODO: multi-kings) @@ -2158,6 +2171,12 @@ export default class ChessRules { let container = document.getElementById(this.containerId) const r = container.querySelector(".chessboard").getBoundingClientRect(); + if (typeof move.start.x == "string") { + // Need to bound width/height (was 100% for reserve pieces) + const pieceWidth = this.getPieceWidth(r.width); + movingPiece.style.width = pieceWidth + "px"; + movingPiece.style.height = pieceWidth + "px"; + } const maxDist = this.getMaxDistance(r.width); const pieces = this.pieces(); if (move.drag) { diff --git a/variants/Benedict/class.js b/variants/Benedict/class.js index 88609d7..68667e1 100644 --- a/variants/Benedict/class.js +++ b/variants/Benedict/class.js @@ -22,6 +22,10 @@ export default class BenedictRules extends ChessRules { return false; } + canTake() { + return false; + } + // Find potential captures from a square // follow steps from x,y until something is met. findAttacks([x, y]) { @@ -52,20 +56,12 @@ export default class BenedictRules extends ChessRules { } postProcessPotentialMoves(moves) { - if (moves.length == 0) - return moves; - const color = this.getColor(moves[0].start.x, moves[0].start.y); - const oppCol = C.GetOppCol(color); - // Remove captures (NOTE: altering canTake has side effects, - // Benedict is still based on captures even if they are forbidden): - moves = super.postProcessPotentialMoves(moves) - .filter(m => this.board[m.end.x][m.end.y] == ""); moves.forEach(m => { super.playOnBoard(m); let attacks = this.findAttacks([m.end.x, m.end.y]) if (this.options["zen"]) { let endSquares = {}; - super.findCapturesOn([m.end.x, m.end.y], true).forEach(c => { + super.findCapturesOn([m.end.x, m.end.y], {zen: true}).forEach(c => { endSquares[C.CoordsToSquare(c.end)] = true; }); Array.prototype.push.apply(attacks, Object.keys(endSquares)); @@ -115,7 +111,7 @@ export default class BenedictRules extends ChessRules { } // A king under (regular) check flips color, and the game is over. - underCheck(square, color) { + underCheck() { return false; }