mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Change search() signature
Pass SpNode as template parameter. No functional change.
This commit is contained in:
parent
5413fda739
commit
b8e6f83cfb
1 changed files with 26 additions and 29 deletions
|
@ -57,7 +57,7 @@ namespace {
|
||||||
const bool FakeSplit = false;
|
const bool FakeSplit = false;
|
||||||
|
|
||||||
// Different node types, used as template parameter
|
// 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
|
// Dynamic razoring margin based on depth
|
||||||
inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
|
inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
|
||||||
|
@ -85,7 +85,7 @@ namespace {
|
||||||
GainsStats Gains;
|
GainsStats Gains;
|
||||||
MovesStats Countermoves, Followupmoves;
|
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);
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
|
||||||
|
|
||||||
template <NodeType NT, bool InCheck>
|
template <NodeType NT, bool InCheck>
|
||||||
|
@ -337,7 +337,7 @@ namespace {
|
||||||
// high/low anymore.
|
// high/low anymore.
|
||||||
while (true)
|
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
|
// Bring the best move to the front. It is critical that sorting
|
||||||
// is done with a stable algorithm because all the values but the
|
// 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
|
// 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.
|
// 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) {
|
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 RootNode = NT == Root;
|
||||||
const bool SpNode = (NT == SplitPointPV || NT == SplitPointNonPV || NT == SplitPointRoot);
|
const bool PvNode = NT == PV || NT == Root;
|
||||||
const bool RootNode = (NT == Root || NT == SplitPointRoot);
|
|
||||||
|
|
||||||
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
||||||
assert(PvNode || (alpha == beta - 1));
|
assert(PvNode || (alpha == beta - 1));
|
||||||
|
@ -621,7 +620,7 @@ namespace {
|
||||||
pos.do_null_move(st);
|
pos.do_null_move(st);
|
||||||
(ss+1)->skipNullMove = true;
|
(ss+1)->skipNullMove = true;
|
||||||
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
|
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;
|
(ss+1)->skipNullMove = false;
|
||||||
pos.undo_null_move();
|
pos.undo_null_move();
|
||||||
|
|
||||||
|
@ -637,7 +636,7 @@ namespace {
|
||||||
// Do verification search at high depths
|
// Do verification search at high depths
|
||||||
ss->skipNullMove = true;
|
ss->skipNullMove = true;
|
||||||
Value v = depth-R < ONE_PLY ? qsearch<NonPV, false>(pos, ss, beta-1, beta, DEPTH_ZERO)
|
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;
|
ss->skipNullMove = false;
|
||||||
|
|
||||||
if (v >= beta)
|
if (v >= beta)
|
||||||
|
@ -669,7 +668,7 @@ namespace {
|
||||||
{
|
{
|
||||||
ss->currentMove = move;
|
ss->currentMove = move;
|
||||||
pos.do_move(move, st, ci, pos.gives_check(move, ci));
|
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);
|
pos.undo_move(move);
|
||||||
if (value >= rbeta)
|
if (value >= rbeta)
|
||||||
return value;
|
return value;
|
||||||
|
@ -684,7 +683,7 @@ namespace {
|
||||||
Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
|
Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
|
||||||
|
|
||||||
ss->skipNullMove = true;
|
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;
|
ss->skipNullMove = false;
|
||||||
|
|
||||||
tte = TT.probe(posKey);
|
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);
|
Value rBeta = ttValue - int(depth);
|
||||||
ss->excludedMove = move;
|
ss->excludedMove = move;
|
||||||
ss->skipNullMove = true;
|
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->skipNullMove = false;
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
|
|
||||||
|
@ -884,13 +883,13 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
if (SpNode)
|
if (SpNode)
|
||||||
alpha = splitPoint->alpha;
|
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
|
// Research at intermediate depth if reduction is very high
|
||||||
if (value > alpha && ss->reduction >= 4 * ONE_PLY)
|
if (value > alpha && ss->reduction >= 4 * ONE_PLY)
|
||||||
{
|
{
|
||||||
Depth d2 = std::max(newDepth - 2 * ONE_PLY, 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);
|
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 ?
|
value = newDepth < ONE_PLY ?
|
||||||
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: -qsearch<NonPV, false>(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
|
// 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 ?
|
value = newDepth < ONE_PLY ?
|
||||||
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
givesCheck ? -qsearch<PV, true>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
||||||
: -qsearch<PV, false>(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
|
// Step 17. Undo move
|
||||||
pos.undo_move(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>
|
template <NodeType NT, bool InCheck>
|
||||||
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
|
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(NT == PV || NT == NonPV);
|
||||||
assert(InCheck == !!pos.checkers());
|
assert(InCheck == !!pos.checkers());
|
||||||
|
@ -1514,19 +1513,17 @@ void Thread::idle_loop() {
|
||||||
|
|
||||||
activePosition = &pos;
|
activePosition = &pos;
|
||||||
|
|
||||||
switch (sp->nodeType) {
|
if (sp->nodeType == NonPV)
|
||||||
case Root:
|
search<NonPV, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
||||||
search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
|
||||||
break;
|
else if (sp->nodeType == PV)
|
||||||
case PV:
|
search<PV, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
||||||
search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
|
||||||
break;
|
else if (sp->nodeType == Root)
|
||||||
case NonPV:
|
search<Root, true>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
||||||
search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
|
|
||||||
break;
|
else
|
||||||
default:
|
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
|
||||||
|
|
||||||
assert(searching);
|
assert(searching);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue