mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Use SearchStack to pass allowNullmove
Also renamed allowNullmove in skipNullMove to reverse the logic so that the field is initialized to 0 (false) instead of 1 (true). No functional change also with faked split. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
5804bef824
commit
c51e12200a
2 changed files with 42 additions and 23 deletions
|
@ -285,7 +285,7 @@ namespace {
|
||||||
Value root_search(Position& pos, SearchStack* ss, RootMoveList& rml, Value* alphaPtr, Value* betaPtr);
|
Value root_search(Position& pos, SearchStack* ss, RootMoveList& rml, Value* alphaPtr, Value* betaPtr);
|
||||||
|
|
||||||
template <NodeType PvNode>
|
template <NodeType PvNode>
|
||||||
Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth, bool allowNullmove, int threadID);
|
Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth, int threadID);
|
||||||
|
|
||||||
template <NodeType PvNode>
|
template <NodeType PvNode>
|
||||||
Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth, int threadID);
|
Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth, int threadID);
|
||||||
|
@ -876,7 +876,7 @@ namespace {
|
||||||
alpha = -VALUE_INFINITE;
|
alpha = -VALUE_INFINITE;
|
||||||
|
|
||||||
// Full depth PV search, done on first move or after a fail high
|
// Full depth PV search, done on first move or after a fail high
|
||||||
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, 0);
|
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -893,7 +893,7 @@ namespace {
|
||||||
if (ss->reduction)
|
if (ss->reduction)
|
||||||
{
|
{
|
||||||
// Reduced depth non-pv search using alpha as upperbound
|
// Reduced depth non-pv search using alpha as upperbound
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, true, 0);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, 0);
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -903,12 +903,12 @@ namespace {
|
||||||
{
|
{
|
||||||
// Full depth non-pv search using alpha as upperbound
|
// Full depth non-pv search using alpha as upperbound
|
||||||
ss->reduction = Depth(0);
|
ss->reduction = Depth(0);
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, true, 0);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, 0);
|
||||||
|
|
||||||
// If we are above alpha then research at same depth but as PV
|
// If we are above alpha then research at same depth but as PV
|
||||||
// to get a correct score or eventually a fail high above beta.
|
// to get a correct score or eventually a fail high above beta.
|
||||||
if (value > alpha)
|
if (value > alpha)
|
||||||
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, 0);
|
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,8 +1031,7 @@ namespace {
|
||||||
// search<>() is the main search function for both PV and non-PV nodes
|
// search<>() is the main search function for both PV and non-PV nodes
|
||||||
|
|
||||||
template <NodeType PvNode>
|
template <NodeType PvNode>
|
||||||
Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth,
|
Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth, int threadID) {
|
||||||
bool allowNullmove, int threadID) {
|
|
||||||
|
|
||||||
assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE);
|
assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE);
|
||||||
assert(beta > alpha && beta <= VALUE_INFINITE);
|
assert(beta > alpha && beta <= VALUE_INFINITE);
|
||||||
|
@ -1060,6 +1059,7 @@ namespace {
|
||||||
TM.incrementNodeCounter(threadID);
|
TM.incrementNodeCounter(threadID);
|
||||||
ss->init(ply);
|
ss->init(ply);
|
||||||
(ss + 1)->excludedMove = MOVE_NONE;
|
(ss + 1)->excludedMove = MOVE_NONE;
|
||||||
|
(ss + 1)->skipNullMove = false;
|
||||||
(ss + 2)->initKillers();
|
(ss + 2)->initKillers();
|
||||||
|
|
||||||
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls)
|
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls)
|
||||||
|
@ -1147,7 +1147,7 @@ namespace {
|
||||||
// We're betting that the opponent doesn't have a move that will reduce
|
// We're betting that the opponent doesn't have a move that will reduce
|
||||||
// the score by more than futility_margin(depth) if we do a null move.
|
// the score by more than futility_margin(depth) if we do a null move.
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& allowNullmove
|
&& !ss->skipNullMove
|
||||||
&& depth < RazorDepth
|
&& depth < RazorDepth
|
||||||
&& refinedValue >= beta + futility_margin(depth, 0)
|
&& refinedValue >= beta + futility_margin(depth, 0)
|
||||||
&& !isCheck
|
&& !isCheck
|
||||||
|
@ -1160,7 +1160,7 @@ namespace {
|
||||||
// at least beta. Otherwise we do a null move if static value is not more than
|
// at least beta. Otherwise we do a null move if static value is not more than
|
||||||
// NullMoveMargin under beta.
|
// NullMoveMargin under beta.
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& allowNullmove
|
&& !ss->skipNullMove
|
||||||
&& depth > OnePly
|
&& depth > OnePly
|
||||||
&& refinedValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0)
|
&& refinedValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0)
|
||||||
&& !isCheck
|
&& !isCheck
|
||||||
|
@ -1178,8 +1178,13 @@ namespace {
|
||||||
|
|
||||||
pos.do_null_move(st);
|
pos.do_null_move(st);
|
||||||
|
|
||||||
|
(ss+1)->skipNullMove = true;
|
||||||
|
|
||||||
nullValue = depth-R*OnePly < OnePly ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
nullValue = depth-R*OnePly < OnePly ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
||||||
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*OnePly, false, threadID);
|
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*OnePly, threadID);
|
||||||
|
|
||||||
|
(ss+1)->skipNullMove = false;
|
||||||
|
|
||||||
pos.undo_null_move();
|
pos.undo_null_move();
|
||||||
|
|
||||||
if (nullValue >= beta)
|
if (nullValue >= beta)
|
||||||
|
@ -1189,8 +1194,14 @@ namespace {
|
||||||
nullValue = beta;
|
nullValue = beta;
|
||||||
|
|
||||||
// Do zugzwang verification search at high depths
|
// Do zugzwang verification search at high depths
|
||||||
if ( depth < 6 * OnePly
|
if (depth < 6 * OnePly)
|
||||||
|| search<NonPV>(pos, ss, alpha, beta, depth-5*OnePly, false, threadID) >= beta)
|
return nullValue;
|
||||||
|
|
||||||
|
ss->skipNullMove = true;
|
||||||
|
Value v = search<NonPV>(pos, ss, alpha, beta, depth-5*OnePly, threadID);
|
||||||
|
ss->skipNullMove = false;
|
||||||
|
|
||||||
|
if (v >= beta)
|
||||||
return nullValue;
|
return nullValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1218,7 +1229,11 @@ namespace {
|
||||||
&& (PvNode || (!isCheck && ss->eval >= beta - IIDMargin)))
|
&& (PvNode || (!isCheck && ss->eval >= beta - IIDMargin)))
|
||||||
{
|
{
|
||||||
Depth d = (PvNode ? depth - 2 * OnePly : depth / 2);
|
Depth d = (PvNode ? depth - 2 * OnePly : depth / 2);
|
||||||
search<PvNode>(pos, ss, alpha, beta, d, false, threadID);
|
|
||||||
|
ss->skipNullMove = true;
|
||||||
|
search<PvNode>(pos, ss, alpha, beta, d, threadID);
|
||||||
|
ss->skipNullMove = false;
|
||||||
|
|
||||||
ttMove = ss->pv[ply];
|
ttMove = ss->pv[ply];
|
||||||
tte = TT.retrieve(posKey);
|
tte = TT.retrieve(posKey);
|
||||||
}
|
}
|
||||||
|
@ -1267,7 +1282,9 @@ namespace {
|
||||||
{
|
{
|
||||||
Value b = ttValue - SingularExtensionMargin;
|
Value b = ttValue - SingularExtensionMargin;
|
||||||
ss->excludedMove = move;
|
ss->excludedMove = move;
|
||||||
Value v = search<NonPV>(pos, ss, b - 1, b, depth / 2, false, threadID);
|
ss->skipNullMove = true;
|
||||||
|
Value v = search<NonPV>(pos, ss, b - 1, b, depth / 2, threadID);
|
||||||
|
ss->skipNullMove = false;
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
|
|
||||||
if (v < ttValue - SingularExtensionMargin)
|
if (v < ttValue - SingularExtensionMargin)
|
||||||
|
@ -1316,7 +1333,7 @@ namespace {
|
||||||
// The first move in list is the expected PV
|
// The first move in list is the expected PV
|
||||||
if (PvNode && moveCount == 1)
|
if (PvNode && moveCount == 1)
|
||||||
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, threadID);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, threadID);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Step 14. Reduced depth search
|
// Step 14. Reduced depth search
|
||||||
|
@ -1334,7 +1351,7 @@ namespace {
|
||||||
{
|
{
|
||||||
Depth d = newDepth - ss->reduction;
|
Depth d = newDepth - ss->reduction;
|
||||||
value = d < OnePly ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), threadID)
|
value = d < OnePly ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), threadID)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true, threadID);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, threadID);
|
||||||
|
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
}
|
}
|
||||||
|
@ -1347,7 +1364,7 @@ namespace {
|
||||||
assert(newDepth - OnePly >= OnePly);
|
assert(newDepth - OnePly >= OnePly);
|
||||||
|
|
||||||
ss->reduction = OnePly;
|
ss->reduction = OnePly;
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, true, threadID);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, threadID);
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
}
|
}
|
||||||
ss->reduction = Depth(0); // Restore original reduction
|
ss->reduction = Depth(0); // Restore original reduction
|
||||||
|
@ -1357,14 +1374,14 @@ namespace {
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
{
|
||||||
value = newDepth < OnePly ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), threadID)
|
value = newDepth < OnePly ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), threadID)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, true, threadID);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, threadID);
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step extra. pv search (only in PV nodes)
|
||||||
// Search only for possible new PV nodes, if instead value >= beta then
|
// Search only for possible new PV nodes, if instead value >= beta then
|
||||||
// parent node fails low with value <= alpha and tries another move.
|
// parent node fails low with value <= alpha and tries another move.
|
||||||
if (PvNode && value > alpha && value < beta)
|
if (PvNode && value > alpha && value < beta)
|
||||||
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), threadID)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, threadID);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, threadID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1725,7 +1742,7 @@ namespace {
|
||||||
Value localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
Depth d = newDepth - ss->reduction;
|
Depth d = newDepth - ss->reduction;
|
||||||
value = d < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
|
value = d < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
|
||||||
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, d, true, threadID);
|
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, d, threadID);
|
||||||
doFullDepthSearch = (value > localAlpha);
|
doFullDepthSearch = (value > localAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1738,7 +1755,7 @@ namespace {
|
||||||
|
|
||||||
ss->reduction = OnePly;
|
ss->reduction = OnePly;
|
||||||
Value localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, true, threadID);
|
value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, threadID);
|
||||||
doFullDepthSearch = (value > localAlpha);
|
doFullDepthSearch = (value > localAlpha);
|
||||||
}
|
}
|
||||||
ss->reduction = Depth(0); // Restore original reduction
|
ss->reduction = Depth(0); // Restore original reduction
|
||||||
|
@ -1749,14 +1766,14 @@ namespace {
|
||||||
{
|
{
|
||||||
Value localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
value = newDepth < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
|
value = newDepth < OnePly ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), threadID)
|
||||||
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, true, threadID);
|
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, threadID);
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step extra. pv search (only in PV nodes)
|
||||||
// Search only for possible new PV nodes, if instead value >= beta then
|
// Search only for possible new PV nodes, if instead value >= beta then
|
||||||
// parent node fails low with value <= alpha and tries another move.
|
// parent node fails low with value <= alpha and tries another move.
|
||||||
if (PvNode && value > localAlpha && value < sp->beta)
|
if (PvNode && value > localAlpha && value < sp->beta)
|
||||||
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -sp->beta, -sp->alpha, Depth(0), threadID)
|
value = newDepth < OnePly ? -qsearch<PV>(pos, ss+1, -sp->beta, -sp->alpha, Depth(0), threadID)
|
||||||
: - search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, false, threadID);
|
: - search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, threadID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 16. Undo move
|
// Step 16. Undo move
|
||||||
|
@ -2227,6 +2244,7 @@ namespace {
|
||||||
ss->init(i);
|
ss->init(i);
|
||||||
ss->initKillers();
|
ss->initKillers();
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
|
ss->skipNullMove = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct SearchStack {
|
||||||
Move killers[KILLER_MAX];
|
Move killers[KILLER_MAX];
|
||||||
Depth reduction;
|
Depth reduction;
|
||||||
Value eval;
|
Value eval;
|
||||||
|
bool skipNullMove;
|
||||||
|
|
||||||
void init(int ply);
|
void init(int ply);
|
||||||
void initKillers();
|
void initKillers();
|
||||||
|
|
Loading…
Add table
Reference in a new issue