// Skill structure is used to implement strength limit
struct Skill {
- Skill(int l) : level(l) {}
+ explicit Skill(int l) : level(l) {}
bool enabled() const { return level < 20; }
bool time_to_pick(Depth depth) const { return depth / ONE_PLY == 1 + level; }
- Move best_move(size_t multiPV) { return best ? best : pick_best(multiPV); }
Move pick_best(size_t multiPV);
int level;
void update_pv(Move* pv, Move move, Move* childPv);
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus);
void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, int bonus);
+ bool pv_is_draw(Position& pos);
// perft() is our utility to verify move generation. All the leaf nodes up
// to the given depth are generated and counted, and the sum is returned.
Thread::search(); // Let's start searching!
}
- // When playing in 'nodes as time' mode, subtract the searched nodes from
- // the available ones before exiting.
- if (Limits.npmsec)
- Time.availableNodes += Limits.inc[us] - Threads.nodes_searched();
-
// When we reach the maximum depth, we can arrive here without a raise of
// Threads.stop. However, if we are pondering or in an infinite search,
// the UCI protocol states that we shouldn't print the best move before the
if (th != this)
th->wait_for_search_finished();
+ // When playing in 'nodes as time' mode, subtract the searched nodes from
+ // the available ones before exiting.
+ if (Limits.npmsec)
+ Time.availableNodes += Limits.inc[us] - Threads.nodes_searched();
+
// Check if there are threads with a better score than main thread
Thread* bestThread = this;
if ( !this->easyMovePlayed
// from the previous search and just did a fast verification.
const int F[] = { mainThread->failedLow,
bestValue - mainThread->previousScore };
-
int improvingFactor = std::max(229, std::min(715, 357 + 119 * F[0] - 6 * F[1]));
- double unstablePvFactor = 1 + mainThread->bestMoveChanges;
+
+ Color us = rootPos.side_to_move();
+ bool thinkHard = DrawValue[us] == bestValue
+ && Limits.time[us] - Time.elapsed() > Limits.time[~us]
+ && ::pv_is_draw(rootPos);
+
+ double unstablePvFactor = 1 + mainThread->bestMoveChanges + thinkHard;
bool doEasyMove = rootMoves[0].pv[0] == easyMove
+ && !thinkHard
&& mainThread->bestMoveChanges < 0.03
&& Time.elapsed() > Time.optimum() * 5 / 44;
// If skill level is enabled, swap best PV line with the sub-optimal one
if (skill.enabled())
- std::swap(rootMoves[0], *std::find(rootMoves.begin(),
- rootMoves.end(), skill.best_move(multiPV)));
+ std::swap(rootMoves[0], *std::find(rootMoves.begin(), rootMoves.end(),
+ skill.best ? skill.best : skill.pick_best(multiPV)));
}
Depth extension, newDepth;
Value bestValue, value, ttValue, eval;
bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
- bool captureOrPromotion, doFullDepthSearch, moveCountPruning, skipQuiets, ttCapture;
+ bool captureOrPromotion, doFullDepthSearch, moveCountPruning, skipQuiets, ttCapture, pvExact;
Piece movedPiece;
int moveCount, quietCount;
&& tte->depth() >= depth - 3 * ONE_PLY;
skipQuiets = false;
ttCapture = false;
+ pvExact = PvNode && ttHit && tte->bound() == BOUND_EXACT;
// Step 11. Loop through moves
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
if ((ss-1)->moveCount > 15)
r -= ONE_PLY;
+ // Decrease reduction for exact PV nodes
+ if (pvExact)
+ r -= ONE_PLY;
+
// Increase reduction if ttMove is a capture
if (ttCapture)
r += ONE_PLY;
- 4000;
// Decrease/increase reduction by comparing opponent's stat score
- if (ss->statScore > 0 && (ss-1)->statScore < 0)
+ if (ss->statScore >= 0 && (ss-1)->statScore < 0)
r -= ONE_PLY;
- else if (ss->statScore < 0 && (ss-1)->statScore > 0)
+ else if ((ss-1)->statScore >= 0 && ss->statScore < 0)
r += ONE_PLY;
// Decrease/increase reduction for moves with a good/bad history
}
+ // Is the PV leading to a draw position? Assumes all pv moves are legal
+ bool pv_is_draw(Position& pos) {
+
+ StateInfo st[MAX_PLY];
+ auto& pv = pos.this_thread()->rootMoves[0].pv;
+
+ for (size_t i = 0; i < pv.size(); ++i)
+ pos.do_move(pv[i], st[i]);
+
+ bool isDraw = pos.is_draw(pv.size());
+
+ for (size_t i = pv.size(); i > 0; --i)
+ pos.undo_move(pv[i-1]);
+
+ return isDraw;
+ }
+
+
// When playing with strength handicap, choose best move among a set of RootMoves
// using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
int push = ( weakness * int(topScore - rootMoves[i].score)
+ delta * (rng.rand<unsigned>() % weakness)) / 128;
- if (rootMoves[i].score + push > maxScore)
+ if (rootMoves[i].score + push >= maxScore)
{
maxScore = rootMoves[i].score + push;
best = rootMoves[i].pv[0];
ProbeDepth = Options["SyzygyProbeDepth"] * ONE_PLY;
Cardinality = Options["SyzygyProbeLimit"];
+ // Don't filter any moves if the user requested analysis on multiple
+ if (Options["MultiPV"] != 1)
+ return;
+
// Skip TB probing when no TB found: !TBLargest -> !TB::Cardinality
if (Cardinality > MaxCardinality)
{