X-Git-Url: https://git.auder.net/?p=xogo.git;a=blobdiff_plain;f=variants%2FCoronation%2Fclass.js;fp=variants%2FCoronation%2Fclass.js;h=bf3684afc9f8c866096a4ec444074d40d7972c76;hp=0000000000000000000000000000000000000000;hb=7379efc5a40788dbf093a4dd5613ca9fbe73cbcf;hpb=8f87962339f2bcaeb4c2716d0588a63449a68bde diff --git a/variants/Coronation/class.js b/variants/Coronation/class.js new file mode 100644 index 0000000..bf3684a --- /dev/null +++ b/variants/Coronation/class.js @@ -0,0 +1,40 @@ +import ChessRules from "/base_rules.js"; + +export default class CoronationRules extends ChessRules { + + get hasSelfCaptures() { + return true; + } + + canSelfTake([x1, y1], [x2, y2]) { + const c = this.getColor(x1, y1); + if ( + this.board.some(row => + row.some(square => + square[0] == c && square[1] == 'q') + ) + ) { + // Already a queen on the board: no coronation + return false; + } + const [p1, p2] = [this.getPiece(x1, y1), this.getPiece(x2, y2)]; + return ((p1 == 'r' && p2 == 'b') || (p1 == 'b' && p2 == 'r')); + } + + getPotentialMovesOf(piece, [x, y]) { + const res = super.getPotentialMovesOf(piece, [x, y]); + if (['r', 'b'].includes(piece)) { + res.forEach(m => { + if ( + m.vanish.length == 2 && + m.appear.length == 1 && + m.vanish[1].c == m.vanish[0].c + ) { + m.appear[0].p = 'q'; + } + }); + } + return res; + } + +};