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>
Depth ext, newDepth;
ValueType vt;
Value bestValue, value, oldAlpha;
Depth ext, newDepth;
ValueType vt;
Value bestValue, value, oldAlpha;
- Value refinedValue, nullValue, futilityBase, futilityValueScaled; // Non-PV specific
+ Value refinedValue, nullValue, futilityBase, futilityValue;
bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
int moveCount = 0, playedMoveCount = 0;
Thread& thread = Threads[pos.thread()];
bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
int moveCount = 0, playedMoveCount = 0;
Thread& thread = Threads[pos.thread()];
// We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
// but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
// We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
// but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
- futilityValueScaled = futilityBase + futility_margin(predictedDepth, moveCount)
- + H.gain(pos.piece_on(move_from(move)), move_to(move));
+ futilityValue = futilityBase + futility_margin(predictedDepth, moveCount)
+ + H.gain(pos.piece_on(move_from(move)), move_to(move));
- if (futilityValueScaled < beta)
+ if (futilityValue < beta)
{
if (SpNode)
{
lock_grab(&(sp->lock));
{
if (SpNode)
{
lock_grab(&(sp->lock));
- if (futilityValueScaled > sp->bestValue)
- sp->bestValue = bestValue = futilityValueScaled;
+ if (futilityValue > sp->bestValue)
+ sp->bestValue = bestValue = futilityValue;
- else if (futilityValueScaled > bestValue)
- bestValue = futilityValueScaled;
+ else if (futilityValue > bestValue)
+ bestValue = futilityValue;
bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
const TTEntry* tte;
Depth ttDepth;
bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
const TTEntry* tte;
Depth ttDepth;
Value oldAlpha = alpha;
ss->bestMove = ss->currentMove = MOVE_NONE;
Value oldAlpha = alpha;
ss->bestMove = ss->currentMove = MOVE_NONE;
CheckInfo ci(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs
CheckInfo ci(pos);
// Loop through the moves until no moves remain or a beta cutoff occurs
+ while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE)
{
assert(move_is_ok(move));
&& (move = mp.get_next_move()) != MOVE_NONE)
{
assert(move_is_ok(move));
+ piece_value_endgame(pos.piece_on(move_to(move)))
+ (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
+ piece_value_endgame(pos.piece_on(move_to(move)))
+ (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
- if (futilityValue < alpha)
+ if (futilityValue < beta)
{
if (futilityValue > bestValue)
bestValue = futilityValue;
{
if (futilityValue > bestValue)
bestValue = futilityValue;
if (value > bestValue)
{
bestValue = value;
if (value > bestValue)
{
bestValue = value;
+ ss->bestMove = move;
+
+ if ( PvNode
+ && value > alpha
+ && value < beta) // We want always alpha < beta
- ss->bestMove = move;
- }
return value_mated_in(ss->ply);
// Update transposition table
return value_mated_in(ss->ply);
// Update transposition table
- ValueType 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, ss->bestMove, ss->eval, evalMargin);
+ move = bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove;
+ 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);