X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2F_Antiking%2Fclass.js;fp=variants%2F_Antiking%2Fclass.js;h=e92edab21f1c67d1b016bd520af8731ee99a7fb6;hb=f3e90e30b6e7ff416afe288bc9dd865e5daf9860;hp=0000000000000000000000000000000000000000;hpb=a548cb4e3ad8099e977da9bb4a4184973beb56e3;p=xogo.git diff --git a/variants/_Antiking/class.js b/variants/_Antiking/class.js new file mode 100644 index 0000000..e92edab --- /dev/null +++ b/variants/_Antiking/class.js @@ -0,0 +1,81 @@ +import ChessRules from "/base_rules.js"; + +export default class AbstractAntikingRules extends ChessRules { + + static get Aliases() { + return Object.assign({'A': AbstractAntikingRules}, ChessRules.Aliases); + } + + static get Options() { + return { + styles: [ + "atomic", + "balance", + "cannibal", + "capture", + "crazyhouse", + "doublemove", + "madrasi", + "progressive", + "recycle", + "rifle", + "teleport", + "zen" + ] + }; + } + + pieces(color, x, y) { + return Object.assign( + { + 'a': { + // Move like a king, no attacks + "class": "antiking", + moves: super.pieces(color, x, y)['k'].moves, + attack: [] + } + }, + super.pieces(color, x, y) + ); + } + + isKing(x, y, p) { + if (!p) + p = this.getPiece(x, y); + return ['k', 'a'].includes(p); + } + + // NOTE: canTake includes (wrong) captures of antiking, + // to not go to low-level using findDestSquares() + canTake([x1, y1], [x2, y2]) { + const piece1 = this.getPiece(x1, y1); + const color1 = this.getColor(x1, y1); + const color2 = this.getColor(x2, y2); + return ( + (piece1 != 'a' && color1 != color2) || + (piece1 == 'a' && color1 == color2) + ); + } + + // Remove captures of antiking (see above) + getPotentialMovesFrom([x, y]) { + return super.getPotentialMovesFrom([x, y]).filter(m => + m.vanish.length == 1 || m.vanish[1].p != 'a'); + } + + underCheck(squares, color) { + let res = false; + squares.forEach(sq => { + switch (this.getPiece(sq[0], sq[1])) { + case 'k': + res ||= super.underAttack(sq, color); + break; + case 'a': + res ||= !super.underAttack(sq, color); + break; + } + }); + return res; + } + +};