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

Sync search() and qsearch() alpha update

Change qsearch() to reflect alpha update logic
of search().

To be consistent changed also moves loop condition and
futility pruning condition.

No regression after 5072 games at TC 10"+0.1

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-08-07 10:29:47 +01:00
parent 4a71c86270
commit 06e0d48794

View file

@ -712,7 +712,7 @@ namespace {
Depth ext, newDepth; Depth ext, newDepth;
ValueType vt; ValueType vt;
Value bestValue, value, oldAlpha; Value bestValue, value, oldAlpha;
Value refinedValue, nullValue, futilityBase, futilityValueScaled; // Non-PV specific Value refinedValue, nullValue, futilityBase, futilityValue;
bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous; bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
int moveCount = 0, playedMoveCount = 0; int moveCount = 0, playedMoveCount = 0;
Thread& thread = Threads[pos.thread()]; Thread& thread = Threads[pos.thread()];
@ -1070,19 +1070,19 @@ split_point_start: // At split points actual search starts from here
// We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth, // We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
// but fixing this made program slightly weaker. // but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount); Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
futilityValueScaled = futilityBase + futility_margin(predictedDepth, moveCount) futilityValue = futilityBase + futility_margin(predictedDepth, moveCount)
+ H.gain(pos.piece_on(move_from(move)), move_to(move)); + H.gain(pos.piece_on(move_from(move)), move_to(move));
if (futilityValueScaled < beta) if (futilityValue < beta)
{ {
if (SpNode) if (SpNode)
{ {
lock_grab(&(sp->lock)); lock_grab(&(sp->lock));
if (futilityValueScaled > sp->bestValue) if (futilityValue > sp->bestValue)
sp->bestValue = bestValue = futilityValueScaled; sp->bestValue = bestValue = futilityValue;
} }
else if (futilityValueScaled > bestValue) else if (futilityValue > bestValue)
bestValue = futilityValueScaled; bestValue = futilityValue;
continue; continue;
} }
@ -1298,6 +1298,7 @@ split_point_start: // At split points actual search starts from here
bool inCheck, enoughMaterial, givesCheck, evasionPrunable; bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
const TTEntry* tte; const TTEntry* tte;
Depth ttDepth; Depth ttDepth;
ValueType vt;
Value oldAlpha = alpha; Value oldAlpha = alpha;
ss->bestMove = ss->currentMove = MOVE_NONE; ss->bestMove = ss->currentMove = MOVE_NONE;
@ -1368,7 +1369,7 @@ split_point_start: // At split points actual search starts from here
CheckInfo ci(pos); CheckInfo ci(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs // Loop through the moves until no moves remain or a beta cutoff occurs
while ( alpha < beta while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE) && (move = mp.get_next_move()) != MOVE_NONE)
{ {
assert(move_is_ok(move)); assert(move_is_ok(move));
@ -1388,10 +1389,11 @@ split_point_start: // At split points actual search starts from here
+ piece_value_endgame(pos.piece_on(move_to(move))) + piece_value_endgame(pos.piece_on(move_to(move)))
+ (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO); + (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
if (futilityValue < alpha) if (futilityValue < beta)
{ {
if (futilityValue > bestValue) if (futilityValue > bestValue)
bestValue = futilityValue; bestValue = futilityValue;
continue; continue;
} }
@ -1450,11 +1452,12 @@ split_point_start: // At split points actual search starts from here
if (value > bestValue) if (value > bestValue)
{ {
bestValue = value; bestValue = value;
if (value > alpha) ss->bestMove = move;
{
if ( PvNode
&& value > alpha
&& value < beta) // We want always alpha < beta
alpha = value; alpha = value;
ss->bestMove = move;
}
} }
} }
@ -1464,8 +1467,11 @@ split_point_start: // At split points actual search starts from here
return value_mated_in(ss->ply); return value_mated_in(ss->ply);
// Update transposition table // Update transposition table
ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT); move = bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove;
TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, ss->bestMove, ss->eval, evalMargin); vt = bestValue <= oldAlpha ? VALUE_TYPE_UPPER
: bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT;
TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);