From e5d081470b54204591beb313f0c42e187b0fbd7d Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Tue, 9 Feb 2021 20:30:22 +0100 Subject: [PATCH] Improve caching of must capture state 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 | 2 +- src/position.cpp | 27 ++------------------------- src/position.h | 24 +++++++++++++++++++++++- src/search.cpp | 3 +-- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/movepick.cpp b/src/movepick.cpp index 07093cd..dc93e1b 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -199,7 +199,7 @@ top: [[fallthrough]]; case QUIET_INIT: - if (!skipQuiets) + if (!skipQuiets && !(pos.must_capture() && pos.has_capture())) { cur = endBadCaptures; endMoves = generate(pos, cur); diff --git a/src/position.cpp b/src/position.cpp index c5176d3..59a289d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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(*this)) - if (capture(mevasion) && legal(mevasion)) - { - st->legalCapture = VALUE_TRUE; - return false; - } - } - else - { - for (const auto& mcap : MoveList(*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)) diff --git a/src/position.h b/src/position.h index 065ae67..f1d68c2 100644 --- a/src/position.h +++ b/src/position.h @@ -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(*this).size()); + // Check for cached value + if (st->legalCapture != NO_VALUE) + return st->legalCapture == VALUE_TRUE; + if (checkers()) + { + for (const auto& mevasion : MoveList(*this)) + if (capture(mevasion) && legal(mevasion)) + { + st->legalCapture = VALUE_TRUE; + return true; + } + } + else + { + for (const auto& mcap : MoveList(*this)) + if (capture(mcap) && legal(mcap)) + { + st->legalCapture = VALUE_TRUE; + return true; + } + } + st->legalCapture = VALUE_FALSE; + return false; } inline bool Position::must_drop() const { diff --git a/src/search.cpp b/src/search.cpp index c03a835..6164a1c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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); -- 1.7.0.4