mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Reformat search dispatch code
Reduce indentation level and lines of code and tidy up some comment. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
9c7d72739c
commit
e9dc2e9e1e
1 changed files with 39 additions and 45 deletions
|
@ -730,7 +730,8 @@ namespace {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
Value bestValue, value, oldAlpha;
|
Value bestValue, value, oldAlpha;
|
||||||
Value refinedValue, nullValue, futilityBase, futilityValue;
|
Value refinedValue, nullValue, futilityBase, futilityValue;
|
||||||
bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
|
bool isPvMove, inCheck, singularExtensionNode, givesCheck;
|
||||||
|
bool captureOrPromotion, dangerous, doFullDepthSearch;
|
||||||
int moveCount = 0, playedMoveCount = 0;
|
int moveCount = 0, playedMoveCount = 0;
|
||||||
Thread& thread = Threads[pos.thread()];
|
Thread& thread = Threads[pos.thread()];
|
||||||
SplitPoint* sp = NULL;
|
SplitPoint* sp = NULL;
|
||||||
|
@ -1056,11 +1057,11 @@ split_point_start: // At split points actual search starts from here
|
||||||
Value rBeta = ttValue - int(depth);
|
Value rBeta = ttValue - int(depth);
|
||||||
ss->excludedMove = move;
|
ss->excludedMove = move;
|
||||||
ss->skipNullMove = true;
|
ss->skipNullMove = true;
|
||||||
Value v = search<NonPV>(pos, ss, rBeta - 1, rBeta, depth / 2);
|
value = search<NonPV>(pos, ss, rBeta - 1, rBeta, depth / 2);
|
||||||
ss->skipNullMove = false;
|
ss->skipNullMove = false;
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
ss->bestMove = MOVE_NONE;
|
ss->bestMove = MOVE_NONE;
|
||||||
if (v < rBeta)
|
if (value < rBeta)
|
||||||
ext = ONE_PLY;
|
ext = ONE_PLY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1134,50 +1135,43 @@ split_point_start: // At split points actual search starts from here
|
||||||
// Step 14. Make the move
|
// Step 14. Make the move
|
||||||
pos.do_move(move, st, ci, givesCheck);
|
pos.do_move(move, st, ci, givesCheck);
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step 15. Reduced depth search (LMR). If the move fails high will be
|
||||||
// The first move in list is the expected PV
|
// re-searched at full depth.
|
||||||
if (isPvMove)
|
|
||||||
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Step 15. Reduced depth search
|
|
||||||
// If the move fails high will be re-searched at full depth.
|
|
||||||
bool doFullDepthSearch = true;
|
|
||||||
|
|
||||||
if ( depth > 3 * ONE_PLY
|
if ( depth > 3 * ONE_PLY
|
||||||
|
&& !isPvMove
|
||||||
&& !captureOrPromotion
|
&& !captureOrPromotion
|
||||||
&& !dangerous
|
&& !dangerous
|
||||||
&& !is_castle(move)
|
&& !is_castle(move)
|
||||||
&& ss->killers[0] != move
|
&& ss->killers[0] != move
|
||||||
&& ss->killers[1] != move
|
&& ss->killers[1] != move)
|
||||||
&& (ss->reduction = reduction<PvNode>(depth, moveCount)) != DEPTH_ZERO)
|
|
||||||
{
|
{
|
||||||
|
ss->reduction = reduction<PvNode>(depth, moveCount);
|
||||||
Depth d = newDepth - ss->reduction;
|
Depth d = newDepth - ss->reduction;
|
||||||
alpha = SpNode ? sp->alpha : alpha;
|
alpha = SpNode ? sp->alpha : alpha;
|
||||||
|
|
||||||
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d);
|
||||||
|
|
||||||
|
doFullDepthSearch = (value > alpha && ss->reduction != DEPTH_ZERO);
|
||||||
ss->reduction = DEPTH_ZERO;
|
ss->reduction = DEPTH_ZERO;
|
||||||
doFullDepthSearch = (value > alpha);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
doFullDepthSearch = !isPvMove;
|
||||||
|
|
||||||
// Step 16. Full depth search
|
// Step 16. Full depth search, when LMR is skipped or fails high
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
{
|
||||||
alpha = SpNode ? sp->alpha : alpha;
|
alpha = SpNode ? sp->alpha : alpha;
|
||||||
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth);
|
||||||
|
}
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Only for PV nodes do a full PV search on the first move or after a fail
|
||||||
// Search only for possible new PV nodes, if instead value >= beta then
|
// high, in the latter case search only if value < beta, otherwise let the
|
||||||
// parent node fails low with value <= alpha and tries another move.
|
// parent node to fail low with value <= alpha and to try another move.
|
||||||
if (PvNode && value > alpha && (RootNode || value < beta))
|
if (PvNode && (isPvMove || (value > alpha && (RootNode || value < beta))))
|
||||||
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 17. Undo move
|
// Step 17. Undo move
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
|
|
Loading…
Add table
Reference in a new issue