Color RootColor;
Time::point SearchTime;
StateStackPtr SetupStates;
+ Value Contempt[2]; // [bestValue > VALUE_DRAW]
}
using std::string;
enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
// Dynamic razoring margin based on depth
- inline Value razor_margin(Depth d) { return Value(512 + 16 * int(d)); }
+ inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
// Futility lookup tables (initialized at startup) and their access functions
int FutilityMoveCounts[2][32]; // [improving][depth]
inline Value futility_margin(Depth d) {
- return Value(100 * int(d));
+ return Value(100 * d);
}
// Reduction lookup tables (initialized at startup) and their access function
{
double pvRed = 0.00 + log(double(hd)) * log(double(mc)) / 3.00;
double nonPVRed = 0.33 + log(double(hd)) * log(double(mc)) / 2.25;
- Reductions[1][1][hd][mc] = (int8_t) ( pvRed >= 1.0 ? floor( pvRed * int(ONE_PLY)) : 0);
- Reductions[0][1][hd][mc] = (int8_t) (nonPVRed >= 1.0 ? floor(nonPVRed * int(ONE_PLY)) : 0);
+ Reductions[1][1][hd][mc] = int8_t( pvRed >= 1.0 ? pvRed * int(ONE_PLY) : 0);
+ Reductions[0][1][hd][mc] = int8_t(nonPVRed >= 1.0 ? nonPVRed * int(ONE_PLY) : 0);
Reductions[1][0][hd][mc] = Reductions[1][1][hd][mc];
Reductions[0][0][hd][mc] = Reductions[0][1][hd][mc];
RootColor = RootPos.side_to_move();
TimeMgr.init(Limits, RootPos.game_ply(), RootColor);
- int cf = Options["Contempt Factor"] * PawnValueMg / 100; // From centipawns
- DrawValue[ RootColor] = VALUE_DRAW - Value(cf);
- DrawValue[~RootColor] = VALUE_DRAW + Value(cf);
+ DrawValue[0] = DrawValue[1] = VALUE_DRAW;
+ Contempt[0] = Options["Contempt Factor"] * PawnValueEg / 100; // From centipawns
+ Contempt[1] = (Options["Contempt Factor"] + 12) * PawnValueEg / 100;
if (RootMoves.empty())
{
<< " time: " << Limits.time[RootColor]
<< " increment: " << Limits.inc[RootColor]
<< " moves to go: " << Limits.movestogo
- << std::endl;
+ << "\n" << std::endl;
}
// Reset the threads, still sleeping: will wake up at split time
{
bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false);
+ DrawValue[ RootColor] = VALUE_DRAW - Contempt[bestValue > VALUE_DRAW];
+ DrawValue[~RootColor] = VALUE_DRAW + Contempt[bestValue > VALUE_DRAW];
+
// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
// first and eventually the new best one are set to -VALUE_INFINITE
: ttValue >= beta ? (tte->bound() & BOUND_LOWER)
: (tte->bound() & BOUND_UPPER)))
{
- TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
// If ttMove is quiet, update killers, history, counter move and followup move on TT hit
// Step 10. Internal iterative deepening (skipped when in check)
if ( depth >= (PvNode ? 5 * ONE_PLY : 8 * ONE_PLY)
&& !ttMove
- && (PvNode || ss->staticEval + Value(256) >= beta))
+ && (PvNode || ss->staticEval + 256 >= beta))
{
Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
if (predictedDepth < 7 * ONE_PLY)
{
futilityValue = ss->staticEval + futility_margin(predictedDepth)
- + Value(128) + Gains[pos.moved_piece(move)][to_sq(move)];
+ + 128 + Gains[pos.moved_piece(move)][to_sq(move)];
if (futilityValue <= alpha)
{
if (PvNode && bestValue > alpha)
alpha = bestValue;
- futilityBase = bestValue + Value(128);
+ futilityBase = bestValue + 128;
}
// Initialize a MovePicker object for the current position, and prepare
string uci_pv(const Position& pos, int depth, Value alpha, Value beta) {
- std::stringstream s;
+ std::stringstream ss;
Time::point elapsed = Time::now() - SearchTime + 1;
size_t uciPVSize = std::min((size_t)Options["MultiPV"], RootMoves.size());
int selDepth = 0;
int d = updated ? depth : depth - 1;
Value v = updated ? RootMoves[i].score : RootMoves[i].prevScore;
- if (s.rdbuf()->in_avail()) // Not at first line
- s << "\n";
+ if (ss.rdbuf()->in_avail()) // Not at first line
+ ss << "\n";
- s << "info depth " << d
- << " seldepth " << selDepth
- << " score " << (i == PVIdx ? score_to_uci(v, alpha, beta) : score_to_uci(v))
- << " nodes " << pos.nodes_searched()
- << " nps " << pos.nodes_searched() * 1000 / elapsed
- << " time " << elapsed
- << " multipv " << i + 1
- << " pv";
+ ss << "info depth " << d
+ << " seldepth " << selDepth
+ << " score " << (i == PVIdx ? score_to_uci(v, alpha, beta) : score_to_uci(v))
+ << " nodes " << pos.nodes_searched()
+ << " nps " << pos.nodes_searched() * 1000 / elapsed
+ << " time " << elapsed
+ << " multipv " << i + 1
+ << " pv";
for (size_t j = 0; RootMoves[i].pv[j] != MOVE_NONE; ++j)
- s << " " << move_to_uci(RootMoves[i].pv[j], pos.is_chess960());
+ ss << " " << move_to_uci(RootMoves[i].pv[j], pos.is_chess960());
}
- return s.str();
+ return ss.str();
}
} // namespace
mutex.lock();
// If we are master and all slaves have finished then exit idle_loop
- if (this_sp && !this_sp->slavesMask)
+ if (this_sp && this_sp->slavesMask.none())
{
mutex.unlock();
break;
searching = false;
activePosition = NULL;
- sp->slavesMask &= ~(1ULL << idx);
+ sp->slavesMask.reset(idx);
sp->nodes += pos.nodes_searched();
// Wake up the master thread so to allow it to return from the idle
// loop in case we are the last slave of the split point.
if ( Threads.sleepWhileIdle
&& this != sp->masterThread
- && !sp->slavesMask)
+ && sp->slavesMask.none())
{
assert(!sp->masterThread->searching);
sp->masterThread->notify_one();
// If this thread is the master of a split point and all slaves have finished
// their work at this split point, return from the idle loop.
- if (this_sp && !this_sp->slavesMask)
+ if (this_sp && this_sp->slavesMask.none())
{
this_sp->mutex.lock();
- bool finished = !this_sp->slavesMask; // Retest under lock protection
+ bool finished = this_sp->slavesMask.none(); // Retest under lock protection
this_sp->mutex.unlock();
if (finished)
return;
sp.mutex.lock();
nodes += sp.nodes;
- Bitboard sm = sp.slavesMask;
- while (sm)
- {
- Position* pos = Threads[pop_lsb(&sm)]->activePosition;
- if (pos)
- nodes += pos->nodes_searched();
- }
+
+ for (size_t idx = 0; idx < Threads.size(); ++idx)
+ if (sp.slavesMask.test(idx) && Threads[idx]->activePosition)
+ nodes += Threads[idx]->activePosition->nodes_searched();
sp.mutex.unlock();
}