0

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:

  1. 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?
  2. Is it worth to store "bestMove" even when its score is lower than alpha?
kubpica
  • 71
  • 1
  • 4
  • Hi, I am not entirely sure what you mean with fail-hard or fail-soft versions of alpha-beta. I suggest you look at CodeMonkeyKings tutorial series: https://www.youtube.com/watch?v=QUNP-UjujBM&list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs, transposition tables starting on episode 70. It helped me a lot when doing this. – eligolf May 16 '22 at 05:10
  • @eligolf I know this website he uses in his video. This website uses fail-hard version of alphabeta, and I wonder shouldn't there be extra cutoff-ifs in case of the hashfEXACT just like in my example? Fail-soft is supposed to be optimization of alphabeta, in fail-soft version you don't clamp returned values to alpha/beta so I think tt look up should work even differently in case of Fail-soft. But like I said I have seen implementations that used "fail-hard search" but "fail-soft transposition table" and vice versa - and that's confusing. – kubpica May 16 '22 at 12:30
  • Example of "fail-hard search" but "fail-soft look up": https://github.com/SebLague/Chess-AI Example of "fail-soft search" but "fail-hard look up": https://github.com/algerbrex/blunder – kubpica May 16 '22 at 12:50
  • I just checked Stockfish source code and it uses fail-soft version and they don't clamp values returned from tt to alpha/beta, so I think I may be right about the first issue. About the second issue: Stockfish doesn't store "bestMove" for All-Nodes (when all moves failed-low) but they do store "bestMove" for Cut-Nodes (when beta-cutoff happens, even tho it may not be the actual best move as we don't check all moves in this case). I found old discussion about this: https://groups.google.com/g/rec.games.chess.computer/c/p8GbiiLjp0o/m/hKkpT8qfrhQJ I guess I will just check what works for me best. – kubpica May 16 '22 at 20:17
  • 1
    Yeh TTs are a mess honestly, very hard to implement without bugs. They might look good and then in some situations the engine makes some stragne move due to a wrongly stored move in the table. TT is the part I hate most about chess programming, hard to understand, hard to implement, hard to debug :P You are probably right, test what works for you and go for it – eligolf May 17 '22 at 03:38

0 Answers0