Code: Select all
int PVS_FailSoft_A(int alpha, int beta, ...) {
...
ASSERT(alpha < beta);
bool isZeroWindow = (beta == alpha+1); // not part of algorithm
bool isFirstMove = true;
int bestScore = -INF;
for (all moves) {
int score;
make();
if (isFirstMove) {
isFirstMove = false;
score = -PVS_FailSoft_A(-beta, -alpha, ...);
} else {
score = -PVS_FailSoft_A(-(alpha+1), -alpha, ...);
if (score > alpha) {
ASSERT(score > alpha);
ASSERT(score > bestScore);
//
// can be either PV node or zero-window (non-PV) node
//
// Q: would it be correct to avoid a re-search for "score >= beta" in fail soft?
// If so, in which of the two cases (PV or non-PV node)?
//
score = -PVS_FailSoft_A(-beta, -alpha, ...);
}
}
unmake();
if (score >= beta) {
return score;
}
if (score > bestScore) {
bestScore = score;
alpha = Max(alpha, bestScore);
}
}
return bestScore;
}
In my opinion you can trust the score, in both PV and non PV ndoes. As already said, non PV nodes are easy to figure out. In PV nodes, let's do with an example: if you have a window of say [alpha,beta]=[100,300], on the first move suppose you get a score of 200, then you collapse the window to [200,201] and do a search with [-201,-200], and get a fail high with a value > beta, say 400. If you research with a window of [-300,-200], you will end up with a score of 400 again, since you will have a TT probe with good draft, bound type (all-node) and value, as soon as you enter the node. That child node, in fact, will continue to fail low unless you search it in a way that would not cause the cut-off, eg with a bound like [-401, -200], and now we are like in the case of an exact score, where search can effectively search and return another score, so in this case I do not trust the score.