1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Space inflate qsearch

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-07 08:31:30 +02:00
parent d517080ab6
commit 6c592955e1

View file

@ -242,7 +242,6 @@ namespace {
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d); bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d);
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply); bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
bool fail_high_ply_1(); bool fail_high_ply_1();
int current_search_time(); int current_search_time();
int nps(); int nps();
@ -1060,6 +1059,7 @@ namespace {
// Mate distance pruning // Mate distance pruning
if (value_mated_in(ply) >= beta) if (value_mated_in(ply) >= beta)
return beta; return beta;
if (value_mate_in(ply + 1) < beta) if (value_mate_in(ply + 1) < beta)
return beta - 1; return beta - 1;
@ -1151,9 +1151,9 @@ namespace {
// Loop through all legal moves until no moves remain or a beta cutoff // Loop through all legal moves until no moves remain or a beta cutoff
// occurs. // occurs.
while( bestValue < beta while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE && (move = mp.get_next_move()) != MOVE_NONE
&& !thread_should_stop(threadID)) && !thread_should_stop(threadID))
{ {
assert(move_is_ok(move)); assert(move_is_ok(move));
@ -1182,11 +1182,12 @@ namespace {
if (depth < 3 * OnePly && approximateEval < beta) if (depth < 3 * OnePly && approximateEval < beta)
{ {
if (futilityValue == VALUE_NONE) if (futilityValue == VALUE_NONE)
futilityValue = evaluate(pos, ei, threadID) + (depth < 2 * OnePly ? FutilityMargin1 : FutilityMargin2); futilityValue = evaluate(pos, ei, threadID)
+ (depth < 2 * OnePly ? FutilityMargin1 : FutilityMargin2);
if (futilityValue < beta) if (futilityValue < beta)
{ {
if(futilityValue > bestValue) if (futilityValue > bestValue)
bestValue = futilityValue; bestValue = futilityValue;
continue; continue;
} }
@ -1230,20 +1231,21 @@ namespace {
bestValue = value; bestValue = value;
if (value >= beta) if (value >= beta)
update_pv(ss, ply); update_pv(ss, ply);
if (value == value_mate_in(ply + 1)) if (value == value_mate_in(ply + 1))
ss[ply].mateKiller = move; ss[ply].mateKiller = move;
} }
// Split? // Split?
if( ActiveThreads > 1 if ( ActiveThreads > 1
&& bestValue < beta && bestValue < beta
&& depth >= MinimumSplitDepth && depth >= MinimumSplitDepth
&& Iteration <= 99 && Iteration <= 99
&& idle_thread_exists(threadID) && idle_thread_exists(threadID)
&& !AbortSearch && !AbortSearch
&& !thread_should_stop(threadID) && !thread_should_stop(threadID)
&& split(pos, ss, ply, &beta, &beta, &bestValue, depth, &moveCount, && split(pos, ss, ply, &beta, &beta, &bestValue, depth, &moveCount,
&mp, dcCandidates, threadID, false)) &mp, dcCandidates, threadID, false))
break; break;
} }
@ -1291,8 +1293,6 @@ namespace {
Value qsearch(Position &pos, SearchStack ss[], Value alpha, Value beta, Value qsearch(Position &pos, SearchStack ss[], Value alpha, Value beta,
Depth depth, int ply, int threadID) { Depth depth, int ply, int threadID) {
Value staticValue, bestValue, value;
EvalInfo ei;
assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE); assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE);
assert(beta >= -VALUE_INFINITE && beta <= VALUE_INFINITE); assert(beta >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
@ -1300,32 +1300,33 @@ namespace {
assert(ply >= 0 && ply < PLY_MAX); assert(ply >= 0 && ply < PLY_MAX);
assert(threadID >= 0 && threadID < ActiveThreads); assert(threadID >= 0 && threadID < ActiveThreads);
EvalInfo ei;
// Initialize, and make an early exit in case of an aborted search, // Initialize, and make an early exit in case of an aborted search,
// an instant draw, maximum ply reached, etc. // an instant draw, maximum ply reached, etc.
if(AbortSearch || thread_should_stop(threadID)) if (AbortSearch || thread_should_stop(threadID))
return Value(0); return Value(0);
init_node(pos, ss, ply, threadID); init_node(pos, ss, ply, threadID);
if(pos.is_draw()) if (pos.is_draw())
return VALUE_DRAW; return VALUE_DRAW;
// Evaluate the position statically: // Evaluate the position statically:
staticValue = evaluate(pos, ei, threadID); Value staticValue = evaluate(pos, ei, threadID);
if(ply == PLY_MAX - 1) return staticValue; if (ply == PLY_MAX - 1)
return staticValue;
// Initialize "stand pat score", and return it immediately if it is // Initialize "stand pat score", and return it immediately if it is
// at least beta. // at least beta.
if(pos.is_check()) Value bestValue = (pos.is_check() ? -VALUE_INFINITE : staticValue);
bestValue = -VALUE_INFINITE;
else { if (bestValue >= beta)
bestValue = staticValue;
if(bestValue >= beta)
return bestValue; return bestValue;
if(bestValue > alpha)
if (bestValue > alpha)
alpha = bestValue; alpha = bestValue;
}
// Initialize a MovePicker object for the current position, and prepare // Initialize a MovePicker object for the current position, and prepare
// to search the moves. Because the depth is <= 0 here, only captures, // to search the moves. Because the depth is <= 0 here, only captures,
@ -1339,62 +1340,72 @@ namespace {
// Loop through the moves until no moves remain or a beta cutoff // Loop through the moves until no moves remain or a beta cutoff
// occurs. // occurs.
while(alpha < beta && ((move = mp.get_next_move()) != MOVE_NONE)) { while ( alpha < beta
UndoInfo u; && (move = mp.get_next_move()) != MOVE_NONE)
{
assert(move_is_ok(move));
bool moveIsCheck = pos.move_is_check(move, dcCandidates); bool moveIsCheck = pos.move_is_check(move, dcCandidates);
bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move); bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
assert(move_is_ok(move));
moveCount++; moveCount++;
ss[ply].currentMove = move; ss[ply].currentMove = move;
// Futility pruning // Futility pruning
if(UseQSearchFutilityPruning && !isCheck && !moveIsCheck && if ( UseQSearchFutilityPruning
!move_promotion(move) && !moveIsPassedPawnPush && && !isCheck
beta - alpha == 1 && && !moveIsCheck
pos.non_pawn_material(pos.side_to_move()) > RookValueMidgame) { && !move_promotion(move)
Value futilityValue = && !moveIsPassedPawnPush
staticValue && beta - alpha == 1
+ Max(pos.midgame_value_of_piece_on(move_to(move)), && pos.non_pawn_material(pos.side_to_move()) > RookValueMidgame)
pos.endgame_value_of_piece_on(move_to(move))) {
+ FutilityMargin0 Value futilityValue = staticValue
+ ei.futilityMargin; + Max(pos.midgame_value_of_piece_on(move_to(move)),
if(futilityValue < alpha) { pos.endgame_value_of_piece_on(move_to(move)))
if(futilityValue > bestValue) + FutilityMargin0
bestValue = futilityValue; + ei.futilityMargin;
continue;
} if (futilityValue < alpha)
{
if (futilityValue > bestValue)
bestValue = futilityValue;
continue;
}
} }
// Don't search captures and checks with negative SEE values. // Don't search captures and checks with negative SEE values.
if(!isCheck && !move_promotion(move) && if ( !isCheck
pos.midgame_value_of_piece_on(move_from(move)) > && !move_promotion(move)
pos.midgame_value_of_piece_on(move_to(move)) && && (pos.midgame_value_of_piece_on(move_from(move)) >
pos.see(move) < 0) pos.midgame_value_of_piece_on(move_to(move)))
continue; && pos.see(move) < 0)
continue;
// Make and search the move. // Make and search the move.
UndoInfo u;
pos.do_move(move, u, dcCandidates); pos.do_move(move, u, dcCandidates);
value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID); Value value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
pos.undo_move(move, u); pos.undo_move(move, u);
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE); assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
// New best move? // New best move?
if(value > bestValue) { if (value > bestValue)
bestValue = value; {
if(value > alpha) { bestValue = value;
alpha = value; if (value > alpha)
update_pv(ss, ply); {
} alpha = value;
} update_pv(ss, ply);
}
}
} }
// All legal moves have been searched. A special case: If we're in check // All legal moves have been searched. A special case: If we're in check
// and no legal moves were found, it is checkmate: // and no legal moves were found, it is checkmate:
if(pos.is_check() && moveCount == 0) // Mate! if (pos.is_check() && moveCount == 0) // Mate!
return value_mated_in(ply); return value_mated_in(ply);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
@ -1626,22 +1637,6 @@ namespace {
} }
// ok_to_use_TT() returns true if a transposition table score
// can be used at a given point in search.
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply) {
Value v = value_from_tt(tte->value(), ply);
return ( tte->depth() >= depth
|| v >= Max(value_mate_in(100), beta)
|| v < Min(value_mated_in(100), beta))
&& ( (is_lower_bound(tte->type()) && v >= beta)
|| (is_upper_bound(tte->type()) && v < beta));
}
/// The RootMove class /// The RootMove class
// Constructor // Constructor
@ -2033,6 +2028,22 @@ namespace {
} }
// ok_to_use_TT() returns true if a transposition table score
// can be used at a given point in search.
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply) {
Value v = value_from_tt(tte->value(), ply);
return ( tte->depth() >= depth
|| v >= Max(value_mate_in(100), beta)
|| v < Min(value_mated_in(100), beta))
&& ( (is_lower_bound(tte->type()) && v >= beta)
|| (is_upper_bound(tte->type()) && v < beta));
}
// fail_high_ply_1() checks if some thread is currently resolving a fail // fail_high_ply_1() checks if some thread is currently resolving a fail
// high at ply 1 at the node below the first root node. This information // high at ply 1 at the node below the first root node. This information
// is used for time managment. // is used for time managment.