X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=179fffa5a91d345173a4e95eac3271c9434aa0c3;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=00452cbd2aa960589fa215eda3752fb422533278;hpb=2d7194bd9c976f444e43e5dc0a725823b6472eb9;p=vchess.git diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index 00452cbd..179fffa5 100644 --- a/public/javascripts/variants/Crazyhouse.js +++ b/public/javascripts/variants/Crazyhouse.js @@ -11,10 +11,9 @@ class CrazyhouseRules extends ChessRules // 6) Check promoted array if (!fenParsed.promoted) return false; - fenpromoted = fenParsed.promoted; - if (fenpromoted == "-") + if (fenParsed.promoted == "-") return true; //no promoted piece on board - const squares = fenpromoted.split(","); + const squares = fenParsed.promoted.split(","); for (let square of squares) { const c = V.SquareToCoords(square); @@ -24,10 +23,21 @@ class CrazyhouseRules extends ChessRules return true; } + static ParseFen(fen) + { + const fenParts = fen.split(" "); + return Object.assign( + ChessRules.ParseFen(fen), + { + reserve: fenParts[5], + promoted: fenParts[6], + } + ); + } + static GenRandInitFen() { - const fen = ChessRules.GenRandInitFen(); - return fen.replace(" w 1111", " w 1111 0000000000 -"); + return ChessRules.GenRandInitFen() + " 0000000000 -"; } getFen() @@ -37,8 +47,8 @@ class CrazyhouseRules extends ChessRules getReserveFen() { - let counts = _.map(_.range(10), 0); - for (let i=0; i 0) res = res.slice(0,-1); //remove last comma + else + res = "-"; return res; } @@ -87,10 +99,13 @@ class CrazyhouseRules extends ChessRules } }; this.promoted = doubleArray(V.size.x, V.size.y, false); - for (let square of fenParsd.promoted.split(",")) + if (fenParsed.promoted != "-") { - const [x,y] = V.SquareToCoords(square); - promoted[x][y] = true; + for (let square of fenParsed.promoted.split(",")) + { + const [x,y] = V.SquareToCoords(square); + promoted[x][y] = true; + } } } @@ -197,7 +212,7 @@ class CrazyhouseRules extends ChessRules super.updateVariables(move); if (move.vanish.length == 2 && move.appear.length == 2) return; //skip castle - const color = this.turn; + const color = move.appear[0].c; if (move.vanish.length == 0) { this.reserve[color][move.appear[0].p]--;