mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Small code stye fixes
Among them restore the original rootPos name for the starting position. No functional change.
This commit is contained in:
parent
a75e45b37e
commit
6f997a83d6
3 changed files with 51 additions and 57 deletions
|
@ -225,8 +225,8 @@ template uint64_t Search::perft<true>(Position& pos, Depth depth);
|
||||||
|
|
||||||
void MainThread::think() {
|
void MainThread::think() {
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = rootPos.side_to_move();
|
||||||
Time.init(Limits, us, pos.game_ply());
|
Time.init(Limits, us, rootPos.game_ply());
|
||||||
|
|
||||||
int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
|
int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
|
||||||
DrawValue[ us] = VALUE_DRAW - Value(contempt);
|
DrawValue[ us] = VALUE_DRAW - Value(contempt);
|
||||||
|
@ -249,17 +249,17 @@ void MainThread::think() {
|
||||||
{
|
{
|
||||||
rootMoves.push_back(RootMove(MOVE_NONE));
|
rootMoves.push_back(RootMove(MOVE_NONE));
|
||||||
sync_cout << "info depth 0 score "
|
sync_cout << "info depth 0 score "
|
||||||
<< UCI::value(pos.checkers() ? -VALUE_MATE : VALUE_DRAW)
|
<< UCI::value(rootPos.checkers() ? -VALUE_MATE : VALUE_DRAW)
|
||||||
<< sync_endl;
|
<< sync_endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (TB::Cardinality >= pos.count<ALL_PIECES>(WHITE)
|
if (TB::Cardinality >= rootPos.count<ALL_PIECES>(WHITE)
|
||||||
+ pos.count<ALL_PIECES>(BLACK))
|
+ rootPos.count<ALL_PIECES>(BLACK))
|
||||||
{
|
{
|
||||||
// If the current root position is in the tablebases then RootMoves
|
// If the current root position is in the tablebases then RootMoves
|
||||||
// contains only moves that preserve the draw or win.
|
// contains only moves that preserve the draw or win.
|
||||||
TB::RootInTB = Tablebases::root_probe(pos, rootMoves, TB::Score);
|
TB::RootInTB = Tablebases::root_probe(rootPos, rootMoves, TB::Score);
|
||||||
|
|
||||||
if (TB::RootInTB)
|
if (TB::RootInTB)
|
||||||
TB::Cardinality = 0; // Do not probe tablebases during the search
|
TB::Cardinality = 0; // Do not probe tablebases during the search
|
||||||
|
@ -267,7 +267,7 @@ void MainThread::think() {
|
||||||
else // If DTZ tables are missing, use WDL tables as a fallback
|
else // If DTZ tables are missing, use WDL tables as a fallback
|
||||||
{
|
{
|
||||||
// Filter out moves that do not preserve a draw or win
|
// Filter out moves that do not preserve a draw or win
|
||||||
TB::RootInTB = Tablebases::root_probe_wdl(pos, rootMoves, TB::Score);
|
TB::RootInTB = Tablebases::root_probe_wdl(rootPos, rootMoves, TB::Score);
|
||||||
|
|
||||||
// Only probe during search if winning
|
// Only probe during search if winning
|
||||||
if (TB::Score <= VALUE_DRAW)
|
if (TB::Score <= VALUE_DRAW)
|
||||||
|
@ -292,7 +292,7 @@ void MainThread::think() {
|
||||||
th->searching = true;
|
th->searching = true;
|
||||||
if (th != this)
|
if (th != this)
|
||||||
{
|
{
|
||||||
th->pos = Position(pos, th);
|
th->rootPos = Position(rootPos, th);
|
||||||
th->rootMoves = rootMoves;
|
th->rootMoves = rootMoves;
|
||||||
th->notify_one(); // Wake up the thread and start searching
|
th->notify_one(); // Wake up the thread and start searching
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ void MainThread::think() {
|
||||||
Threads.timer->run = true;
|
Threads.timer->run = true;
|
||||||
Threads.timer->notify_one(); // Start the recurring timer
|
Threads.timer->notify_one(); // Start the recurring timer
|
||||||
|
|
||||||
search(true); // Here we go!
|
search(true); // Let's start searching!
|
||||||
|
|
||||||
// Stop the threads and the timer
|
// Stop the threads and the timer
|
||||||
Signals.stop = true;
|
Signals.stop = true;
|
||||||
|
@ -329,10 +329,10 @@ void MainThread::think() {
|
||||||
wait(Signals.stop);
|
wait(Signals.stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_cout << "bestmove " << UCI::move(rootMoves[0].pv[0], pos.is_chess960());
|
sync_cout << "bestmove " << UCI::move(rootMoves[0].pv[0], rootPos.is_chess960());
|
||||||
|
|
||||||
if (rootMoves[0].pv.size() > 1 || rootMoves[0].extract_ponder_from_tt(pos))
|
if (rootMoves[0].pv.size() > 1 || rootMoves[0].extract_ponder_from_tt(rootPos))
|
||||||
std::cout << " ponder " << UCI::move(rootMoves[0].pv[1], pos.is_chess960());
|
std::cout << " ponder " << UCI::move(rootMoves[0].pv[1], rootPos.is_chess960());
|
||||||
|
|
||||||
std::cout << sync_endl;
|
std::cout << sync_endl;
|
||||||
}
|
}
|
||||||
|
@ -344,23 +344,23 @@ void MainThread::think() {
|
||||||
|
|
||||||
void Thread::search(bool isMainThread) {
|
void Thread::search(bool isMainThread) {
|
||||||
|
|
||||||
|
Stack* ss = stack + 2; // To allow referencing (ss-2) and (ss+2)
|
||||||
Value bestValue, alpha, beta, delta;
|
Value bestValue, alpha, beta, delta;
|
||||||
|
|
||||||
Move easyMove = MOVE_NONE;
|
Move easyMove = MOVE_NONE;
|
||||||
if (isMainThread)
|
|
||||||
{
|
|
||||||
easyMove = EasyMove.get(pos.key());
|
|
||||||
EasyMove.clear();
|
|
||||||
BestMoveChanges = 0;
|
|
||||||
TT.new_search();
|
|
||||||
}
|
|
||||||
|
|
||||||
Stack* ss = stack+2; // To allow referencing (ss-2) and (ss+2)
|
|
||||||
std::memset(ss-2, 0, 5 * sizeof(Stack));
|
std::memset(ss-2, 0, 5 * sizeof(Stack));
|
||||||
|
|
||||||
bestValue = delta = alpha = -VALUE_INFINITE;
|
bestValue = delta = alpha = -VALUE_INFINITE;
|
||||||
beta = VALUE_INFINITE;
|
beta = VALUE_INFINITE;
|
||||||
|
|
||||||
|
if (isMainThread)
|
||||||
|
{
|
||||||
|
easyMove = EasyMove.get(rootPos.key());
|
||||||
|
EasyMove.clear();
|
||||||
|
BestMoveChanges = 0;
|
||||||
|
TT.new_search();
|
||||||
|
}
|
||||||
|
|
||||||
size_t multiPV = Options["MultiPV"];
|
size_t multiPV = Options["MultiPV"];
|
||||||
Skill skill(Options["Skill Level"]);
|
Skill skill(Options["Skill Level"]);
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ void Thread::search(bool isMainThread) {
|
||||||
// Iterative deepening loop until requested to stop or target depth reached
|
// Iterative deepening loop until requested to stop or target depth reached
|
||||||
while (++depth < DEPTH_MAX && !Signals.stop && (!Limits.depth || depth <= Limits.depth))
|
while (++depth < DEPTH_MAX && !Signals.stop && (!Limits.depth || depth <= Limits.depth))
|
||||||
{
|
{
|
||||||
// Set up our new depth for the helper threads
|
// Set up the new depth for the helper threads
|
||||||
if (!isMainThread)
|
if (!isMainThread)
|
||||||
depth = Threads.main()->depth + Depth(int(3 * log(1 + this->idx)));
|
depth = Threads.main()->depth + Depth(int(3 * log(1 + this->idx)));
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ void Thread::search(bool isMainThread) {
|
||||||
// high/low anymore.
|
// high/low anymore.
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
bestValue = ::search<Root>(pos, ss, alpha, beta, depth, false);
|
bestValue = ::search<Root>(rootPos, ss, alpha, beta, depth, false);
|
||||||
|
|
||||||
// Bring the best move to the front. It is critical that sorting
|
// Bring the best move to the front. It is critical that sorting
|
||||||
// is done with a stable algorithm because all the values but the
|
// is done with a stable algorithm because all the values but the
|
||||||
|
@ -411,13 +411,12 @@ void Thread::search(bool isMainThread) {
|
||||||
// and we want to keep the same order for all the moves except the
|
// and we want to keep the same order for all the moves except the
|
||||||
// new PV that goes to the front. Note that in case of MultiPV
|
// new PV that goes to the front. Note that in case of MultiPV
|
||||||
// search the already searched PV lines are preserved.
|
// search the already searched PV lines are preserved.
|
||||||
|
|
||||||
std::stable_sort(rootMoves.begin() + PVIdx, rootMoves.end());
|
std::stable_sort(rootMoves.begin() + PVIdx, rootMoves.end());
|
||||||
|
|
||||||
// Write PV back to transposition table in case the relevant
|
// Write PV back to transposition table in case the relevant
|
||||||
// entries have been overwritten during the search.
|
// entries have been overwritten during the search.
|
||||||
for (size_t i = 0; i <= PVIdx; ++i)
|
for (size_t i = 0; i <= PVIdx; ++i)
|
||||||
rootMoves[i].insert_pv_in_tt(pos);
|
rootMoves[i].insert_pv_in_tt(rootPos);
|
||||||
|
|
||||||
// If search has been stopped break immediately. Sorting and
|
// If search has been stopped break immediately. Sorting and
|
||||||
// writing PV back to TT is safe because RootMoves is still
|
// writing PV back to TT is safe because RootMoves is still
|
||||||
|
@ -425,15 +424,13 @@ void Thread::search(bool isMainThread) {
|
||||||
if (Signals.stop)
|
if (Signals.stop)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (isMainThread)
|
// When failing high/low give some update (without cluttering
|
||||||
{
|
// the UI) before a re-search.
|
||||||
// When failing high/low give some update (without cluttering
|
if ( isMainThread
|
||||||
// the UI) before a re-search.
|
&& multiPV == 1
|
||||||
if (multiPV == 1
|
&& (bestValue <= alpha || bestValue >= beta)
|
||||||
&& (bestValue <= alpha || bestValue >= beta)
|
&& Time.elapsed() > 3000)
|
||||||
&& Time.elapsed() > 3000)
|
sync_cout << UCI::pv(rootPos, depth, alpha, beta) << sync_endl;
|
||||||
sync_cout << UCI::pv(pos, depth, alpha, beta) << sync_endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case of failing low/high increase aspiration window and
|
// In case of failing low/high increase aspiration window and
|
||||||
// re-search, otherwise exit the loop.
|
// re-search, otherwise exit the loop.
|
||||||
|
@ -472,7 +469,7 @@ void Thread::search(bool isMainThread) {
|
||||||
<< " time " << Time.elapsed() << sync_endl;
|
<< " time " << Time.elapsed() << sync_endl;
|
||||||
|
|
||||||
else if (PVIdx + 1 == multiPV || Time.elapsed() > 3000)
|
else if (PVIdx + 1 == multiPV || Time.elapsed() > 3000)
|
||||||
sync_cout << UCI::pv(pos, depth, alpha, beta) << sync_endl;
|
sync_cout << UCI::pv(rootPos, depth, alpha, beta) << sync_endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMainThread)
|
if (!isMainThread)
|
||||||
|
@ -516,7 +513,7 @@ void Thread::search(bool isMainThread) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootMoves[0].pv.size() >= 3)
|
if (rootMoves[0].pv.size() >= 3)
|
||||||
EasyMove.update(pos, rootMoves[0].pv);
|
EasyMove.update(rootPos, rootMoves[0].pv);
|
||||||
else
|
else
|
||||||
EasyMove.clear();
|
EasyMove.clear();
|
||||||
}
|
}
|
||||||
|
@ -1436,22 +1433,22 @@ moves_loop: // When in check search starts from here
|
||||||
|
|
||||||
string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
||||||
|
|
||||||
Thread* thisThread = pos.this_thread();
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
int elapsed = Time.elapsed() + 1;
|
int elapsed = Time.elapsed() + 1;
|
||||||
size_t multiPV = std::min((size_t)Options["MultiPV"], thisThread->rootMoves.size());
|
const Search::RootMoveVector& rootMoves = pos.this_thread()->rootMoves;
|
||||||
int selDepth = thisThread->maxPly;
|
size_t PVIdx = pos.this_thread()->PVIdx;
|
||||||
uint64_t nodes = Threads.nodes_searched();
|
size_t multiPV = std::min((size_t)Options["MultiPV"], rootMoves.size());
|
||||||
|
uint64_t nodes_searched = Threads.nodes_searched();
|
||||||
|
|
||||||
for (size_t i = 0; i < multiPV; ++i)
|
for (size_t i = 0; i < multiPV; ++i)
|
||||||
{
|
{
|
||||||
bool updated = (i <= thisThread->PVIdx);
|
bool updated = (i <= PVIdx);
|
||||||
|
|
||||||
if (depth == ONE_PLY && !updated)
|
if (depth == ONE_PLY && !updated)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Depth d = updated ? depth : depth - ONE_PLY;
|
Depth d = updated ? depth : depth - ONE_PLY;
|
||||||
Value v = updated ? thisThread->rootMoves[i].score : thisThread->rootMoves[i].previousScore;
|
Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore;
|
||||||
|
|
||||||
bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
|
bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
|
||||||
v = tb ? TB::Score : v;
|
v = tb ? TB::Score : v;
|
||||||
|
@ -1461,15 +1458,15 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
||||||
|
|
||||||
ss << "info"
|
ss << "info"
|
||||||
<< " depth " << d / ONE_PLY
|
<< " depth " << d / ONE_PLY
|
||||||
<< " seldepth " << selDepth
|
<< " seldepth " << pos.this_thread()->maxPly
|
||||||
<< " multipv " << i + 1
|
<< " multipv " << i + 1
|
||||||
<< " score " << UCI::value(v);
|
<< " score " << UCI::value(v);
|
||||||
|
|
||||||
if (!tb && i == thisThread->PVIdx)
|
if (!tb && i == PVIdx)
|
||||||
ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
|
ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
|
||||||
|
|
||||||
ss << " nodes " << nodes
|
ss << " nodes " << nodes_searched
|
||||||
<< " nps " << nodes * 1000 / elapsed;
|
<< " nps " << nodes_searched * 1000 / elapsed;
|
||||||
|
|
||||||
if (elapsed > 1000) // Earlier makes little sense
|
if (elapsed > 1000) // Earlier makes little sense
|
||||||
ss << " hashfull " << TT.hashfull();
|
ss << " hashfull " << TT.hashfull();
|
||||||
|
@ -1478,7 +1475,7 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
|
||||||
<< " time " << elapsed
|
<< " time " << elapsed
|
||||||
<< " pv";
|
<< " pv";
|
||||||
|
|
||||||
for (Move m : thisThread->rootMoves[i].pv)
|
for (Move m : rootMoves[i].pv)
|
||||||
ss << " " << UCI::move(m, pos.is_chess960());
|
ss << " " << UCI::move(m, pos.is_chess960());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,9 +1568,6 @@ void check_time() {
|
||||||
else if (Limits.movetime && elapsed >= Limits.movetime)
|
else if (Limits.movetime && elapsed >= Limits.movetime)
|
||||||
Signals.stop = true;
|
Signals.stop = true;
|
||||||
|
|
||||||
else if (Limits.nodes)
|
else if (Limits.nodes && Threads.nodes_searched() >= Limits.nodes)
|
||||||
{
|
|
||||||
if (Threads.nodes_searched() >= Limits.nodes)
|
|
||||||
Signals.stop = true;
|
Signals.stop = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,10 +223,10 @@ void ThreadPool::read_uci_options() {
|
||||||
|
|
||||||
int64_t ThreadPool::nodes_searched() {
|
int64_t ThreadPool::nodes_searched() {
|
||||||
|
|
||||||
int64_t nodes = 0;
|
int64_t nodes = 0;
|
||||||
for (Thread *th : *this)
|
for (Thread *th : *this)
|
||||||
nodes += th->pos.nodes_searched();
|
nodes += th->rootPos.nodes_searched();
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
||||||
Signals.stop = Signals.failedLowAtRoot = false;
|
Signals.stop = Signals.failedLowAtRoot = false;
|
||||||
|
|
||||||
main()->rootMoves.clear();
|
main()->rootMoves.clear();
|
||||||
main()->pos = pos;
|
main()->rootPos = pos;
|
||||||
Limits = limits;
|
Limits = limits;
|
||||||
if (states.get()) // If we don't set a new position, preserve current state
|
if (states.get()) // If we don't set a new position, preserve current state
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,7 +74,7 @@ struct Thread : public ThreadBase {
|
||||||
int maxPly;
|
int maxPly;
|
||||||
volatile bool searching;
|
volatile bool searching;
|
||||||
|
|
||||||
Position pos;
|
Position rootPos;
|
||||||
Search::RootMoveVector rootMoves;
|
Search::RootMoveVector rootMoves;
|
||||||
Search::Stack stack[MAX_PLY+4];
|
Search::Stack stack[MAX_PLY+4];
|
||||||
HistoryStats History;
|
HistoryStats History;
|
||||||
|
|
Loading…
Add table
Reference in a new issue