mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
Make LMR code easier to follow
Remove flags doFullDepthSearch and didLMR, and reorder instruction. Small measured speedup. Closes https://github.com/official-stockfish/Stockfish/pull/4129 No functional change.
This commit is contained in:
parent
4568f6369b
commit
3370f69881
1 changed files with 13 additions and 22 deletions
|
@ -558,8 +558,8 @@ namespace {
|
||||||
Move ttMove, move, excludedMove, bestMove;
|
Move ttMove, move, excludedMove, bestMove;
|
||||||
Depth extension, newDepth;
|
Depth extension, newDepth;
|
||||||
Value bestValue, value, ttValue, eval, maxValue, probCutBeta;
|
Value bestValue, value, ttValue, eval, maxValue, probCutBeta;
|
||||||
bool givesCheck, improving, didLMR, priorCapture, singularQuietLMR;
|
bool givesCheck, improving, priorCapture, singularQuietLMR;
|
||||||
bool capture, doFullDepthSearch, moveCountPruning, ttCapture;
|
bool capture, moveCountPruning, ttCapture;
|
||||||
Piece movedPiece;
|
Piece movedPiece;
|
||||||
int moveCount, captureCount, quietCount, improvement, complexity;
|
int moveCount, captureCount, quietCount, improvement, complexity;
|
||||||
|
|
||||||
|
@ -1127,8 +1127,6 @@ moves_loop: // When in check, search starts here
|
||||||
// Step 16. Make the move
|
// Step 16. Make the move
|
||||||
pos.do_move(move, st, givesCheck);
|
pos.do_move(move, st, givesCheck);
|
||||||
|
|
||||||
bool doDeeperSearch = false;
|
|
||||||
|
|
||||||
// Step 17. Late moves reduction / extension (LMR, ~98 Elo)
|
// Step 17. Late moves reduction / extension (LMR, ~98 Elo)
|
||||||
// We use various heuristics for the sons of a node after the first son has
|
// We use various heuristics for the sons of a node after the first son has
|
||||||
// been searched. In general we would like to reduce them, but there are many
|
// been searched. In general we would like to reduce them, but there are many
|
||||||
|
@ -1187,25 +1185,12 @@ moves_loop: // When in check, search starts here
|
||||||
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
||||||
|
|
||||||
// If the son is reduced and fails high it will be re-searched at full depth
|
// Do full depth search when reduced LMR search fails high
|
||||||
doFullDepthSearch = value > alpha && d < newDepth;
|
if (value > alpha && d < newDepth)
|
||||||
doDeeperSearch = value > (alpha + 78 + 11 * (newDepth - d));
|
|
||||||
didLMR = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
doFullDepthSearch = !PvNode || moveCount > 1;
|
|
||||||
didLMR = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 18. Full depth search when LMR is skipped or fails high
|
|
||||||
if (doFullDepthSearch)
|
|
||||||
{
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth + doDeeperSearch, !cutNode);
|
|
||||||
|
|
||||||
// If the move passed LMR update its stats
|
|
||||||
if (didLMR)
|
|
||||||
{
|
{
|
||||||
|
const bool doDeeperSearch = value > (alpha + 78 + 11 * (newDepth - d));
|
||||||
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth + doDeeperSearch, !cutNode);
|
||||||
|
|
||||||
int bonus = value > alpha ? stat_bonus(newDepth)
|
int bonus = value > alpha ? stat_bonus(newDepth)
|
||||||
: -stat_bonus(newDepth);
|
: -stat_bonus(newDepth);
|
||||||
|
|
||||||
|
@ -1216,6 +1201,12 @@ moves_loop: // When in check, search starts here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 18. Full depth search when LMR is skipped
|
||||||
|
else if (!PvNode || moveCount > 1)
|
||||||
|
{
|
||||||
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// parent node fail low with value <= alpha and try another move.
|
// parent node fail low with value <= alpha and try another move.
|
||||||
|
|
Loading…
Add table
Reference in a new issue