X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FClorange%2Fclass.js;h=485bbd63a8cab30eef0209181bcdb0ba4d2f8110;hb=061c078d4724d24003897415939ab3a5c057a45d;hp=38cb958f543c3eb5b3ef1d8eb610d69748f8f6bd;hpb=6bf2ab3498d5d469ea456b528c178dc481789b76;p=xogo.git diff --git a/variants/Clorange/class.js b/variants/Clorange/class.js index 38cb958..485bbd6 100644 --- a/variants/Clorange/class.js +++ b/variants/Clorange/class.js @@ -2,7 +2,13 @@ import ChessRules from "/base_rules.js"; export default class ClorangeRules extends ChessRules { - // TODO: options : disable teleport/recycle at least ? + static get Options() { + return { + select: C.Options.select, + styles: + C.Options.styles.filter(s => !["crazyhouse","recycle"].includes(s)) + }; + } get hasReserve() { return true; @@ -23,44 +29,50 @@ export default class ClorangeRules extends ChessRules { res['o'] = {"class": "nv-knight", moveas: "n"}; res['c'] = {"class": "nv-bishop", moveas: "b"}; res['t'] = {"class": "nv-queen", moveas: "q"}; + return res; } - setOtherVariables(fen) { - super.setOtherVariables(fen, - ['p', 'r', 'n', 'b', 'q', 's', 'u', 'o', 'c', 't']); + static get V_PIECES() { + return ['p', 'r', 'n', 'b', 'q']; + } + static get NV_PIECES() { + return ['s', 'u', 'o', 'c', 't']; } - postProcessPotentialMoves(moves) { - // Remove captures for non-violent pieces: - return super.postProcessPotentialMoves(moves).filter(m => { - return ( - m.vanish.length != 2 || - m.appear.length != 1 || - ['p', 'r', 'n', 'b', 'q'].includes(m.vanish[0].p) - ); - }); + setOtherVariables(fen) { + super.setOtherVariables(fen, V.V_PIECES.concat(V.NV_PIECES)); } + // Forbid non-violent pieces to capture canTake([x1, y1], [x2, y2]) { return ( this.getColor(x1, y1) !== this.getColor(x2, y2) && - ['p', 'r', 'n', 'b', 'q', 'k'].includes(this.getPiece(x1, y1)) + (['k'].concat(V.V_PIECES)).includes(this.getPiece(x1, y1)) ); } + pawnPostProcess(moves, color, oppCols) { + let res = super.pawnPostProcess(moves, color, oppCols); + if (res.length > 0 && res[0].vanish[0].p == 's') { + // Fix promotions of non-violent pawns (if any) + res.forEach(m => { + if (m.appear[0].p != 's') + m.appear[0].p = V.NV_PIECES[V.V_PIECES.indexOf(m.appear[0].p)]; + }); + } + return res; + } + prePlay(move) { super.prePlay(move); - // No crazyhouse or recycle, so the last call didn't update reserve: + // NOTE: drop moves already taken into account in base prePlay() if (move.vanish.length == 2 && move.appear.length == 1) { - // Capture: update reserves - this.Reserve[move.vanish - const pIdx = ['p', 'r', 'n', 'b', 'q'].indexOf(move.vanish[1].p); - // TODO - if normal - ? ChessRules.PIECES.findIndex(p => p == move.vanish[1].p) - : V.NON_VIOLENT.findIndex(p => p == move.vanish[1].p); - const rPiece = (normal ? V.NON_VIOLENT : ChessRules.PIECES)[pIdx]; - this.reserve[move.vanish[1].c][rPiece]++; + const normal = V.V_PIECES.includes(move.vanish[1].p); + const pIdx = + (normal ? V.V_PIECES : V.NV_PIECES).indexOf(move.vanish[1].p); + const resPiece = (normal ? V.NV_PIECES : V.V_PIECES)[pIdx]; + super.updateReserve(C.GetOppTurn(this.turn), resPiece, + this.reserve[C.GetOppTurn(this.turn)][resPiece] + 1); } }