From 1bec5d02174e89cbc5018bb93745cae2ed54b00b Mon Sep 17 00:00:00 2001 From: dhb <1084714805@qq.com> Date: Wed, 12 Jun 2024 14:52:51 +0800 Subject: [PATCH] show full PV in vcfsearch Always show full length bestline even if the last part is in vcfsearch. This may introduce a little bit speed loss. Passed STC non-regressive test on s15: Total/Win/Draw/Lose: 13128 / 3556 / 6044 / 3528 PTNML: 391 / 1413 / 2907 / 1483 / 370 WinRate: 50.11% ELO: 0.05[-4.73, 4.68] LOS: 50.82 LLR: 1.47[-1.39, 1.39] Failed STC non-regressive test on r15: Total/Win/Draw/Lose: 15080 / 5784 / 3485 / 5811 PTNML: 883 / 1220 / 3340 / 1235 / 862 WinRate: 49.91% ELO: -0.98[-6.14, 4.00] LOS: 35.02 LLR: 1.13[-1.39, 1.39] bench ee2fe9a5 bench (msvc clang) 1500e0f4 --- Rapfi/search/ab/search.cpp | 20 +++++++++----------- Rapfi/search/searchthread.h | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Rapfi/search/ab/search.cpp b/Rapfi/search/ab/search.cpp index 01b8c8c1..021df22c 100644 --- a/Rapfi/search/ab/search.cpp +++ b/Rapfi/search/ab/search.cpp @@ -665,7 +665,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth if (!RootNode) { // Step 2. Check for aborted search and immediate draw // Check if we reach the time limit - if (thisThread->id == 0) + if (thisThread->isMainThread()) static_cast(thisThread)->checkExit(); // Check if the board has been filled or we have reached the max game ply. @@ -977,7 +977,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth curNumNodes = thisThread->numNodes.load(std::memory_order_relaxed); } - if (RootNode && thisThread->id == 0) + if (RootNode && thisThread->isMainThread()) searcher->printer.printEnteringMove(*static_cast(thisThread), timectl, searchData->pvIdx, @@ -1033,8 +1033,9 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth && (ttBound & BOUND_LOWER) // ttMove failed high last time && ttDepth >= depth - SE_TTE_DEPTH // ttEntry has enough depth to trust ) { - bool formerPv = !PvNode && ss->ttPv; - Value singularBeta = std::max(ttValue - singularMargin(depth, formerPv), -VALUE_MATE); + bool formerPv = !PvNode && ss->ttPv; + Value singularBeta = + std::max(ttValue - singularMargin(depth, formerPv), -VALUE_MATE); // Backup current P4 // Pattern4 moveP4Backup[SIDE_NB] = {ss->moveP4[BLACK], ss->moveP4[WHITE]}; @@ -1210,7 +1211,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth // Step 17. Undo move board.undo(); - if (RootNode && thisThread->id == 0) + if (RootNode && thisThread->isMainThread()) searcher->printer.printLeavingMove(*static_cast(thisThread), timectl, searchData->pvIdx, @@ -1315,7 +1316,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth } } - if (RootNode && thisThread->id == 0) + if (RootNode && thisThread->isMainThread()) searcher->printer.printMoveResult(*static_cast(thisThread), timectl, searchData->pvIdx, @@ -1485,7 +1486,7 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de // Step 2. Check for immediate draw and winning // Check if we reach the time limit - if (thisThread->id == 0) + if (thisThread->isMainThread()) static_cast(thisThread)->checkExit(); // Check if the board has been filled or we have reached the max game ply. @@ -1522,10 +1523,7 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de bool ttHit = TT.probe(posKey, ttValue, ttEval, ttIsPv, ttBound, ttMove, ttDepth, ss->ply); // Check for an early TT cutoff (for all types of nodes) - if (ttHit && ttDepth >= depth -#ifdef EMSCRIPTEN - && (!PvNode || thisThread->id != 0) // Show full PV for wasm build -#endif + if (ttHit && ttDepth >= depth && (!PvNode || !thisThread->isMainThread()) // Show full PV ) { if (ttBound & BOUND_LOWER) alpha = std::max(alpha, ttValue); diff --git a/Rapfi/search/searchthread.h b/Rapfi/search/searchthread.h index bdfcc962..f77ec5d2 100644 --- a/Rapfi/search/searchthread.h +++ b/Rapfi/search/searchthread.h @@ -18,8 +18,8 @@ #pragma once -#include "../database/dbstorage.h" #include "../database/dbclient.h" +#include "../database/dbstorage.h" #include "../eval/evaluator.h" #include "../game/board.h" #include "searchcommon.h" @@ -81,13 +81,14 @@ struct SearchThread /// Search entry point. After entering main thread search function, all threads are /// waked up by the main thread, then this function is called to start the search. virtual void search(); + /// Return if this thread is the main thread. + bool isMainThread() const { return id == 0; } - template - SD *searchDataAs() const - { - return static_cast(searchData.get()); - } + /// Get the search data as a specific type. + template + SearchDataType *searchDataAs() const; + /// Get the shared search options. SearchOptions &options() const; /// Reference to the thread pool that this thread belongs to. @@ -222,7 +223,13 @@ class ThreadPool : public std::vector> ThreadPool(); }; -inline SearchOptions &Search::SearchThread::options() const +template +inline SearchDataType *SearchThread::searchDataAs() const +{ + return static_cast(searchData.get()); +} + +inline SearchOptions &SearchThread::options() const { assert(threads.main()); return threads.main()->searchOptions;