1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Similarize pruning code in search() and sp_search()

Use futility pruning also in split points.
Do not use history pruning in split points when
getting mated.

After 1000 games on Joona QUAD
Orig - Mod: 496 - 504

Added an optimization to avoid a costly lock in the
very common case that sp->futilityValue <= sp->bestValue.
A test on a dual CPU shows only 114 hits on 23196 events,
so avoid a lock in all the other cases.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Joona Kiiski 2009-10-17 08:42:42 +03:00 committed by Marco Costalba
parent 4dd7fccfd1
commit f0b0a3b135
2 changed files with 42 additions and 9 deletions

View file

@ -308,7 +308,9 @@ namespace {
bool thread_is_available(int slave, int master); bool thread_is_available(int slave, int master);
bool idle_thread_exists(int master); bool idle_thread_exists(int master);
bool split(const Position& pos, SearchStack* ss, int ply, bool split(const Position& pos, SearchStack* ss, int ply,
Value *alpha, Value *beta, Value *bestValue, Depth depth, int *moves, Value *alpha, Value *beta, Value *bestValue,
const Value futilityValue, const Value approximateValue,
Depth depth, int *moves,
MovePicker *mp, Bitboard dcCandidates, int master, bool pvNode); MovePicker *mp, Bitboard dcCandidates, int master, bool pvNode);
void wake_sleeping_threads(); void wake_sleeping_threads();
@ -1176,7 +1178,7 @@ namespace {
&& idle_thread_exists(threadID) && idle_thread_exists(threadID)
&& !AbortSearch && !AbortSearch
&& !thread_should_stop(threadID) && !thread_should_stop(threadID)
&& split(pos, ss, ply, &alpha, &beta, &bestValue, depth, && split(pos, ss, ply, &alpha, &beta, &bestValue, VALUE_NONE, VALUE_NONE, depth,
&moveCount, &mp, dcCandidates, threadID, true)) &moveCount, &mp, dcCandidates, threadID, true))
break; break;
} }
@ -1437,7 +1439,7 @@ namespace {
&& idle_thread_exists(threadID) && idle_thread_exists(threadID)
&& !AbortSearch && !AbortSearch
&& !thread_should_stop(threadID) && !thread_should_stop(threadID)
&& split(pos, ss, ply, &beta, &beta, &bestValue, depth, &moveCount, && split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, approximateEval, depth, &moveCount,
&mp, dcCandidates, threadID, false)) &mp, dcCandidates, threadID, false))
break; break;
} }
@ -1693,10 +1695,37 @@ namespace {
if ( useFutilityPruning if ( useFutilityPruning
&& !dangerous && !dangerous
&& !moveIsCapture && !moveIsCapture
&& !move_is_promotion(move) && !move_is_promotion(move))
&& moveCount >= 2 + int(sp->depth) {
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth)) // History pruning. See ok_to_prune() definition
continue; if ( moveCount >= 2 + int(sp->depth)
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth)
&& sp->bestValue > value_mated_in(PLY_MAX))
continue;
// Value based pruning
if (sp->approximateEval < sp->beta)
{
if (sp->futilityValue == VALUE_NONE)
{
EvalInfo ei;
sp->futilityValue = evaluate(pos, ei, threadID)
+ FutilityMargins[int(sp->depth) - 2];
}
if (sp->futilityValue < sp->beta)
{
if (sp->futilityValue > sp->bestValue) // Less then 1% of cases
{
lock_grab(&(sp->lock));
if (sp->futilityValue > sp->bestValue)
sp->bestValue = sp->futilityValue;
lock_release(&(sp->lock));
}
continue;
}
}
}
// Make and search the move. // Make and search the move.
StateInfo st; StateInfo st;
@ -2756,7 +2785,8 @@ namespace {
// splitPoint->cpus becomes 0), split() returns true. // splitPoint->cpus becomes 0), split() returns true.
bool split(const Position& p, SearchStack* sstck, int ply, bool split(const Position& p, SearchStack* sstck, int ply,
Value* alpha, Value* beta, Value* bestValue, Depth depth, int* moves, Value* alpha, Value* beta, Value* bestValue, const Value futilityValue,
const Value approximateEval, Depth depth, int* moves,
MovePicker* mp, Bitboard dcCandidates, int master, bool pvNode) { MovePicker* mp, Bitboard dcCandidates, int master, bool pvNode) {
assert(p.is_ok()); assert(p.is_ok());
@ -2796,6 +2826,8 @@ namespace {
splitPoint->pvNode = pvNode; splitPoint->pvNode = pvNode;
splitPoint->dcCandidates = dcCandidates; splitPoint->dcCandidates = dcCandidates;
splitPoint->bestValue = *bestValue; splitPoint->bestValue = *bestValue;
splitPoint->futilityValue = futilityValue;
splitPoint->approximateEval = approximateEval;
splitPoint->master = master; splitPoint->master = master;
splitPoint->mp = mp; splitPoint->mp = mp;
splitPoint->moves = *moves; splitPoint->moves = *moves;

View file

@ -50,7 +50,8 @@ struct SplitPoint {
SearchStack *parentSstack; SearchStack *parentSstack;
int ply; int ply;
Depth depth; Depth depth;
volatile Value alpha, beta, bestValue; volatile Value alpha, beta, bestValue, futilityValue;
Value approximateEval;
bool pvNode; bool pvNode;
Bitboard dcCandidates; Bitboard dcCandidates;
int master, slaves[THREAD_MAX]; int master, slaves[THREAD_MAX];