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]);
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 (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(4096LL, Limits.nodes / 1024)
+ : 4096;
}
- if (++thisThread->callsCnt > 4096)
+
+ if (--thisThread->callsCnt <= 0)
{
for (Thread* th : Threads)
th->resetCalls = true;
{
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))
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)