Improve caching of must capture state
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 9 Feb 2021 19:30:22 +0000 (20:30 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 9 Feb 2021 19:30:22 +0000 (20:30 +0100)
giveaway STC
LLR: 2.97 (-2.94,2.94) [-10.00,5.00]
Total: 473 W: 222 L: 167 D: 84
http://www.variantfishtest.org:6543/tests/view/6021b77b6e23db669974e884

giveaway LTC
LLR: 2.98 (-2.94,2.94) [-10.00,5.00]
Total: 361 W: 168 L: 114 D: 79
http://www.variantfishtest.org:6543/tests/view/6021ba026e23db669974e893

losers STC
LLR: 2.99 (-2.94,2.94) [-10.00,5.00]
Total: 387 W: 204 L: 144 D: 39
http://www.variantfishtest.org:6543/tests/view/6021b78d6e23db669974e887

losers LTC
LLR: 2.97 (-2.94,2.94) [-10.00,5.00]
Total: 690 W: 329 L: 273 D: 88
http://www.variantfishtest.org:6543/tests/view/6021b9fb6e23db669974e891

src/movepick.cpp
src/position.cpp
src/position.h
src/search.cpp

index 07093cd..dc93e1b 100644 (file)
@@ -199,7 +199,7 @@ top:
       [[fallthrough]];
 
   case QUIET_INIT:
-      if (!skipQuiets)
+      if (!skipQuiets && !(pos.must_capture() && pos.has_capture()))
       {
           cur = endBadCaptures;
           endMoves = generate<QUIETS>(pos, cur);
index c5176d3..59a289d 100644 (file)
@@ -875,31 +875,8 @@ bool Position::legal(Move m) const {
       return false;
 
   // Illegal quiet moves
-  if (must_capture() && !capture(m) && st->legalCapture != VALUE_FALSE)
-  {
-      // Check for cached value
-      if (st->legalCapture == VALUE_TRUE)
-          return false;
-      if (checkers())
-      {
-          for (const auto& mevasion : MoveList<EVASIONS>(*this))
-              if (capture(mevasion) && legal(mevasion))
-              {
-                  st->legalCapture = VALUE_TRUE;
-                  return false;
-              }
-      }
-      else
-      {
-          for (const auto& mcap : MoveList<CAPTURES>(*this))
-              if (capture(mcap) && legal(mcap))
-              {
-                  st->legalCapture = VALUE_TRUE;
-                  return false;
-              }
-      }
-      st->legalCapture = VALUE_FALSE;
-  }
+  if (must_capture() && !capture(m) && has_capture())
+      return false;
 
   // Illegal non-drop moves
   if (must_drop() && type_of(m) != DROP && count_in_hand(us, var->mustDropType))
index 065ae67..f1d68c2 100644 (file)
@@ -516,7 +516,29 @@ inline bool Position::must_capture() const {
 }
 
 inline bool Position::has_capture() const {
-  return st->legalCapture == VALUE_TRUE || (st->legalCapture == NO_VALUE && MoveList<CAPTURES>(*this).size());
+  // Check for cached value
+  if (st->legalCapture != NO_VALUE)
+      return st->legalCapture == VALUE_TRUE;
+  if (checkers())
+  {
+      for (const auto& mevasion : MoveList<EVASIONS>(*this))
+          if (capture(mevasion) && legal(mevasion))
+          {
+              st->legalCapture = VALUE_TRUE;
+              return true;
+          }
+  }
+  else
+  {
+      for (const auto& mcap : MoveList<CAPTURES>(*this))
+          if (capture(mcap) && legal(mcap))
+          {
+              st->legalCapture = VALUE_TRUE;
+              return true;
+          }
+  }
+  st->legalCapture = VALUE_FALSE;
+  return false;
 }
 
 inline bool Position::must_drop() const {
index c03a835..6164a1c 100644 (file)
@@ -1114,8 +1114,7 @@ moves_loop: // When in check, search starts from here
           && bestValue > VALUE_TB_LOSS_IN_MAX_PLY)
       {
           // Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
-          moveCountPruning = moveCount >= futility_move_count(improving, depth)
-                            || (pos.must_capture() && (moveCountPruning || pos.capture(move)));
+          moveCountPruning = moveCount >= futility_move_count(improving, depth);
 
           // Reduced depth of the next LMR search
           int lmrDepth = std::max(newDepth - reduction(improving, depth, moveCount), 0);