X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FCopycat%2Fclass.js;fp=variants%2FCopycat%2Fclass.js;h=2c417c5e41b4760edede600905a62defac603728;hb=296f846a620c361b3fe4e61f6bb369adc361d312;hp=0000000000000000000000000000000000000000;hpb=24a6312db06bd3632ff702389c3712f77d01046d;p=xogo.git diff --git a/variants/Copycat/class.js b/variants/Copycat/class.js new file mode 100644 index 0000000..2c417c5 --- /dev/null +++ b/variants/Copycat/class.js @@ -0,0 +1,63 @@ +import ChessRules from "/base_rules.js"; + +export default class CopycatRules extends ChessRules { + + static get Options() { + return { + select: C.Options.select, + input: C.Options.input, + styles: ["atomic", "capture", "crazyhouse", "cylinder", "dark", "zen"] + }; + } + + getPotentialMovesFrom([x, y], color) { + let moves = super.getPotentialMovesFrom([x, y], color); + // Expand potential moves if attacking friendly pieces. + const piece = this.getPiece(x,y); + if (['p', 'k'].includes(piece)) + return moves; + let movements = {}; + const steps = this.pieces()[piece].both[0].steps; + steps.forEach(s => { + let [i, j] = [x + s[0], y + s[1]]; + while ( + this.onBoard(i, j) && + this.board[i][j] == "" && + piece != 'n' + ) { + i += s[0]; + j += s[1]; + } + if (this.onBoard(i, j) && this.getColor(i, j) == this.turn) { + const attacked = this.getPiece(i, j); + if (['r', 'b', 'n'].includes(attacked)) { + if (!movements[attacked]) + movements[attacked] = true; + } + else if (attacked == 'q') { + if (!movements['r']) + movements['r'] = true; + if (!movements['b']) + movements['b'] = true; + } + } + }); + Object.keys(movements).forEach(type => { + if ( + (piece != 'q' && type != piece) || + (piece == 'q' && type == 'n') + ) { + Array.prototype.push.apply(moves, + super.getPotentialMovesOf(type, [x, y])); + } + }); + return moves; + } + + underAttack([x, y], oppCols) { + if (super.underAttack([x, y], oppCols) + return true; + //TODO + } + +};