Speed up computer thinking, fix Zen ep
authorBenjamin Auder <benjamin.auder@somewhere>
Sun, 18 Nov 2018 11:27:35 +0000 (12:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sun, 18 Nov 2018 11:27:35 +0000 (12:27 +0100)
public/javascripts/base_rules.js
public/javascripts/variants/Zen.js

index b604e79..d8ec34a 100644 (file)
@@ -98,6 +98,7 @@ class ChessRules
                                j++;
                        }
                }
+               // TODO: since we keep moves stack, next 2 are redundant
                let epSq = undefined;
                if (fenParts[2] != "-")
                {
@@ -838,8 +839,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 +849,7 @@ class ChessRules
                }
                if (depth == 0)
       return this.evalPosition();
+               const moves = this.getAllValidMoves(color);
     let v = color=="w" ? -1000 : 1000;
                if (color == "w")
                {
index d9e2294..96dd8f9 100644 (file)
@@ -1,5 +1,11 @@
 class ZenRules extends ChessRules
 {
+       // NOTE: enPassant, if enabled, would need to redefine carefully getEpSquare
+       getEpSquare(move)
+       {
+               return undefined;
+       }
+
        // TODO: some duplicated code in 2 next functions
        getSlideNJumpMoves(x, y, color, steps, oneStep)
        {
@@ -135,21 +141,7 @@ class ZenRules extends ChessRules
                        });
                }
 
-               // En passant
-               const Lep = this.epSquares.length;
-               const epSquare = Lep>0 ? this.epSquares[Lep-1] : undefined;
-               if (!!epSquare && epSquare.x == x+shift && Math.abs(epSquare.y - y) == 1)
-               {
-                       let epStep = epSquare.y - y;
-                       var enpassantMove = this.getBasicMove(x, y, x+shift, y+epStep);
-                       enpassantMove.vanish.push({
-                               x: x,
-                               y: y+epStep,
-                               p: 'p',
-                               c: this.getColor(x,y+epStep)
-                       });
-                       moves.push(enpassantMove);
-               }
+               // No en passant here
 
                // Add "zen" captures
                Array.prototype.push.apply(moves, this.findCaptures(x, y, color));