std::copy(newPv.begin(), newPv.begin() + 3, pv);
StateInfo st[2];
- pos.do_move(newPv[0], st[0], pos.gives_check(newPv[0]));
- pos.do_move(newPv[1], st[1], pos.gives_check(newPv[1]));
+ pos.do_move(newPv[0], st[0]);
+ pos.do_move(newPv[1], st[1]);
expectedPosKey = pos.key();
pos.undo_move(newPv[1]);
pos.undo_move(newPv[0]);
for (int mc = 1; mc < 64; ++mc)
{
double r = log(d) * log(mc) / 2;
- if (r < 0.80)
- continue;
Reductions[NonPV][imp][d][mc] = int(std::round(r));
Reductions[PV][imp][d][mc] = std::max(Reductions[NonPV][imp][d][mc] - 1, 0);
th->counterMoves.clear();
th->fromTo.clear();
th->counterMoveHistory.clear();
+ th->resetCalls = true;
}
Threads.main()->previousScore = VALUE_INFINITE;
cnt = 1, nodes++;
else
{
- pos.do_move(m, st, pos.gives_check(m));
+ pos.do_move(m, st);
cnt = leaf ? MoveList<LEGAL>(pos).size() : perft<false>(pos, depth - ONE_PLY);
nodes += cnt;
pos.undo_move(m);
void Thread::search() {
- Stack stack[MAX_PLY+7], *ss = stack+5; // To allow referencing (ss-5) and (ss+2)
+ Stack stack[MAX_PLY+7], *ss = stack+4; // To allow referencing (ss-4) and (ss+2)
Value bestValue, alpha, beta, delta;
Move easyMove = MOVE_NONE;
MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
- std::memset(ss-5, 0, 8 * sizeof(Stack));
+ std::memset(ss-4, 0, 7 * sizeof(Stack));
bestValue = delta = alpha = -VALUE_INFINITE;
beta = VALUE_INFINITE;
if (!mainThread)
continue;
- if (Signals.stop)
- sync_cout << "info nodes " << Threads.nodes_searched()
- << " time " << Time.elapsed() << sync_endl;
-
- else if (PVIdx + 1 == multiPV || Time.elapsed() > 3000)
+ if (Signals.stop || PVIdx + 1 == multiPV || Time.elapsed() > 3000)
sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl;
}
Thread* thisThread = pos.this_thread();
inCheck = pos.checkers();
moveCount = quietCount = ss->moveCount = 0;
+ ss->history = VALUE_ZERO;
bestValue = -VALUE_INFINITE;
ss->ply = (ss-1)->ply + 1;
if (thisThread->resetCalls.load(std::memory_order_relaxed))
{
thisThread->resetCalls = false;
- thisThread->callsCnt = 0;
+ // At low node count increase the checking rate to about 0.1% of nodes
+ // otherwise use a default value.
+ thisThread->callsCnt = Limits.nodes ? std::min((int64_t)4096, Limits.nodes / 1024)
+ : 4096;
}
- if (++thisThread->callsCnt > 4096)
+
+ if (--thisThread->callsCnt <= 0)
{
for (Thread* th : Threads)
th->resetCalls = true;
&& pos.rule50_count() == 0
&& !pos.can_castle(ANY_CASTLING))
{
- int found, v = Tablebases::probe_wdl(pos, &found);
+ TB::ProbeState err;
+ TB::WDLScore v = Tablebases::probe_wdl(pos, &err);
- if (found)
+ if (err != TB::ProbeState::FAIL)
{
thisThread->tbHits++;
{
ss->currentMove = move;
ss->counterMoves = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)];
- pos.do_move(move, st, pos.gives_check(move));
+ pos.do_move(move, st);
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
pos.undo_move(move);
if (value >= rbeta)
&& !pos.see_ge(move, Value(-35 * lmrDepth * lmrDepth)))
continue;
}
- else if ( depth < 7 * ONE_PLY
- && !extension
- && !pos.see_ge(move, Value(-35 * depth / ONE_PLY * depth / ONE_PLY)))
+ else if (depth < 7 * ONE_PLY && !extension)
+ {
+ Value v = Value(-35 * depth / ONE_PLY * depth / ONE_PLY);
+ if (ss->staticEval != VALUE_NONE)
+ v += ss->staticEval - alpha - 200;
+
+ if (!pos.see_ge(move, v))
continue;
+ }
}
// Speculative prefetch as early as possible
// Decrease reduction for moves that escape a capture. Filter out
// castling moves, because they are coded as "king captures rook" and
- // hence break make_move(). Also use see() instead of see_sign(),
- // because the destination square is empty.
+ // hence break make_move().
else if ( type_of(move) == NORMAL
&& type_of(pos.piece_on(to_sq(move))) != PAWN
&& !pos.see_ge(make_move(to_sq(move), from_sq(move)), VALUE_ZERO))
r -= 2 * ONE_PLY;
+ ss->history = thisThread->history[moved_piece][to_sq(move)]
+ + (cmh ? (*cmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
+ + (fmh ? (*fmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
+ + (fmh2 ? (*fmh2)[moved_piece][to_sq(move)] : VALUE_ZERO)
+ + thisThread->fromTo.get(~pos.side_to_move(), move)
+ - 8000; // Correction factor
+
+ // Decrease/increase reduction by comparing opponent's stat score
+ if (ss->history > VALUE_ZERO && (ss-1)->history < VALUE_ZERO)
+ r -= ONE_PLY;
+
+ else if (ss->history < VALUE_ZERO && (ss-1)->history > VALUE_ZERO)
+ r += ONE_PLY;
+
// Decrease/increase reduction for moves with a good/bad history
- Value val = thisThread->history[moved_piece][to_sq(move)]
- + (cmh ? (*cmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
- + (fmh ? (*fmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
- + (fmh2 ? (*fmh2)[moved_piece][to_sq(move)] : VALUE_ZERO)
- + thisThread->fromTo.get(~pos.side_to_move(), move);
- int rHist = (val - 8000) / 20000;
- r = std::max(DEPTH_ZERO, (r / ONE_PLY - rHist) * ONE_PLY);
+ r = std::max(DEPTH_ZERO, (r / ONE_PLY - ss->history / 20000) * ONE_PLY);
}
Depth d = std::max(newDepth - r, ONE_PLY);
if (!pv[0])
return false;
- pos.do_move(pv[0], st, pos.gives_check(pv[0]));
+ pos.do_move(pv[0], st);
TTEntry* tte = TT.probe(pos.key(), ttHit);
if (ttHit)