1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Don't need to early check PV moves for legality

As long as isPvMove (renamed to pvMove) is set after
legality check, we can postpone legality even in PV case.

Patch aligns the PV case with the common non-pv one.

No functional change.
This commit is contained in:
Marco Costalba 2012-09-29 17:41:53 +02:00
parent bc8f5fe0bf
commit d53c928261

View file

@ -528,7 +528,7 @@ namespace {
Bound bt; Bound bt;
Value bestValue, value, oldAlpha, ttValue; Value bestValue, value, oldAlpha, ttValue;
Value refinedValue, nullValue, futilityBase, futilityValue; Value refinedValue, nullValue, futilityBase, futilityValue;
bool isPvMove, inCheck, singularExtensionNode, givesCheck; bool pvMove, inCheck, singularExtensionNode, givesCheck;
bool captureOrPromotion, dangerous, doFullDepthSearch; bool captureOrPromotion, dangerous, doFullDepthSearch;
int moveCount = 0, playedMoveCount = 0; int moveCount = 0, playedMoveCount = 0;
Thread* thisThread = pos.this_thread(); Thread* thisThread = pos.this_thread();
@ -818,12 +818,12 @@ split_point_start: // At split points actual search starts from here
if (RootNode && !std::count(RootMoves.begin() + PVIdx, RootMoves.end(), move)) if (RootNode && !std::count(RootMoves.begin() + PVIdx, RootMoves.end(), move))
continue; continue;
// At PV and SpNode nodes we want all moves to be legal since the beginning
if ((PvNode || SpNode) && !pos.pl_move_is_legal(move, ci.pinned))
continue;
if (SpNode) if (SpNode)
{ {
// Shared counter cannot be decremented later if move turns out to be illegal
if (!pos.pl_move_is_legal(move, ci.pinned))
continue;
moveCount = ++sp->moveCount; moveCount = ++sp->moveCount;
sp->mutex.unlock(); sp->mutex.unlock();
} }
@ -840,7 +840,6 @@ split_point_start: // At split points actual search starts from here
<< " currmovenumber " << moveCount + PVIdx << sync_endl; << " currmovenumber " << moveCount + PVIdx << sync_endl;
} }
isPvMove = (PvNode && moveCount <= 1);
captureOrPromotion = pos.is_capture_or_promotion(move); captureOrPromotion = pos.is_capture_or_promotion(move);
givesCheck = pos.move_gives_check(move, ci); givesCheck = pos.move_gives_check(move, ci);
dangerous = givesCheck || is_dangerous(pos, move, captureOrPromotion); dangerous = givesCheck || is_dangerous(pos, move, captureOrPromotion);
@ -929,6 +928,7 @@ split_point_start: // At split points actual search starts from here
continue; continue;
} }
pvMove = PvNode ? moveCount <= 1 : false;
ss->currentMove = move; ss->currentMove = move;
if (!SpNode && !captureOrPromotion && playedMoveCount < 64) if (!SpNode && !captureOrPromotion && playedMoveCount < 64)
movesSearched[playedMoveCount++] = move; movesSearched[playedMoveCount++] = move;
@ -939,7 +939,7 @@ split_point_start: // At split points actual search starts from here
// Step 15. Reduced depth search (LMR). If the move fails high will be // Step 15. Reduced depth search (LMR). If the move fails high will be
// re-searched at full depth. // re-searched at full depth.
if ( depth > 3 * ONE_PLY if ( depth > 3 * ONE_PLY
&& !isPvMove && !pvMove
&& !captureOrPromotion && !captureOrPromotion
&& !dangerous && !dangerous
&& ss->killers[0] != move && ss->killers[0] != move
@ -955,7 +955,7 @@ split_point_start: // At split points actual search starts from here
ss->reduction = DEPTH_ZERO; ss->reduction = DEPTH_ZERO;
} }
else else
doFullDepthSearch = !isPvMove; doFullDepthSearch = !pvMove;
// Step 16. Full depth search, when LMR is skipped or fails high // Step 16. Full depth search, when LMR is skipped or fails high
if (doFullDepthSearch) if (doFullDepthSearch)
@ -968,7 +968,7 @@ split_point_start: // At split points actual search starts from here
// Only for PV nodes do a full PV search on the first move or after a fail // Only for PV nodes 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 to fail low with value <= alpha and to try another move. // parent node to fail low with value <= alpha and to try another move.
if (PvNode && (isPvMove || (value > alpha && (RootNode || value < beta)))) if (PvNode && (pvMove || (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);
@ -994,7 +994,7 @@ split_point_start: // At split points actual search starts from here
RootMove& rm = *std::find(RootMoves.begin(), RootMoves.end(), move); RootMove& rm = *std::find(RootMoves.begin(), RootMoves.end(), move);
// PV move or new best move ? // PV move or new best move ?
if (isPvMove || value > alpha) if (pvMove || value > alpha)
{ {
rm.score = value; rm.score = value;
rm.extract_pv_from_tt(pos); rm.extract_pv_from_tt(pos);
@ -1002,7 +1002,7 @@ split_point_start: // At split points actual search starts from here
// We record how often the best move has been changed in each // We record how often the best move has been changed in each
// iteration. This information is used for time management: When // iteration. This information is used for time management: When
// the best move changes frequently, we allocate some more time. // the best move changes frequently, we allocate some more time.
if (!isPvMove && MultiPV == 1) if (!pvMove && MultiPV == 1)
BestMoveChanges++; BestMoveChanges++;
} }
else else