X-Git-Url: https://git.auder.net/images/diag_mark.svg?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=3a0f1c6332d1c4d4b5b2dc48c5a4c96d0bae3b47;hb=f3802fcd1279e5d07cdff1341fc5e17c5296dc9c;hp=b604e7970ffc357c4b05b0217836756485bde3c6;hpb=4b5fe3061829e184f9ad86a13d831eda22d95343;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index b604e797..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,14 +98,8 @@ class ChessRules j++; } } - 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",...] @@ -838,8 +832,7 @@ class ChessRules alphabeta(color, oppCol, depth, alpha, beta) { - const moves = this.getAllValidMoves(color); - if (moves.length == 0) + if (!this.atLeastOneMove(color)) { switch (this.checkGameEnd(color)) { @@ -849,6 +842,7 @@ class ChessRules } if (depth == 0) return this.evalPosition(); + const moves = this.getAllValidMoves(color); let v = color=="w" ? -1000 : 1000; if (color == "w") { @@ -949,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()