void put_threads_to_sleep();
void idle_loop(int threadID, SplitPoint* waitSp);
bool split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
- const Value futilityValue, Depth depth, int* moves, MovePicker* mp, int master, bool pvNode);
+ Depth depth, int* moves, MovePicker* mp, int master, bool pvNode);
private:
friend void poll();
&& TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
- && TM.split(pos, ss, ply, &alpha, beta, &bestValue, VALUE_NONE,
+ && TM.split(pos, ss, ply, &alpha, beta, &bestValue,
depth, &moveCount, &mp, threadID, true))
break;
}
const TTEntry* tte;
Move ttMove, move;
Depth ext, newDepth;
- Value bestValue, staticValue, nullValue, value, futilityValue, futilityValueScaled;
+ Value bestValue, refinedValue, nullValue, value, futilityValueScaled;
bool isCheck, singleEvasion, moveIsCheck, captureOrPromotion, dangerous;
bool mateThreat = false;
int moveCount = 0;
- futilityValue = staticValue = bestValue = value = -VALUE_INFINITE;
+ refinedValue = bestValue = value = -VALUE_INFINITE;
if (depth < OnePly)
return qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
// Step 4. Transposition table lookup
// We don't want the score of a partial search to overwrite a previous full search
- // TT value, so we use a different position key in case of an excluded move exsists.
+ // TT value, so we use a different position key in case of an excluded move exists.
Key posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key();
tte = TT.retrieve(posKey);
if (!isCheck)
{
if (tte && (tte->type() & VALUE_TYPE_EVAL))
- staticValue = value_from_tt(tte->value(), ply);
+ ss[ply].eval = value_from_tt(tte->value(), ply);
else
- staticValue = evaluate(pos, ei, threadID);
+ ss[ply].eval = evaluate(pos, ei, threadID);
- ss[ply].eval = staticValue;
- futilityValue = staticValue + futility_margin(depth, 0); //FIXME: Remove me, only for split
- staticValue = refine_eval(tte, staticValue, ply); // Enhance accuracy with TT value if possible
+ refinedValue = refine_eval(tte, ss[ply].eval, ply); // Enhance accuracy with TT value if possible
update_gains(pos, ss[ply - 1].currentMove, ss[ply - 1].eval, ss[ply].eval);
}
if ( !value_is_mate(beta)
&& !isCheck
&& depth < RazorDepth
- && staticValue < beta - (0x200 + 16 * depth)
+ && refinedValue < beta - (0x200 + 16 * depth)
&& ss[ply - 1].currentMove != MOVE_NULL
&& ttMove == MOVE_NONE
&& !pos.has_pawn_on_7th(pos.side_to_move()))
if ( !isCheck
&& allowNullmove
&& depth < RazorDepth
- && staticValue - futility_margin(depth, 0) >= beta)
- return staticValue - futility_margin(depth, 0);
+ && refinedValue - futility_margin(depth, 0) >= beta)
+ return refinedValue - futility_margin(depth, 0);
// Step 8. Null move search with verification search
// When we jump directly to qsearch() we do a null move only if static value is
&& !isCheck
&& !value_is_mate(beta)
&& ok_to_do_nullmove(pos)
- && staticValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0))
+ && refinedValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0))
{
ss[ply].currentMove = MOVE_NULL;
int R = 3 + (depth >= 5 * OnePly ? depth / 8 : 0);
// Null move dynamic reduction based on value
- if (staticValue - beta > PawnValueMidgame)
+ if (refinedValue - beta > PawnValueMidgame)
R++;
nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
&& TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
- && TM.split(pos, ss, ply, NULL, beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
+ && TM.split(pos, ss, ply, NULL, beta, &bestValue,
depth, &moveCount, &mp, threadID, false))
break;
}
Move move;
int moveCount;
bool isCheck = pos.is_check();
- bool useFutilityPruning = sp->depth < 7 * OnePly //FIXME: sync with search
- && !isCheck;
+ // Step 10. Loop through moves
+ // Loop through all legal moves until no moves remain or a beta cutoff occurs
lock_grab(&(sp->lock));
while ( sp->bestValue < sp->beta
bool moveIsCheck = pos.move_is_check(move, ci);
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
- ss[sp->ply].currentMove = move;
-
- // Decide the new search depth
+ // Step 11. Decide the new search depth
bool dangerous;
Depth ext = extension(pos, move, false, captureOrPromotion, moveIsCheck, false, false, &dangerous);
Depth newDepth = sp->depth - OnePly + ext;
- // Prune?
- if ( useFutilityPruning
+ // Update current move
+ ss[sp->ply].currentMove = move;
+
+ // Step 12. Futility pruning
+ if ( !isCheck
&& !dangerous
- && !captureOrPromotion)
+ && !captureOrPromotion
+ && !move_is_castle(move))
{
// Move count based pruning
if ( moveCount >= futility_move_count(sp->depth)
}
// Value based pruning
- Value futilityValueScaled = sp->futilityValue - moveCount * 8; //FIXME: sync with search
+ Depth predictedDepth = newDepth - nonpv_reduction(sp->depth, moveCount);
+ Value futilityValueScaled = ss[sp->ply].eval + futility_margin(predictedDepth, moveCount)
+ + H.gain(pos.piece_on(move_from(move)), move_to(move)) + 45;
if (futilityValueScaled < sp->beta)
{
Position pos(*sp->pos);
CheckInfo ci(pos);
SearchStack* ss = sp->sstack[threadID];
+ StateInfo st;
Value value = -VALUE_INFINITE;
int moveCount;
Move move;
+ // Step 10. Loop through moves
+ // Loop through all legal moves until no moves remain or a beta cutoff occurs
lock_grab(&(sp->lock));
while ( sp->alpha < sp->beta
bool moveIsCheck = pos.move_is_check(move, ci);
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
- ss[sp->ply].currentMove = move;
-
- // Decide the new search depth
+ // Step 11. Decide the new search depth
bool dangerous;
Depth ext = extension(pos, move, true, captureOrPromotion, moveIsCheck, false, false, &dangerous);
Depth newDepth = sp->depth - OnePly + ext;
- // Make and search the move.
- StateInfo st;
+ // Update current move
+ ss[sp->ply].currentMove = move;
+
+ // Step 12. Futility pruning (is omitted in PV nodes)
+
+ // Step 13. Make the move
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.
bool doFullDepthSearch = true;
}
}
- if (doFullDepthSearch) // Go with full depth non-pv search
+ // Step 15. Full depth search
+ if (doFullDepthSearch)
{
Value localAlpha = sp->alpha;
ss[sp->ply].reduction = Depth(0);
value = -search_pv(pos, ss, -sp->beta, -localAlpha, newDepth, sp->ply+1, threadID);
}
}
+
+ // Step 16. Undo move
pos.undo_move(move);
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
- // New best move?
+ // Step 17. Check for new best move
lock_grab(&(sp->lock));
if (value > sp->bestValue && !TM.thread_should_stop(threadID))
// splitPoint->cpus becomes 0), split() returns true.
bool ThreadsManager::split(const Position& p, SearchStack* sstck, int ply,
- Value* alpha, const Value beta, Value* bestValue, const Value futilityValue,
+ Value* alpha, const Value beta, Value* bestValue,
Depth depth, int* moves, MovePicker* mp, int master, bool pvNode) {
assert(p.is_ok());
splitPoint->beta = beta;
splitPoint->pvNode = pvNode;
splitPoint->bestValue = *bestValue;
- splitPoint->futilityValue = futilityValue;
splitPoint->master = master;
splitPoint->mp = mp;
splitPoint->moves = *moves;