mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Space inflate sp_search_pv
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
eacb42092b
commit
421fd9c3bf
1 changed files with 70 additions and 56 deletions
|
@ -1516,8 +1516,8 @@ 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--;
|
||||||
|
@ -1536,6 +1536,7 @@ namespace {
|
||||||
// after we return from the split point.
|
// after we return from the split point.
|
||||||
|
|
||||||
void sp_search_pv(SplitPoint *sp, int threadID) {
|
void sp_search_pv(SplitPoint *sp, int threadID) {
|
||||||
|
|
||||||
assert(threadID >= 0 && threadID < ActiveThreads);
|
assert(threadID >= 0 && threadID < ActiveThreads);
|
||||||
assert(ActiveThreads > 1);
|
assert(ActiveThreads > 1);
|
||||||
|
|
||||||
|
@ -1543,12 +1544,11 @@ namespace {
|
||||||
SearchStack *ss = sp->sstack[threadID];
|
SearchStack *ss = sp->sstack[threadID];
|
||||||
Value value;
|
Value value;
|
||||||
Move move;
|
Move move;
|
||||||
int moveCount = sp->moves;
|
|
||||||
|
|
||||||
while(sp->alpha < sp->beta && !thread_should_stop(threadID)
|
while ( sp->alpha < sp->beta
|
||||||
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE) {
|
&& !thread_should_stop(threadID)
|
||||||
UndoInfo u;
|
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE)
|
||||||
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);
|
||||||
|
@ -1559,42 +1559,52 @@ namespace {
|
||||||
PawnValueMidgame : pos.midgame_value_of_piece_on(move_to(move));
|
PawnValueMidgame : pos.midgame_value_of_piece_on(move_to(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, true, moveIsCheck, false, false);
|
Depth ext = extension(pos, move, true, moveIsCheck, false, false);
|
||||||
newDepth = sp->depth - OnePly + ext;
|
Depth newDepth = sp->depth - OnePly + ext;
|
||||||
|
|
||||||
// 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 >= LMRPVMoves && !moveIsCapture
|
|
||||||
&& !move_promotion(move) && !moveIsPassedPawnPush
|
// Try to reduce non-pv search depth by one ply if move seems not problematic,
|
||||||
|
// if the move fails high will be re-searched at full depth.
|
||||||
|
if ( ext == Depth(0)
|
||||||
|
&& moveCount >= LMRPVMoves
|
||||||
|
&& !moveIsCapture
|
||||||
|
&& !moveIsPassedPawnPush
|
||||||
|
&& !move_promotion(move)
|
||||||
&& !move_is_castle(move)
|
&& !move_is_castle(move)
|
||||||
&& move != ss[sp->ply].killer1 && move != ss[sp->ply].killer2) {
|
&& move != ss[sp->ply].killer1
|
||||||
|
&& move != ss[sp->ply].killer2)
|
||||||
|
{
|
||||||
ss[sp->ply].reduction = OnePly;
|
ss[sp->ply].reduction = OnePly;
|
||||||
value = -search(pos, ss, -sp->alpha, newDepth - OnePly, sp->ply+1,
|
value = -search(pos, ss, -sp->alpha, newDepth - OnePly, sp->ply+1, true, threadID);
|
||||||
true, threadID);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = sp->alpha + 1;
|
value = sp->alpha + 1; // Just to trigger next condition
|
||||||
if(value > sp->alpha) {
|
|
||||||
|
if (value > sp->alpha) // Go with full depth non-pv search
|
||||||
|
{
|
||||||
ss[sp->ply].reduction = Depth(0);
|
ss[sp->ply].reduction = Depth(0);
|
||||||
value = -search(pos, ss, -sp->alpha, newDepth, sp->ply+1, true,
|
value = -search(pos, ss, -sp->alpha, newDepth, sp->ply+1, true, threadID);
|
||||||
threadID);
|
|
||||||
if(value > sp->alpha && value < sp->beta) {
|
if (value > sp->alpha && value < sp->beta)
|
||||||
if(sp->ply == 1 && RootMoveNumber == 1)
|
{
|
||||||
// When the search fails high at ply 1 while searching the first
|
// When the search fails high at ply 1 while searching the first
|
||||||
// move at the root, set the flag failHighPly1. This is used for
|
// move at the root, set the flag failHighPly1. This is used for
|
||||||
// time managment: We don't want to stop the search early in
|
// time managment: We don't want to stop the search early in
|
||||||
// such cases, because resolving the fail high at ply 1 could
|
// such cases, because resolving the fail high at ply 1 could
|
||||||
// result in a big drop in score at the root.
|
// result in a big drop in score at the root.
|
||||||
|
if (sp->ply == 1 && RootMoveNumber == 1)
|
||||||
Threads[threadID].failHighPly1 = true;
|
Threads[threadID].failHighPly1 = true;
|
||||||
value = -search_pv(pos, ss, -sp->beta, -sp->alpha, newDepth,
|
|
||||||
sp->ply+1, threadID);
|
value = -search_pv(pos, ss, -sp->beta, -sp->alpha, newDepth, sp->ply+1, threadID);
|
||||||
Threads[threadID].failHighPly1 = false;
|
Threads[threadID].failHighPly1 = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1602,30 +1612,34 @@ namespace {
|
||||||
|
|
||||||
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;
|
sp->bestValue = value;
|
||||||
if(value > sp->alpha) {
|
if (value > sp->alpha)
|
||||||
|
{
|
||||||
sp->alpha = value;
|
sp->alpha = value;
|
||||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||||
if(value == value_mate_in(sp->ply + 1))
|
if (value == value_mate_in(sp->ply + 1))
|
||||||
ss[sp->ply].mateKiller = move;
|
ss[sp->ply].mateKiller = move;
|
||||||
if(value >= sp->beta) {
|
|
||||||
|
if(value >= sp->beta)
|
||||||
|
{
|
||||||
for(int i = 0; i < ActiveThreads; i++)
|
for(int i = 0; i < ActiveThreads; i++)
|
||||||
if(i != threadID && (i == sp->master || sp->slaves[i]))
|
if(i != threadID && (i == sp->master || sp->slaves[i]))
|
||||||
Threads[i].stop = true;
|
Threads[i].stop = true;
|
||||||
|
|
||||||
sp->finished = true;
|
sp->finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we are at ply 1, and we are searching the first root move at
|
// If we are at ply 1, and we are searching the first root move at
|
||||||
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
||||||
// (from the computer's point of view) since the previous iteration:
|
// (from the computer's point of view) since the previous iteration:
|
||||||
if(Iteration >= 2 &&
|
if (Iteration >= 2 && -value <= ValueByIteration[Iteration-1] - ProblemMargin)
|
||||||
-value <= ValueByIteration[Iteration-1] - ProblemMargin)
|
|
||||||
Problem = true;
|
Problem = true;
|
||||||
}
|
}
|
||||||
lock_release(&(sp->lock));
|
lock_release(&(sp->lock));
|
||||||
|
@ -1635,9 +1649,9 @@ 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--;
|
||||||
|
|
Loading…
Add table
Reference in a new issue