X-Git-Url: https://git.auder.net/js/rpsls.js?a=blobdiff_plain;f=variants%2FClorange%2Fclass.js;h=e8506db8a83c85e6581f623132967c52d0a5bd70;hb=3232aba3419f129c70d5edd9a4ded1fefc146ea0;hp=01d718934a23c073c6ef40a277224992323989c8;hpb=5269839f65908a0782db512f498e2d55662bee9f;p=xogo.git diff --git a/variants/Clorange/class.js b/variants/Clorange/class.js index 01d7189..e8506db 100644 --- a/variants/Clorange/class.js +++ b/variants/Clorange/class.js @@ -14,14 +14,6 @@ export default class ClorangeRules extends ChessRules { return true; } - getReserveFen(o) { - if (o.init) - return "00000000000000000000"; - return ( - ["w","b"].map(c => Object.values(this.reserve[c]).join("")).join("") - ); - } - pieces(color, x, y) { let res = super.pieces(color, x, y); res['s'] = {"class": "nv-pawn", moveas: "p"}; @@ -38,9 +30,8 @@ export default class ClorangeRules extends ChessRules { static get NV_PIECES() { return ['s', 'u', 'o', 'c', 't']; } - - setOtherVariables(fen) { - super.setOtherVariables(fen, V.V_PIECES.concat(V.NV_PIECES)); + static get ReserveArray() { + return V.V_PIECES.concat(V.NV_PIECES); } // Forbid non-violent pieces to capture @@ -51,26 +42,28 @@ export default class ClorangeRules extends ChessRules { ); } + 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: - if ( - (move.vanish.length == 2 && move.appear.length == 1) || - move.vanish.length == 0 //drop - ) { - const trPiece = - (move.vanish.length > 0 ? move.vanish[1].p : move.appear[0].p); - const normal = V.V_PIECES.includes(trPiece); - const pIdx = (normal ? V.V_PIECES : V.NV_PIECES).indexOf(trPiece); + // NOTE: drop moves already taken into account in base prePlay() + if (move.vanish.length == 2 && move.appear.length == 1) { + 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]; - if (move.vanish.length > 0) { - super.updateReserve(C.GetOppTurn(this.turn), resPiece, - this.reserve[C.GetOppTurn(this.turn)][resPiece] + 1); - } - else { - super.updateReserve(this.turn, resPiece, - this.reserve[this.turn][resPiece] - 1); - } + super.updateReserve(C.GetOppTurn(this.turn), resPiece, + this.reserve[C.GetOppTurn(this.turn)][resPiece] + 1); } }