From: Benjamin Auder Date: Thu, 27 Jul 2023 17:35:22 +0000 (+0200) Subject: Fix Copycat X-Git-Url: https://git.auder.net/js/%3C?a=commitdiff_plain;h=a46d74c085e79e62716e3fca8a10a22d2ca10056;p=xogo.git Fix Copycat --- diff --git a/base_rules.js b/base_rules.js index 9cedfd0..c0d9b60 100644 --- a/base_rules.js +++ b/base_rules.js @@ -1838,8 +1838,6 @@ export default class ChessRules { } } - // TODO here: should/could use getPotentialMovesFrom ?! (not sure) - // --> would be useful for variants like Copycat. // Search for enemy (or not) pieces attacking [x, y] findCapturesOn([x, y], o, allowed) { if (!o.byCol) diff --git a/variants/Copycat/class.js b/variants/Copycat/class.js index 2c417c5..e19367c 100644 --- a/variants/Copycat/class.js +++ b/variants/Copycat/class.js @@ -6,16 +6,16 @@ export default class CopycatRules extends ChessRules { return { select: C.Options.select, input: C.Options.input, - styles: ["atomic", "capture", "crazyhouse", "cylinder", "dark", "zen"] + styles: C.Options.styles.filter(s => !["madrasi", "zen"].includes(s)) }; } - getPotentialMovesFrom([x, y], color) { - let moves = super.getPotentialMovesFrom([x, y], color); - // Expand potential moves if attacking friendly pieces. + getStepSpec(color, x, y) { + let res = super.getStepSpec(color, x, y); const piece = this.getPiece(x,y); if (['p', 'k'].includes(piece)) - return moves; + return res; + // Now check if the piece at x, y attack some friendly one (enhancement) let movements = {}; const steps = this.pieces()[piece].both[0].steps; steps.forEach(s => { @@ -28,7 +28,7 @@ export default class CopycatRules extends ChessRules { i += s[0]; j += s[1]; } - if (this.onBoard(i, j) && this.getColor(i, j) == this.turn) { + if (this.onBoard(i, j) && this.getColor(i, j) == color) { const attacked = this.getPiece(i, j); if (['r', 'b', 'n'].includes(attacked)) { if (!movements[attacked]) @@ -43,21 +43,10 @@ export default class CopycatRules extends ChessRules { } }); Object.keys(movements).forEach(type => { - if ( - (piece != 'q' && type != piece) || - (piece == 'q' && type == 'n') - ) { - Array.prototype.push.apply(moves, - super.getPotentialMovesOf(type, [x, y])); - } + if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n')) + res.both.push(this.pieces()[type].both[0]); }); - return moves; - } - - underAttack([x, y], oppCols) { - if (super.underAttack([x, y], oppCols) - return true; - //TODO + return res; } };