X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=3d9c743f8dc23bf510ccc4963b184951f8e3c81b;hp=afebcc35086b0e0ba0f85d022440a090faa8c5b1;hb=b6487fb9c41705187cf97215fc9e8f86a59057c7;hpb=643479f8d7c3622b57fc49c4f10d9950793ebf4f diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index afebcc35..3d9c743f 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]--;