X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FCopycat%2Fclass.js;h=e19367c3155798b008fd7ebb386e1ff9e1991a6c;hb=a46d74c085e79e62716e3fca8a10a22d2ca10056;hp=2c417c5e41b4760edede600905a62defac603728;hpb=296f846a620c361b3fe4e61f6bb369adc361d312;p=xogo.git 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; } };