mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Space inflate sp_search
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
a10c9632a5
commit
eacb42092b
1 changed files with 59 additions and 44 deletions
103
src/search.cpp
103
src/search.cpp
|
@ -935,7 +935,7 @@ namespace {
|
||||||
else
|
else
|
||||||
value = alpha + 1; // Just to trigger next condition
|
value = alpha + 1; // Just to trigger next condition
|
||||||
|
|
||||||
if (value > alpha) // Go with full depth non-pv search
|
if (value > alpha) // Go with full depth pv search
|
||||||
{
|
{
|
||||||
ss[ply].reduction = Depth(0);
|
ss[ply].reduction = Depth(0);
|
||||||
value = -search(pos, ss, -alpha, newDepth, ply+1, true, threadID);
|
value = -search(pos, ss, -alpha, newDepth, ply+1, true, threadID);
|
||||||
|
@ -1417,6 +1417,7 @@ namespace {
|
||||||
// care of after we return from the split point.
|
// care of after we return from the split point.
|
||||||
|
|
||||||
void sp_search(SplitPoint *sp, int threadID) {
|
void sp_search(SplitPoint *sp, int threadID) {
|
||||||
|
|
||||||
assert(threadID >= 0 && threadID < ActiveThreads);
|
assert(threadID >= 0 && threadID < ActiveThreads);
|
||||||
assert(ActiveThreads > 1);
|
assert(ActiveThreads > 1);
|
||||||
|
|
||||||
|
@ -1424,73 +1425,87 @@ namespace {
|
||||||
SearchStack *ss = sp->sstack[threadID];
|
SearchStack *ss = sp->sstack[threadID];
|
||||||
Value value;
|
Value value;
|
||||||
Move move;
|
Move move;
|
||||||
int moveCount = sp->moves;
|
|
||||||
bool isCheck = pos.is_check();
|
bool isCheck = pos.is_check();
|
||||||
bool useFutilityPruning =
|
bool useFutilityPruning = UseFutilityPruning
|
||||||
UseFutilityPruning && sp->depth < SelectiveDepth && !isCheck;
|
&& sp->depth < SelectiveDepth
|
||||||
|
&& !isCheck;
|
||||||
|
|
||||||
|
while ( sp->bestValue < sp->beta
|
||||||
|
&& !thread_should_stop(threadID)
|
||||||
|
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE)
|
||||||
|
{
|
||||||
|
assert(move_is_ok(move));
|
||||||
|
|
||||||
while(sp->bestValue < sp->beta && !thread_should_stop(threadID)
|
|
||||||
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE) {
|
|
||||||
UndoInfo u;
|
|
||||||
Depth ext, newDepth;
|
|
||||||
bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
|
bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
|
||||||
bool moveIsCapture = pos.move_is_capture(move);
|
bool moveIsCapture = pos.move_is_capture(move);
|
||||||
bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
|
bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
|
||||||
|
|
||||||
assert(move_is_ok(move));
|
|
||||||
|
|
||||||
lock_grab(&(sp->lock));
|
lock_grab(&(sp->lock));
|
||||||
sp->moves++;
|
int moveCount = ++sp->moves;
|
||||||
moveCount = sp->moves;
|
|
||||||
lock_release(&(sp->lock));
|
lock_release(&(sp->lock));
|
||||||
|
|
||||||
ss[sp->ply].currentMove = move;
|
ss[sp->ply].currentMove = move;
|
||||||
|
|
||||||
// Decide the new search depth.
|
// Decide the new search depth.
|
||||||
ext = extension(pos, move, false, moveIsCheck, false, false);
|
Depth ext = extension(pos, move, false, moveIsCheck, false, false);
|
||||||
newDepth = sp->depth - OnePly + ext;
|
Depth newDepth = sp->depth - OnePly + ext;
|
||||||
|
|
||||||
// Prune?
|
// Prune?
|
||||||
if(useFutilityPruning && ext == Depth(0) && !moveIsCapture
|
if ( useFutilityPruning
|
||||||
&& !moveIsPassedPawnPush && !move_promotion(move)
|
&& ext == Depth(0)
|
||||||
&& moveCount >= 2 + int(sp->depth)
|
&& !moveIsCapture
|
||||||
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth))
|
&& !moveIsPassedPawnPush
|
||||||
|
&& !move_promotion(move)
|
||||||
|
&& moveCount >= 2 + int(sp->depth)
|
||||||
|
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Make and search the move.
|
// Make and search the move.
|
||||||
|
UndoInfo u;
|
||||||
pos.do_move(move, u, sp->dcCandidates);
|
pos.do_move(move, u, sp->dcCandidates);
|
||||||
if(ext == Depth(0) && moveCount >= LMRNonPVMoves
|
|
||||||
&& !moveIsCapture && !move_promotion(move) && !moveIsPassedPawnPush
|
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||||
&& !move_is_castle(move)
|
// if the move fails high will be re-searched at full depth.
|
||||||
&& move != ss[sp->ply].killer1 && move != ss[sp->ply].killer2) {
|
if ( ext == Depth(0)
|
||||||
ss[sp->ply].reduction = OnePly;
|
&& moveCount >= LMRNonPVMoves
|
||||||
value = -search(pos, ss, -(sp->beta-1), newDepth - OnePly, sp->ply+1,
|
&& !moveIsCapture
|
||||||
true, threadID);
|
&& !moveIsPassedPawnPush
|
||||||
|
&& !move_promotion(move)
|
||||||
|
&& !move_is_castle(move)
|
||||||
|
&& move != ss[sp->ply].killer1
|
||||||
|
&& move != ss[sp->ply].killer2)
|
||||||
|
{
|
||||||
|
ss[sp->ply].reduction = OnePly;
|
||||||
|
value = -search(pos, ss, -(sp->beta-1), newDepth - OnePly, sp->ply+1, true, threadID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = sp->beta;
|
value = sp->beta; // Just to trigger next condition
|
||||||
if(value >= sp->beta) {
|
|
||||||
ss[sp->ply].reduction = Depth(0);
|
if (value >= sp->beta) // Go with full depth non-pv search
|
||||||
value = -search(pos, ss, -(sp->beta - 1), newDepth, sp->ply+1, true,
|
{
|
||||||
threadID);
|
ss[sp->ply].reduction = Depth(0);
|
||||||
|
value = -search(pos, ss, -(sp->beta - 1), newDepth, sp->ply+1, true, 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);
|
||||||
|
|
||||||
if(thread_should_stop(threadID))
|
if (thread_should_stop(threadID))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// New best move?
|
// New best move?
|
||||||
lock_grab(&(sp->lock));
|
lock_grab(&(sp->lock));
|
||||||
if(value > sp->bestValue && !thread_should_stop(threadID)) {
|
if (value > sp->bestValue && !thread_should_stop(threadID))
|
||||||
sp->bestValue = value;
|
{
|
||||||
if(sp->bestValue >= sp->beta) {
|
sp->bestValue = value;
|
||||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
if (sp->bestValue >= sp->beta)
|
||||||
for(int i = 0; i < ActiveThreads; i++)
|
{
|
||||||
if(i != threadID && (i == sp->master || sp->slaves[i]))
|
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||||
Threads[i].stop = true;
|
for (int i = 0; i < ActiveThreads; i++)
|
||||||
sp->finished = true;
|
if (i != threadID && (i == sp->master || sp->slaves[i]))
|
||||||
|
Threads[i].stop = true;
|
||||||
|
|
||||||
|
sp->finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lock_release(&(sp->lock));
|
lock_release(&(sp->lock));
|
||||||
|
@ -1500,10 +1515,10 @@ namespace {
|
||||||
|
|
||||||
// If this is the master thread and we have been asked to stop because of
|
// If this is the master thread and we have been asked to stop because of
|
||||||
// a beta cutoff higher up in the tree, stop all slave threads:
|
// a beta cutoff higher up in the tree, stop all slave threads:
|
||||||
if(sp->master == threadID && thread_should_stop(threadID))
|
if (sp->master == threadID && thread_should_stop(threadID))
|
||||||
for(int i = 0; i < ActiveThreads; i++)
|
for(int i = 0; i < ActiveThreads; i++)
|
||||||
if(sp->slaves[i])
|
if(sp->slaves[i])
|
||||||
Threads[i].stop = true;
|
Threads[i].stop = true;
|
||||||
|
|
||||||
sp->cpus--;
|
sp->cpus--;
|
||||||
sp->slaves[threadID] = 0;
|
sp->slaves[threadID] = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue