X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FBario.js;h=3e076658782222106b7b563ed00ab62bf0d6b018;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=fcdb44d90263b0d2c01d9b2e0fcf4868fe5e9cb9;hpb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775;p=vchess.git diff --git a/client/src/variants/Bario.js b/client/src/variants/Bario.js index fcdb44d9..3e076658 100644 --- a/client/src/variants/Bario.js +++ b/client/src/variants/Bario.js @@ -4,6 +4,10 @@ import { randInt } from "@/utils/alea"; export class BarioRules extends ChessRules { + static get Options() { + return null; + } + // Does not really seem necessary (although the author mention it) // Instead, first move = pick a square for the king. static get HasFlags() { @@ -73,7 +77,7 @@ export class BarioRules extends ChessRules { vanish: [ new PiPo({ x: square[0], y: square[1], c: c, p: V.UNDEFINED }) ], - start: { x: -1, y: -1 }, + start: { x: -1, y: -1 } }); } @@ -262,7 +266,6 @@ export class BarioRules extends ChessRules { const color = this.turn; if (this.movesCount <= 1) { // Just put the king on the board - let moves = []; const firstRank = (color == 'w' ? 7 : 0); return [...Array(8)].map((x, j) => { return new Move({ @@ -293,9 +296,16 @@ export class BarioRules extends ChessRules { } filterValid(moves) { + if (this.movesCount <= 1) return moves; const color = this.turn; return moves.filter(m => { - if (m.vanish.length == 0) return true; + if (m.vanish.length == 0) { + // subTurn == 0: need to check if a move exists at subTurn == 1 + this.play(m); + const res = this.filterValid(this.getAllPotentialMoves()).length > 0; + this.undo(m); + return res; + } const start = { x: m.vanish[0].x, y: m.vanish[0].y }; const end = { x: m.appear[0].x, y: m.appear[0].y }; if (start.x == end.x && start.y == end.y) { @@ -330,9 +340,10 @@ export class BarioRules extends ChessRules { } return false; }; - if (this.subTurn == 0) return true; //always one reserve for an undefined - if (!super.atLeastOneMove()) return atLeastOneReserveMove(); - return true; + if (this.subTurn == 0) return atLeastOneReserveMove(); + const canMoveSomething = super.atLeastOneMove(); + if (this.subTurn == 2) return canMoveSomething; + return (canMoveSomething || atLeastOneReserveMove()); } underCheck(color) { @@ -519,7 +530,7 @@ export class BarioRules extends ChessRules { this.movesCount--; this.postUndo(move); }; - if (this.movesCount <= 2) toPrevPlayer(); + if (this.movesCount <= 2 && move.appear[0].p == V.KING) toPrevPlayer(); else if (move.vanish.length == 0) { this.reserve[this.turn][move.start.p]++; this.subTurn = move.turn[1];