X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=3a0f1c6332d1c4d4b5b2dc48c5a4c96d0bae3b47;hb=f3802fcd1279e5d07cdff1341fc5e17c5296dc9c;hp=d8ec34a0f7969d25f62f675e52bd8e8659e10cd2;hpb=a29d9d6b7703d680ddb49cd3fe096f49b1d774f5;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index d8ec34a0..3a0f1c63 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -52,8 +52,8 @@ class ChessRules this.moves = moves; // Use fen string to initialize variables, flags and board this.initVariables(fen); - this.flags = VariantRules.GetFlags(fen); this.board = VariantRules.GetBoard(fen); + this.flags = VariantRules.GetFlags(fen); } initVariables(fen) @@ -98,15 +98,8 @@ class ChessRules j++; } } - // TODO: since we keep moves stack, next 2 are redundant - let epSq = undefined; - if (fenParts[2] != "-") - { - const digits = fenParts[2].split(","); //3,2 ... - epSq = { x:Number.parseInt(digits[0]), y:Number.parseInt(digits[1]) }; - } + const epSq = this.moves.length > 0 ? this.getEpSquare(this.lastMove) : undefined; this.epSquares = [ epSq ]; - this.movesCount = Number.parseInt(fenParts[3]); } // Turn diagram fen into double array ["wb","wp","bk",...] @@ -950,19 +943,14 @@ class ChessRules let fen = pieces[0].join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + pieces[1].join("").toUpperCase() + - " 1111 - 0"; //flags + enPassant + movesCount + " 1111"; //add flags return fen; } // Return current fen according to pieces+colors state getFen() { - const L = this.epSquares.length; - const epSq = this.epSquares[L-1]===undefined - ? "-" - : this.epSquares[L-1].x+","+this.epSquares[L-1].y; - return this.getBaseFen() + " " + this.getFlagsFen() - + " " + epSq + " " + this.movesCount; + return this.getBaseFen() + " " + this.getFlagsFen(); } getBaseFen()