X-Git-Url: https://git.auder.net/assets/img/logo_Westcastle.png?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fvariants%2FCrazyhouse.js;h=7fa47b7253fd406d8cf3175c0a21dfab609304a4;hb=d982fffc441a0443be90ba6f57a94d1d60b702c8;hp=ee485448b13f9e0db17eba4cec84c6d5c0660bac;hpb=e50a802531b99829c533f22ecd21e359e7e1e049;p=vchess.git diff --git a/client/src/variants/Crazyhouse.js b/client/src/variants/Crazyhouse.js index ee485448..7fa47b72 100644 --- a/client/src/variants/Crazyhouse.js +++ b/client/src/variants/Crazyhouse.js @@ -2,6 +2,7 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; export class CrazyhouseRules extends ChessRules { + static IsGoodFen(fen) { if (!ChessRules.IsGoodFen(fen)) return false; const fenParsed = V.ParseFen(fen); @@ -165,10 +166,9 @@ export class CrazyhouseRules extends ChessRules { } getPotentialMovesFrom([x, y]) { - if (x >= V.size.x) { + if (x >= V.size.x) // Reserves, outside of board: x == sizeX(+1) return this.getReserveMoves([x, y]); - } // Standard moves return super.getPotentialMovesFrom([x, y]); } @@ -185,17 +185,15 @@ export class CrazyhouseRules extends ChessRules { } atLeastOneMove() { - if (!super.atLeastOneMove()) { - // Search one reserve move - for (let i = 0; i < V.RESERVE_PIECES.length; i++) { - let moves = this.filterValid( - this.getReserveMoves([V.size.x + (this.turn == "w" ? 0 : 1), i]) - ); - if (moves.length > 0) return true; - } - return false; + if (super.atLeastOneMove()) return true; + // Search one reserve move + for (let i = 0; i < V.RESERVE_PIECES.length; i++) { + const moves = this.filterValid( + this.getReserveMoves([V.size.x + (this.turn == "w" ? 0 : 1), i]) + ); + if (moves.length > 0) return true; } - return true; + return false; } postPlay(move) { @@ -253,4 +251,5 @@ export class CrazyhouseRules extends ChessRules { move.appear[0].p != V.PAWN ? move.appear[0].p.toUpperCase() : ""; return piece + "@" + V.CoordsToSquare(move.end); } + };