Skip to content

Commit

Permalink
Ensure a pondermove is always returned and tweak time management
Browse files Browse the repository at this point in the history
Previously, if the search stopped after an aspiration fail-high, no ponder move could be extracted from the PV.
This patch allows using the TT as a fallback for these cases.
Also, the previous time management led to some time losses when pondering was enabled under short TCs. The strategy is updated to consider pondering time in the allocated search time.

Non-regression STC:
LLR:  2.95/2.94<-6.00, 0.00> Elo diff: 0.07 [-2.19, 2.34] (95%)
Games: 18782 W: 2444 L: 2440 D: 13898 Draw ratio: 74.0%
Pntl: [96, 1567, 6062, 1569, 97]

STC w/ pondering (both sides):
LLR:  2.97/2.94<0.00, 10.00> Elo diff: 45.64 [27.86, 63.67] (95%)
Games: 490 W: 123 L: 59 D: 308 Draw ratio: 62.9%
Pntl: [1, 36, 123, 68, 17]

No functional change
  • Loading branch information
ruicoelhopedro committed Jan 7, 2024
1 parent ccd1500 commit e5385c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/Search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace Search
{
m_timer = timer;
m_managed = true;
m_movetime_ms = movetime_ms;
m_optimum = std::numeric_limits<double>::infinity();
m_pondering.store(ponder);
m_end_time.store(m_timer.begin() + std::chrono::milliseconds(movetime_ms));
Expand All @@ -63,7 +62,6 @@ namespace Search
{
m_timer = timer;
m_managed = true;
m_movetime_ms = movetime_ms;
m_optimum = optimum_ms / 1000.0;
m_pondering.store(ponder);
m_end_time.store(m_timer.begin() + std::chrono::milliseconds(movetime_ms));
Expand All @@ -72,8 +70,6 @@ namespace Search
void SearchTime::ponderhit()
{
m_pondering.store(false);
if (m_managed)
m_end_time.store(std::chrono::steady_clock::now() + std::chrono::milliseconds(m_movetime_ms));
}

bool SearchTime::pondering() const
Expand Down
1 change: 0 additions & 1 deletion src/Search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ namespace Search
Timer m_timer;
bool m_managed;
double m_optimum;
uint64_t m_movetime_ms;
std::atomic_bool m_pondering;
std::atomic<std::chrono::steady_clock::time_point> m_end_time;

Expand Down
10 changes: 10 additions & 0 deletions src/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ void Thread::search()
Move bestmove = *best_pv;
Move pondermove = *(best_pv + 1);

// If we get no pondermove from the PV, use the TT to try to guess a move to ponder
if (pondermove == MOVE_NULL)
{
m_position.make_move(bestmove);
TranspositionEntry* entry = nullptr;
if (ttable.query(m_position.hash(), &entry) && m_position.board().legal(entry->hash_move()))
pondermove = entry->hash_move();
m_position.unmake_move();
}

// Mandatory output to the GUI
std::cout << "bestmove " << m_position.board().to_uci(bestmove);
if (pondermove != MOVE_NULL)
Expand Down

0 comments on commit e5385c3

Please sign in to comment.