X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=public%2Fjavascripts%2Fvariants%2FCrazyhouse.js;h=1fff1e919109058117158c743196238bf753c4a3;hb=fb6ceeff17b53ab049e14d2bee7a61de92ca4762;hp=afebcc35086b0e0ba0f85d022440a090faa8c5b1;hpb=f1cb85f915a7734b6900527039f505c391b234e5;p=vchess.git diff --git a/public/javascripts/variants/Crazyhouse.js b/public/javascripts/variants/Crazyhouse.js index afebcc35..1fff1e91 100644 --- a/public/javascripts/variants/Crazyhouse.js +++ b/public/javascripts/variants/Crazyhouse.js @@ -24,10 +24,21 @@ class CrazyhouseRules extends ChessRules return true; } + static ParseFen(fen) + { + const fenParts = fen.split(" "); + return Object.assign( + ChessRules.ParseFen(fen), + { + reserve: fenParts[4], + promoted: fenParts[5], + } + ); + } + static GenRandInitFen() { - const fen = ChessRules.GenRandInitFen(); - return fen.replace(" w 1111", " w 1111 0000000000 -"); + return ChessRules.GenRandInitFen() + " 0000000000 -"; } getFen() @@ -59,6 +70,8 @@ class CrazyhouseRules extends ChessRules } if (res.length > 0) res = res.slice(0,-1); //remove last comma + else + res = "-"; return res; } @@ -87,10 +100,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; + } } }