/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad
+ Copyright (C) 2008-2013 Marco Costalba, Joona Kiiski, Tord Romstad
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Move movesSearched[64];
StateInfo st;
const TTEntry *tte;
- SplitPoint* sp;
+ SplitPoint* splitPoint;
Key posKey;
Move ttMove, move, excludedMove, bestMove, threatMove;
Depth ext, newDepth;
if (SpNode)
{
- sp = ss->sp;
- bestMove = sp->bestMove;
- threatMove = sp->threatMove;
- bestValue = sp->bestValue;
+ splitPoint = ss->splitPoint;
+ bestMove = splitPoint->bestMove;
+ threatMove = splitPoint->threatMove;
+ bestValue = splitPoint->bestValue;
tte = NULL;
ttMove = excludedMove = MOVE_NONE;
ttValue = VALUE_NONE;
- assert(sp->bestValue > -VALUE_INFINITE && sp->moveCount > 0);
+ assert(splitPoint->bestValue > -VALUE_INFINITE && splitPoint->moveCount > 0);
goto split_point_start;
}
if (!pos.pl_move_is_legal(move, ci.pinned))
continue;
- moveCount = ++sp->moveCount;
- sp->mutex.unlock();
+ moveCount = ++splitPoint->moveCount;
+ splitPoint->mutex.unlock();
}
else
moveCount++;
newDepth = depth - ONE_PLY + ext;
// Step 13. Futility pruning (is omitted in PV nodes)
- if ( !PvNode
- && !captureOrPromotion
+ if ( !captureOrPromotion
&& !inCheck
&& !dangerous
- && move != ttMove
- && (bestValue > VALUE_MATED_IN_MAX_PLY || ( bestValue == -VALUE_INFINITE
- && alpha > VALUE_MATED_IN_MAX_PLY)))
+ && move != ttMove)
{
// Move count based pruning
- if ( depth < 16 * ONE_PLY
+ if ( !PvNode
+ && depth < 16 * ONE_PLY
&& moveCount >= FutilityMoveCounts[depth]
&& (!threatMove || !refutes(pos, move, threatMove)))
{
if (SpNode)
- sp->mutex.lock();
+ splitPoint->mutex.lock();
continue;
}
futilityValue = ss->staticEval + ss->evalMargin + futility_margin(predictedDepth, moveCount)
+ Gain[pos.piece_moved(move)][to_sq(move)];
- if (futilityValue < beta)
+ if (!PvNode && futilityValue < beta)
{
if (SpNode)
- sp->mutex.lock();
+ splitPoint->mutex.lock();
continue;
}
&& pos.see_sign(move) < 0)
{
if (SpNode)
- sp->mutex.lock();
+ splitPoint->mutex.lock();
continue;
}
{
ss->reduction = reduction<PvNode>(depth, moveCount);
Depth d = std::max(newDepth - ss->reduction, ONE_PLY);
- alpha = SpNode ? sp->alpha : alpha;
+ if (SpNode)
+ alpha = splitPoint->alpha;
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d);
// Step 16. Full depth search, when LMR is skipped or fails high
if (doFullDepthSearch)
{
- alpha = SpNode ? sp->alpha : alpha;
+ if (SpNode)
+ alpha = splitPoint->alpha;
+
value = newDepth < ONE_PLY ?
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
// Step 18. Check for new best move
if (SpNode)
{
- sp->mutex.lock();
- bestValue = sp->bestValue;
- alpha = sp->alpha;
+ splitPoint->mutex.lock();
+ bestValue = splitPoint->bestValue;
+ alpha = splitPoint->alpha;
}
// Finished searching the move. If Signals.stop is true, the search
if (value > bestValue)
{
- bestValue = SpNode ? sp->bestValue = value : value;
+ bestValue = SpNode ? splitPoint->bestValue = value : value;
if (value > alpha)
{
- bestMove = SpNode ? sp->bestMove = move : move;
+ bestMove = SpNode ? splitPoint->bestMove = move : move;
if (PvNode && value < beta) // Update alpha! Always alpha < beta
- alpha = SpNode ? sp->alpha = value : value;
+ alpha = SpNode ? splitPoint->alpha = value : value;
else
{
assert(value >= beta); // Fail high
if (SpNode)
- sp->cutoff = true;
+ splitPoint->cutoff = true;
break;
}
Position pos(*sp->pos, this);
memcpy(ss, sp->ss - 1, 4 * sizeof(Stack));
- (ss+1)->sp = sp;
+ (ss+1)->splitPoint = sp;
sp->mutex.lock();