Skip to content

Commit

Permalink
show full PV in vcfsearch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dhbloo committed Jun 12, 2024
1 parent 0d1d79c commit 1bec5d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
20 changes: 9 additions & 11 deletions Rapfi/search/ab/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainSearchThread *>(thisThread)->checkExit();

// Check if the board has been filled or we have reached the max game ply.
Expand Down Expand Up @@ -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<MainSearchThread *>(thisThread),
timectl,
searchData->pvIdx,
Expand Down Expand Up @@ -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<Rule>(depth, formerPv), -VALUE_MATE);
bool formerPv = !PvNode && ss->ttPv;
Value singularBeta =
std::max(ttValue - singularMargin<Rule>(depth, formerPv), -VALUE_MATE);

// Backup current P4
// Pattern4 moveP4Backup[SIDE_NB] = {ss->moveP4[BLACK], ss->moveP4[WHITE]};
Expand Down Expand Up @@ -1210,7 +1211,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth
// Step 17. Undo move
board.undo<Rule>();

if (RootNode && thisThread->id == 0)
if (RootNode && thisThread->isMainThread())
searcher->printer.printLeavingMove(*static_cast<MainSearchThread *>(thisThread),
timectl,
searchData->pvIdx,
Expand Down Expand Up @@ -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<MainSearchThread *>(thisThread),
timectl,
searchData->pvIdx,
Expand Down Expand Up @@ -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<MainSearchThread *>(thisThread)->checkExit();

// Check if the board has been filled or we have reached the max game ply.
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 14 additions & 7 deletions Rapfi/search/searchthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <typename SD>
SD *searchDataAs() const
{
return static_cast<SD *>(searchData.get());
}
/// Get the search data as a specific type.
template <typename SearchDataType>
SearchDataType *searchDataAs() const;

/// Get the shared search options.
SearchOptions &options() const;

/// Reference to the thread pool that this thread belongs to.
Expand Down Expand Up @@ -222,7 +223,13 @@ class ThreadPool : public std::vector<std::unique_ptr<SearchThread>>
ThreadPool();
};

inline SearchOptions &Search::SearchThread::options() const
template <typename SearchDataType>
inline SearchDataType *SearchThread::searchDataAs() const
{
return static_cast<SearchDataType *>(searchData.get());
}

inline SearchOptions &SearchThread::options() const
{
assert(threads.main());
return threads.main()->searchOptions;
Expand Down

0 comments on commit 1bec5d0

Please sign in to comment.