diff --git a/Rapfi/search/ab/parameter.h b/Rapfi/search/ab/parameter.h index 6e4fd542..5e1f5245 100644 --- a/Rapfi/search/ab/parameter.h +++ b/Rapfi/search/ab/parameter.h @@ -173,19 +173,6 @@ constexpr Value qvcfDeltaMargin(Depth d) // note: d <= 0 return Value(std::max(QVCFBias[R] + QVCFScale[R] * int(d), 768)); } -/// LMR move count. For non-PV all node, moves that exceeds late move count -/// will be searched will late move reduction even without other condition. -template -constexpr int lateMoveCount(Depth d, bool improving) -{ - constexpr float LMC[RULE_NB][2] = { - {0.82f, 1.48f}, - {0.83f, 0.89f}, - {0.70f, 1.65f}, - }; - return 1 + 2 * improving + int(LMC[R][improving] * d); -} - /// Extension for full-depth search when reduced LMR search fails high template constexpr int @@ -263,12 +250,4 @@ inline int policyPruningScore(Depth d) return PPBias[R] - int(d * PPScale[R]); } -/// Policy reduction score at given depth. Moves lower than this will do lmr. -template -inline int policyReductionScore(Depth d) -{ - constexpr int PRBias[RULE_NB] = {489, 535, 520}; - return PRBias[R]; -} - } // namespace Search::AB diff --git a/Rapfi/search/ab/search.cpp b/Rapfi/search/ab/search.cpp index 021df22c..089c15ac 100644 --- a/Rapfi/search/ab/search.cpp +++ b/Rapfi/search/ab/search.cpp @@ -984,7 +984,7 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth searchData->rootDepth, move); - // Initialize various heruistic information + // Initialize heruistic information ss->moveCount = ++moveCount; ss->moveP4[BLACK] = board.cell(move).pattern4[BLACK]; ss->moveP4[WHITE] = board.cell(move).pattern4[WHITE]; @@ -1101,22 +1101,14 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth board.move(move); TT.prefetch(board.zobristKey()); - bool doFullDepthSearch; // Step 15. Late move reduction (LMR). Moves are searched with a reduced // depth and will be re-searched at full depth if fail high. - if (depth > 2 && moveCount > 1 + 2 * RootNode - && (!importantMove // do LMR for non important move - || distract // do LMR for distract move - || cutNode // do LMR for all moves in cut node - || moveCount >= lateMoveCount(depth, improvement > 0) // do LMR for late move - || mp.hasPolicyScore() // do LMR for low policy - && mp.curMoveScore() < policyReductionScore(depth))) { - Value delta = beta - alpha; - Depth r = reduction(searcher->reductions, + if (depth >= 2 && moveCount > 1 + RootNode) { + Depth r = reduction(searcher->reductions, depth, moveCount, improvement, - delta, + beta - alpha, searchData->rootDelta); // Policy based reduction @@ -1164,10 +1156,8 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth r -= ss->statScore * (1.0f / (12633 + 4055 * (depth > 7))); // Allow LMR to do deeper search in some circumstances - int deeper = r < -1 && moveCount <= 4 ? 1 : 0; - // Clamp the LMR depth to newDepth (no depth less than one) - Depth d = std::max(std::min(newDepth - r, newDepth + deeper), 1.0f); + Depth d = std::max(std::min(newDepth - r, newDepth + 1), 1.0f); value = -search(board, ss + 1, -(alpha + 1), -alpha, d, true); @@ -1179,16 +1169,22 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth else ss->extraExtension += std::max(ext - 1.0f, 0.0f); newDepth += ext; - } - doFullDepthSearch = (value > alpha && d < newDepth); + if (d < newDepth) + value = -search(board, + ss + 1, + -(alpha + 1), + -alpha, + newDepth, + !cutNode); + } } - else - doFullDepthSearch = !PvNode || moveCount > 1; // Step 16. Full depth search when LMR is skipped or fails high - if (doFullDepthSearch) + else if (!PvNode || moveCount > 1) { + // If expected reduction is high, we reduce search depth by 1 here value = -search(board, ss + 1, -(alpha + 1), -alpha, newDepth, !cutNode); + } // For balance move mode, we also check if a move can trigger beta cut // (which is too good to be balanced), so we can safely discard this move.