1
0
Fork 0

Change search() signature

Pass SpNode as template parameter.

No functional change.
sf_5_base
Marco Costalba 2014-05-04 13:11:32 +02:00
parent 5413fda739
commit b8e6f83cfb
1 changed files with 26 additions and 29 deletions

View File

@ -57,7 +57,7 @@ namespace {
const bool FakeSplit = false;
// Different node types, used as template parameter
enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
enum NodeType { Root, PV, NonPV };
// Dynamic razoring margin based on depth
inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
@ -85,7 +85,7 @@ namespace {
GainsStats Gains;
MovesStats Countermoves, Followupmoves;
template <NodeType NT>
template <NodeType NT, bool SpNode>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
template <NodeType NT, bool InCheck>
@ -337,7 +337,7 @@ namespace {
// high/low anymore.
while (true)
{
bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false);
bestValue = search<Root, false>(pos, ss, alpha, beta, depth * ONE_PLY, false);
// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
@ -443,12 +443,11 @@ namespace {
// repeat all this work again. We also don't need to store anything to the hash
// table here: This is taken care of after we return from the split point.
template <NodeType NT>
template <NodeType NT, bool SpNode>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
const bool PvNode = (NT == PV || NT == Root || NT == SplitPointPV || NT == SplitPointRoot);
const bool SpNode = (NT == SplitPointPV || NT == SplitPointNonPV || NT == SplitPointRoot);
const bool RootNode = (NT == Root || NT == SplitPointRoot);
const bool RootNode = NT == Root;
const bool PvNode = NT == PV || NT == Root;
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
assert(PvNode || (alpha == beta - 1));
@ -621,7 +620,7 @@ namespace {
pos.do_null_move(st);
(ss+1)->skipNullMove = true;
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
: - search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
: - search<NonPV, false>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
(ss+1)->skipNullMove = false;
pos.undo_null_move();
@ -637,7 +636,7 @@ namespace {
// Do verification search at high depths
ss->skipNullMove = true;
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
: search<NonPV>(pos, ss, beta-1, beta, depth-R, false);
: search<NonPV, false>(pos, ss, beta-1, beta, depth-R, false);
ss->skipNullMove = false;
if (v >= beta)
@ -669,7 +668,7 @@ namespace {
{
ss->currentMove = move;
pos.do_move(move, st, ci, pos.gives_check(move, ci));
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
value = -search<NonPV, false>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
pos.undo_move(move);
if (value >= rbeta)
return value;
@ -684,7 +683,7 @@ namespace {
Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
ss->skipNullMove = true;
search<PvNode ? PV : NonPV>(pos, ss, alpha, beta, d, true);
search<PvNode ? PV : NonPV, false>(pos, ss, alpha, beta, d, true);
ss->skipNullMove = false;
tte = TT.probe(posKey);
@ -784,7 +783,7 @@ moves_loop: // When in check and at SpNode search starts from here
Value rBeta = ttValue - int(depth);
ss->excludedMove = move;
ss->skipNullMove = true;
value = search<NonPV>(pos, ss, rBeta - 1, rBeta, depth / 2, cutNode);
value = search<NonPV, false>(pos, ss, rBeta - 1, rBeta, depth / 2, cutNode);
ss->skipNullMove = false;
ss->excludedMove = MOVE_NONE;
@ -884,13 +883,13 @@ moves_loop: // When in check and at SpNode search starts from here
if (SpNode)
alpha = splitPoint->alpha;
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
value = -search<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, d, true);
// Research at intermediate depth if reduction is very high
if (value > alpha && ss->reduction >= 4 * ONE_PLY)
{
Depth d2 = std::max(newDepth - 2 * ONE_PLY, ONE_PLY);
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d2, true);
value = -search<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, d2, true);
}
doFullDepthSearch = (value > alpha && ss->reduction != DEPTH_ZERO);
@ -908,7 +907,7 @@ moves_loop: // When in check and at SpNode search starts from here
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)
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
: - search<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
}
// For PV nodes only, do a full PV search on the first move or after a fail
@ -918,7 +917,7 @@ moves_loop: // When in check and at SpNode search starts from here
value = newDepth < ONE_PLY ?
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
: -qsearch<PV, false>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
: - search<PV, false>(pos, ss+1, -beta, -alpha, newDepth, false);
// Step 17. Undo move
pos.undo_move(move);
@ -1043,7 +1042,7 @@ moves_loop: // When in check and at SpNode search starts from here
template <NodeType NT, bool InCheck>
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
const bool PvNode = (NT == PV);
const bool PvNode = NT == PV;
assert(NT == PV || NT == NonPV);
assert(InCheck == !!pos.checkers());
@ -1514,19 +1513,17 @@ void Thread::idle_loop() {
activePosition = &pos;
switch (sp->nodeType) {
case Root:
search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
break;
case PV:
search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
break;
case NonPV:
search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
break;
default:
if (sp->nodeType == NonPV)
search<NonPV, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
else if (sp->nodeType == PV)
search<PV, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
else if (sp->nodeType == Root)
search<Root, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
else
assert(false);
}
assert(searching);