I am new to chess-programming (and I actually make engine to some variant of draughts) and currently I'm trying to understand transposition tables. I have seen many examples of transposition table look up implementations that differ in detail. I have the impression that the look up should differ depending on whether we are using fail-hard or fail-soft version of the alphabeta algorithm. But what confuses me is that I have seen implementations that used "fail-hard search" but "fail-soft transposition table" and vice versa (fail-soft search but fail-hard look up).
I think tt look up for Fail-hard Alpha-beta should look like this:
//... (Fail-hard)
if (entry.nodeType == Exact)
{
// Cached at PV-Node but alpha-beta range could change
if (entry.score >= beta) return beta; // respect Fail-hard beta cutoff (Cut-Node)
if (entry.score <= alpha) return alpha; // Fail-hard fail-low (All-Node)
return entry.score; // Within the window (PV-Node)
}
else if (entry.nodeType == UpperBound && entry.score <= alpha)
{
// All-Node
return alpha;
}
else if (entry.nodeType == LowerBound && entry.score >= beta)
{
// Cut-Node
return beta;
}
And for Fail-soft like this:
//... (Fail-soft)
if (entry.nodeType == Exact)
{
// Any node - even if alpha-beta range changed we would still return "bestScore"
return entry.score;
}
else if (entry.nodeType == UpperBound && entry.score <= alpha)
{
// All-Node
return entry.score; // in Fail-soft when we fail-low we don't clamp to alpha
}
else if (entry.nodeType == LowerBound && entry.score >= beta)
{
// Cut-Node
return entry.score; // in Fail-soft when we fail-high we don't clamp to beta
}
Am I right or am I missing something?
Another thing I noticed is that some implementations store "bestMove" for All-Nodes, while other don't save any move when we fail-low ("empty" or "incorrect" move is stored instead). While browsing the internet, I found opinions that even if in All-Node we do not know which move is actually the best, it is still worth keeping the one that returned the highest bound (as it would be good guess for move-ordering anyway), when others think that it doesn't make sense and may only spoil the move-ordering, who is right?
So my questions are:
- Should transposition table look up differ depending on whether we are using Fail-hard or Fail-soft version of the Alpha-beta algorithm? And are my examples correct?
- Is it worth to store "bestMove" even when its score is lower than alpha?