1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-12 03:59:15 +00:00

Search code documentation, take III

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Joona Kiiski 2010-02-24 12:55:58 +02:00 committed by Marco Costalba
parent 195b54c312
commit 9eedc0a463

View file

@ -1402,12 +1402,13 @@ namespace {
tte = TT.retrieve(posKey); tte = TT.retrieve(posKey);
} }
// Initialize a MovePicker object for the current position, and prepare // Step 10. Loop through moves
// to search all moves. // Loop through all legal moves until no moves remain or a beta cutoff occurs
// Initialize a MovePicker object for the current position
MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]); MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
CheckInfo ci(pos); CheckInfo ci(pos);
// Loop through all legal moves until no moves remain or a beta cutoff occurs
while ( bestValue < beta while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE && (move = mp.get_next_move()) != MOVE_NONE
&& !TM.thread_should_stop(threadID)) && !TM.thread_should_stop(threadID))
@ -1421,7 +1422,7 @@ namespace {
singleEvasion = (isCheck && mp.number_of_evasions() == 1); singleEvasion = (isCheck && mp.number_of_evasions() == 1);
captureOrPromotion = pos.move_is_capture_or_promotion(move); captureOrPromotion = pos.move_is_capture_or_promotion(move);
// Decide the new search depth // Step 11. Decide the new search depth
ext = extension(pos, move, false, captureOrPromotion, moveIsCheck, singleEvasion, mateThreat, &dangerous); ext = extension(pos, move, false, captureOrPromotion, moveIsCheck, singleEvasion, mateThreat, &dangerous);
// Singular extension search. We extend the TT move if its value is much better than // Singular extension search. We extend the TT move if its value is much better than
@ -1448,10 +1449,10 @@ namespace {
newDepth = depth - OnePly + ext; newDepth = depth - OnePly + ext;
// Update current move // Update current move (this must be done after singular extension search)
movesSearched[moveCount++] = ss[ply].currentMove = move; movesSearched[moveCount++] = ss[ply].currentMove = move;
// Futility pruning // Step 12. Futility pruning
if ( !isCheck if ( !isCheck
&& !dangerous && !dangerous
&& !captureOrPromotion && !captureOrPromotion
@ -1477,10 +1478,10 @@ namespace {
} }
} }
// Make and search the move // Step 13. Make the move
pos.do_move(move, st, ci, moveIsCheck); pos.do_move(move, st, ci, moveIsCheck);
// Try to reduce non-pv search depth by one ply if move seems not problematic, // Step 14. Reduced search
// if the move fails high will be re-searched at full depth. // if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true; bool doFullDepthSearch = true;
@ -1498,16 +1499,19 @@ namespace {
} }
} }
if (doFullDepthSearch) // Go with full depth non-pv search // Step 15. Full depth search
if (doFullDepthSearch)
{ {
ss[ply].reduction = Depth(0); ss[ply].reduction = Depth(0);
value = -search(pos, ss, -(beta-1), newDepth, ply+1, true, threadID); value = -search(pos, ss, -(beta-1), newDepth, ply+1, true, threadID);
} }
// Step 16. Undo move
pos.undo_move(move); pos.undo_move(move);
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE); assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
// New best move? // Step 17. Check for new best move
if (value > bestValue) if (value > bestValue)
{ {
bestValue = value; bestValue = value;
@ -1518,7 +1522,7 @@ namespace {
ss[ply].mateKiller = move; ss[ply].mateKiller = move;
} }
// Split? // Step 18. Check for split
if ( TM.active_threads() > 1 if ( TM.active_threads() > 1
&& bestValue < beta && bestValue < beta
&& depth >= MinimumSplitDepth && depth >= MinimumSplitDepth
@ -1531,11 +1535,14 @@ namespace {
break; break;
} }
// All legal moves have been searched. A special case: If there were // Step 19. Check for mate and stalemate
// All legal moves have been searched and if there were
// no legal moves, it must be mate or stalemate. // no legal moves, it must be mate or stalemate.
// If one move was excluded return fail low.
if (!moveCount) if (!moveCount)
return excludedMove ? beta - 1 : (pos.is_check() ? value_mated_in(ply) : VALUE_DRAW); return excludedMove ? beta - 1 : (pos.is_check() ? value_mated_in(ply) : VALUE_DRAW);
// Step 20. Update tables
// If the search is not aborted, update the transposition table, // If the search is not aborted, update the transposition table,
// history counters, and killer moves. // history counters, and killer moves.
if (AbortSearch || TM.thread_should_stop(threadID)) if (AbortSearch || TM.thread_should_stop(threadID))