mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Clean-up skipEarlyPruning (#921)
make skipEarlyPruning a search argument instead of managing this by hand. Verified for no regression at STC: LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 96754 W: 17089 L: 17095 D: 62570 No functional change.
This commit is contained in:
parent
589049a0e5
commit
1b62d413c1
2 changed files with 13 additions and 23 deletions
|
@ -162,7 +162,7 @@ namespace {
|
||||||
Value DrawValue[COLOR_NB];
|
Value DrawValue[COLOR_NB];
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType NT>
|
||||||
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool skipEarlyPruning);
|
||||||
|
|
||||||
template <NodeType NT, bool InCheck>
|
template <NodeType NT, bool InCheck>
|
||||||
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
|
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
|
||||||
|
@ -407,7 +407,7 @@ void Thread::search() {
|
||||||
// high/low anymore.
|
// high/low anymore.
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
bestValue = ::search<PV>(rootPos, ss, alpha, beta, rootDepth, false);
|
bestValue = ::search<PV>(rootPos, ss, alpha, beta, rootDepth, false, 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
|
||||||
|
@ -541,7 +541,7 @@ namespace {
|
||||||
// search<>() is the main search function for both PV and non-PV nodes
|
// search<>() is the main search function for both PV and non-PV nodes
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType NT>
|
||||||
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool skipEarlyPruning) {
|
||||||
|
|
||||||
const bool PvNode = NT == PV;
|
const bool PvNode = NT == PV;
|
||||||
const bool rootNode = PvNode && (ss-1)->ply == 0;
|
const bool rootNode = PvNode && (ss-1)->ply == 0;
|
||||||
|
@ -617,7 +617,6 @@ namespace {
|
||||||
|
|
||||||
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
|
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
|
||||||
ss->counterMoves = nullptr;
|
ss->counterMoves = nullptr;
|
||||||
(ss+1)->skipEarlyPruning = false;
|
|
||||||
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
|
|
||||||
|
@ -712,7 +711,7 @@ namespace {
|
||||||
ss->staticEval, TT.generation());
|
ss->staticEval, TT.generation());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ss->skipEarlyPruning)
|
if (skipEarlyPruning)
|
||||||
goto moves_loop;
|
goto moves_loop;
|
||||||
|
|
||||||
// Step 6. Razoring (skipped when in check)
|
// Step 6. Razoring (skipped when in check)
|
||||||
|
@ -753,10 +752,8 @@ namespace {
|
||||||
Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;
|
Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;
|
||||||
|
|
||||||
pos.do_null_move(st);
|
pos.do_null_move(st);
|
||||||
(ss+1)->skipEarlyPruning = true;
|
|
||||||
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
|
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
|
: - search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode, true);
|
||||||
(ss+1)->skipEarlyPruning = false;
|
|
||||||
pos.undo_null_move();
|
pos.undo_null_move();
|
||||||
|
|
||||||
if (nullValue >= beta)
|
if (nullValue >= beta)
|
||||||
|
@ -769,10 +766,8 @@ namespace {
|
||||||
return nullValue;
|
return nullValue;
|
||||||
|
|
||||||
// Do verification search at high depths
|
// Do verification search at high depths
|
||||||
ss->skipEarlyPruning = true;
|
|
||||||
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
|
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
|
||||||
: search<NonPV>(pos, ss, beta-1, beta, depth-R, false);
|
: search<NonPV>(pos, ss, beta-1, beta, depth-R, false, true);
|
||||||
ss->skipEarlyPruning = false;
|
|
||||||
|
|
||||||
if (v >= beta)
|
if (v >= beta)
|
||||||
return nullValue;
|
return nullValue;
|
||||||
|
@ -801,7 +796,7 @@ namespace {
|
||||||
ss->currentMove = move;
|
ss->currentMove = move;
|
||||||
ss->counterMoves = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)];
|
ss->counterMoves = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)];
|
||||||
pos.do_move(move, st);
|
pos.do_move(move, st);
|
||||||
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
|
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode, false);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
if (value >= rbeta)
|
if (value >= rbeta)
|
||||||
return value;
|
return value;
|
||||||
|
@ -814,9 +809,7 @@ namespace {
|
||||||
&& (PvNode || ss->staticEval + 256 >= beta))
|
&& (PvNode || ss->staticEval + 256 >= beta))
|
||||||
{
|
{
|
||||||
Depth d = (3 * depth / (4 * ONE_PLY) - 2) * ONE_PLY;
|
Depth d = (3 * depth / (4 * ONE_PLY) - 2) * ONE_PLY;
|
||||||
ss->skipEarlyPruning = true;
|
search<NT>(pos, ss, alpha, beta, d, cutNode, true);
|
||||||
search<NT>(pos, ss, alpha, beta, d, cutNode);
|
|
||||||
ss->skipEarlyPruning = false;
|
|
||||||
|
|
||||||
tte = TT.probe(posKey, ttHit);
|
tte = TT.probe(posKey, ttHit);
|
||||||
ttMove = ttHit ? tte->move() : MOVE_NONE;
|
ttMove = ttHit ? tte->move() : MOVE_NONE;
|
||||||
|
@ -898,9 +891,7 @@ moves_loop: // When in check search starts from here
|
||||||
Value rBeta = std::max(ttValue - 2 * depth / ONE_PLY, -VALUE_MATE);
|
Value rBeta = std::max(ttValue - 2 * depth / ONE_PLY, -VALUE_MATE);
|
||||||
Depth d = (depth / (2 * ONE_PLY)) * ONE_PLY;
|
Depth d = (depth / (2 * ONE_PLY)) * ONE_PLY;
|
||||||
ss->excludedMove = move;
|
ss->excludedMove = move;
|
||||||
ss->skipEarlyPruning = true;
|
value = search<NonPV>(pos, ss, rBeta - 1, rBeta, d, cutNode, true);
|
||||||
value = search<NonPV>(pos, ss, rBeta - 1, rBeta, d, cutNode);
|
|
||||||
ss->skipEarlyPruning = false;
|
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
|
|
||||||
if (value < rBeta)
|
if (value < rBeta)
|
||||||
|
@ -1014,7 +1005,7 @@ moves_loop: // When in check search starts from here
|
||||||
|
|
||||||
Depth d = std::max(newDepth - r, ONE_PLY);
|
Depth d = std::max(newDepth - r, ONE_PLY);
|
||||||
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true, false);
|
||||||
|
|
||||||
doFullDepthSearch = (value > alpha && d != newDepth);
|
doFullDepthSearch = (value > alpha && d != newDepth);
|
||||||
}
|
}
|
||||||
|
@ -1026,7 +1017,7 @@ moves_loop: // When in check search starts from here
|
||||||
value = newDepth < ONE_PLY ?
|
value = newDepth < ONE_PLY ?
|
||||||
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode, false);
|
||||||
|
|
||||||
// For PV nodes only, do a full PV search on the first move or after a fail
|
// For PV nodes only, do a full PV search on the first move or after a fail
|
||||||
// high (in the latter case search only if value < beta), otherwise let the
|
// high (in the latter case search only if value < beta), otherwise let the
|
||||||
|
@ -1039,7 +1030,7 @@ moves_loop: // When in check search starts from here
|
||||||
value = newDepth < ONE_PLY ?
|
value = newDepth < ONE_PLY ?
|
||||||
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
||||||
: -qsearch<PV, false>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
: -qsearch<PV, false>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 17. Undo move
|
// Step 17. Undo move
|
||||||
|
|
|
@ -38,15 +38,14 @@ namespace Search {
|
||||||
|
|
||||||
struct Stack {
|
struct Stack {
|
||||||
Move* pv;
|
Move* pv;
|
||||||
|
CounterMoveStats* counterMoves;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
Move excludedMove;
|
Move excludedMove;
|
||||||
Move killers[2];
|
Move killers[2];
|
||||||
Value staticEval;
|
Value staticEval;
|
||||||
Value history;
|
Value history;
|
||||||
bool skipEarlyPruning;
|
|
||||||
int moveCount;
|
int moveCount;
|
||||||
CounterMoveStats* counterMoves;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue