X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FAvalanche%2Fclass.js;h=ee805502ae4af265af9ac40d07933d3503b578f5;hb=bc97fdd1302473b774cfb19e65dc3ed3ed388901;hp=dbbe9d55d4eb9666fb921a5f5d592480ef930564;hpb=df3fdaff8fa7b3046eb67e4bc4da37a5bcc8c4d7;p=xogo.git diff --git a/variants/Avalanche/class.js b/variants/Avalanche/class.js index dbbe9d5..ee80550 100644 --- a/variants/Avalanche/class.js +++ b/variants/Avalanche/class.js @@ -7,6 +7,14 @@ export default class AvalancheRules extends ChessRules { static get Options() { return { select: C.Options.select, + input: [ + { + label: "Balanced", + variable: "balanced", + type: "checkbox", + defaut: false + } + ], styles: [ "atomic", "cannibal", @@ -116,35 +124,46 @@ export default class AvalancheRules extends ChessRules { return false; } - postPlay(move) { + tryChangeTurn(move) { const color = this.turn; const oppCol = C.GetOppTurn(color); - this.promotion = ( - this.subTurn == 2 && - move.end.x == (oppCol == 'w' ? 0 : this.size.x - 1) && - move.vanish[0].p == 'p' - ); - if (this.subTurn == 0) { - this.subTurn++; - if (!this.atLeastOneMove(color)) { - move.result = "1/2"; //avoid re-computation - this.turn = oppCol; + const incrementTurn = () => { + if (this.options["balanced"] && this.movesCount == 0) { + // No pawn push on move 1: + return true; } - } - else if (this.subTurn == 2) { - this.turn = oppCol; - this.subTurn = this.promotion ? 0 : 1; - } - else { //subTurn == 1, usual case + this.promotion = ( + this.subTurn == 2 && + move.end.x == (oppCol == 'w' ? 0 : this.size.x - 1) && + move.vanish[0].p == 'p' + ); + if (this.subTurn == 0) { + this.subTurn++; + if (!this.atLeastOneMove(color)) { + move.result = "1/2"; //avoid re-computation + return true; + } + return false; + } + if (this.subTurn == 2) { + this.subTurn = (this.promotion ? 0 : 1); + return true; + } + // subTurn == 1, usual case const kingCapture = this.searchKingPos(oppCol).length == 0; if (kingCapture) move.result = (color == 'w' ? "1-0" : "0-1"); - if (!kingCapture && this.atLeastOnePawnPush(oppCol)) - this.subTurn++; - else { - this.turn = oppCol; - this.subTurn = this.promotion ? 0 : 1; + if (kingCapture || !this.atLeastOnePawnPush(oppCol)) { + this.subTurn = (this.promotion ? 0 : 1); + return true; } + // A pawn push is possible: usual case + this.subTurn++; + return false; + }; + if (incrementTurn()) { + this.turn = oppCol; + this.movesCount++; } }