Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

Commit a4230fc

Browse files
committed
Implemented pondering
1 parent 4223d41 commit a4230fc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

backend.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
#include "gtb.h"
2727

2828
Backend::Backend()
29-
: m_mode(Backend::EngineMode_force), m_searchInProgress(false), m_maxDepth(0), m_showThinking(false),
29+
: m_mode(Backend::EngineMode_force),
30+
m_searchInProgress(false),
31+
m_maxDepth(0),
32+
m_showThinking(false),
33+
m_pondering(false),
3034
m_whiteClock(ChessClock::CONVENTIONAL_INCREMENTAL_MODE, 0, 300, 0),
3135
m_blackClock(ChessClock::CONVENTIONAL_INCREMENTAL_MODE, 0, 300, 0),
3236
m_tTable(DEFAULT_TTABLE_SIZE / sizeof(TTEntry)),
@@ -394,6 +398,20 @@ void Backend::StartSearch_(Search::SearchType searchType)
394398
m_whiteClock.Stop();
395399
m_blackClock.Start();
396400
}
401+
402+
if (m_pondering)
403+
{
404+
// we have to do this in a new thread so that the search thread itself can die
405+
auto startPonderThreadFunc = [this]()
406+
{
407+
std::lock_guard<std::mutex> lock(m_mutex);
408+
StopSearch_(lock);
409+
StartSearch_(Search::SearchType_infinite);
410+
};
411+
412+
std::thread t(startPonderThreadFunc);
413+
t.detach();
414+
}
397415
};
398416

399417
m_search.reset(new Search::AsyncSearch(*m_searchContext));

backend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Backend
6363

6464
void SetAnalyzing(bool enabled);
6565

66+
void SetPondering(bool enabled) { std::lock_guard<std::mutex> lock(m_mutex); m_pondering = enabled; }
67+
6668
void Undo(int32_t moves);
6769

6870
void SetTimeControl(const ChessClock &cc)
@@ -122,6 +124,8 @@ class Backend
122124

123125
bool m_showThinking;
124126

127+
bool m_pondering;
128+
125129
ChessClock m_whiteClock;
126130
ChessClock m_blackClock;
127131

0 commit comments

Comments
 (0)