sje wrote:When moving one ply down (away from the root), the window bounds are swapped and then shifted down. When moving one ply up (towards the root), the result score is shifted up.
Note: It is possible to get scores better than mate in one or worse than checkmated, so there has to be a safety range between mate in one and +infinity and also between checkmated and -infinity. This safety margin length has to be at least as long as the greatest possible search ply.
In my draughts program, I also use distance-to-mate with respect to the leaf node, not to the root. However, I don't have a safety margin between the smallest loss/win and infinity:
Code: Select all
inline int infinity()
{
return SHRT_MAX;
}
inline int loss_min()
{
return -(infinity() - 1);
}
Mate adjustment is done like this:
Code: Select all
// loss and win values are "stretched" one step towards the edges of the [-INF, +INF] interval
inline int stretch(int value)
{
return value - is_loss(value) + is_win(value);
}
// loss and win values are "squeezed" one step towards the center of the [-INF, +INF] interval
inline int squeeze(int value)
{
return value + is_loss(value) - is_win(value);
}
which is called as
Code: Select all
value = -squeeze(pvs<PV>(pos, -stretch(beta), -stretch(alpha), depth - 1,...));
Of course, you have to be careful not to let the search window collapse when one of the bounds crosses over to infinity. This is done by mate distance pruning:
Code: Select all
// alpha < beta <= +INF implies alpha <= win_min
// with equality, any finite score will fail low
if (alpha == win_min())
return alpha;
// -INF <= alpha < beta implies loss_min <= beta
// with equality, any finite score will fail high
if (beta == loss_min())
return beta;
What the above code does is to cutoff null-window nodes with either alpha or beta equal to plus/minus infinity. I have the same assert() statements as Stockfish to check the sanity of the alpha-beta window (as a function of the node type). I use automated unit tests to run mate searches on dozens of tablebase positions without error.