Transposition table based cutoffs

Discussion of chess software programming and technical issues.

Moderator: Ras

Witek
Posts: 87
Joined: Thu Oct 07, 2021 12:48 am
Location: Warsaw, Poland
Full name: Michal Witanowski

Transposition table based cutoffs

Post by Witek »

Hi,
normally after probing TT we do something like:

Code: Select all

if (!PvNode & ttEntry.depth >= depth)
{
    if ((ttEntry.bounds == Bounds::Exact) ||
        (ttEntry.bounds == Bounds::Lower && ttScore >= beta) ||
        (ttEntry.bounds == Bounds::Upper && ttScore <= alpha))
    {
        return ttScore;
    }
}
At least the code looks like that in SF, Ethereal, Koivisto, and probably some other engines too.

However, when I did something more fancy:

Code: Select all

if (!PvNode & ttEntry.depth >= depth)
{
    if (ttEntry.bounds == Bounds::Exact)
    {
        return ttScore;
    }
    else if (ttEntry.bounds == Bounds::Upper)
    {
        if (ttScore <= alpha) return alpha;
        if (ttScore < beta) beta = ttScore;
    }
    else if (ttEntry.bounds == Bounds::Lower)
    {
        if (ttScore >= beta) return beta;
        if (ttScore > alpha) alpha = ttScore;
    }
}
I got +21.5 +/- 10.9 Elo gain, 100% LOS.

Am I missing something, or just found some new way to speedup the search?
Author of Caissa Chess Engine: https://github.com/Witek902/Caissa
Mergi
Posts: 127
Joined: Sat Aug 21, 2021 9:55 pm
Full name: Jen

Re: Transposition table based cutoffs

Post by Mergi »

Not a good idea. There's already a similar thread with some reasons as to why not do it. http://www.talkchess.com/forum3/viewtopic.php?t=59856

However the returned score from the TT is not completely useless either. Even if you don't make a cutoff, you can still use it to improve your static evaluation of the current position.

Code: Select all

if ((ttEntry.bounds == Bounds::Upper && staticEval > ttScore) || (ttEntry.bounds == Bounds::Lower && staticEval < ttScore)) {
  staticEval = ttScore;
}
abulmo2
Posts: 460
Joined: Fri Dec 16, 2016 11:04 am
Location: France
Full name: Richard Delorme

Re: Transposition table based cutoffs

Post by abulmo2 »

Shifting alpha and beta bounds on non pvnodes is useless (I suppose you are using pvs and not plain alphabeta). On non pv nodes beta=alpha+1, so if you increase the alpha value or decrease the beta value you should get a cutoff.
Richard Delorme
User avatar
j.t.
Posts: 263
Joined: Wed Jun 16, 2021 2:08 am
Location: Berlin
Full name: Jost Triller

Re: Transposition table based cutoffs

Post by j.t. »

I did something similar as well, and I believe I saw this in other engines, too.
Nalwald/search.nim#L163:

Code: Select all

    # update alpha, beta or value based on hash table result
    if (not hashResult.isEmpty) and height > 0 and (alpha > -valueInfinity or beta < valueInfinity):
        if hashResult.depth >= depth:
            case hashResult.nodeType:
            of exact:
                return hashResult.value
            of lowerBound:
                alpha = max(alpha, hashResult.value)
            of upperBound:
                beta = min(beta, hashResult.value)
            if alpha >= beta:
                return alpha
If it works for you, keep it.
User avatar
hgm
Posts: 28326
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Transposition table based cutoffs

Post by hgm »

I suppose this only works in combination with fail-hard, where beta would be returned when the score of the node is raised to above beta? Otherwise is would seem very wrong.
Joost Buijs
Posts: 1624
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Transposition table based cutoffs

Post by Joost Buijs »

Witek wrote: Tue Apr 05, 2022 5:34 pm However, when I did something more fancy:

Code: Select all

if (!PvNode & ttEntry.depth >= depth)
{
    if (ttEntry.bounds == Bounds::Exact)
    {
        return ttScore;
    }
    else if (ttEntry.bounds == Bounds::Upper)
    {
        if (ttScore <= alpha) return alpha;
        if (ttScore < beta) beta = ttScore;
    }
    else if (ttEntry.bounds == Bounds::Lower)
    {
        if (ttScore >= beta) return beta;
        if (ttScore > alpha) alpha = ttScore;
    }
}
I got +21.5 +/- 10.9 Elo gain, 100% LOS.

Am I missing something, or just found some new way to speedup the search?
You use this in nonPV nodes, so alpha equals beta-1, so (ttScore <= alpha) is the same as (ttScore < beta) and (ttScore >= beta) is the same as (ttScore > alpha). I don't see how this could do anything at all, if it does you must be entering nonPV nodes with wrong alpha beta values.
User avatar
hgm
Posts: 28326
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Transposition table based cutoffs

Post by hgm »

You assume he is using PVS. But perhaps this is just vanilla alpha-beta.
Joost Buijs
Posts: 1624
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Transposition table based cutoffs

Post by Joost Buijs »

Yes, this could be an exception. Not many people are using vanilla A-B these days, I completely forgot about it's existence.
Witek
Posts: 87
Joined: Thu Oct 07, 2021 12:48 am
Location: Warsaw, Poland
Full name: Michal Witanowski

Re: Transposition table based cutoffs

Post by Witek »

I'm using PVS, not vanilla AB, in fail-soft version. Indeed, adjusting alpha/beta does not change anything, like Joost noticed. What does matter though is whether I return alpha/beta/TT score on cutoff (depending on bounds) instead of TT score always. In the former case I observe 20 Elo gain. It's a bit weird, because it does not fit the fail-soft framework.
Author of Caissa Chess Engine: https://github.com/Witek902/Caissa
User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

Re: Transposition table based cutoffs

Post by pedrox »

Witek wrote: Mon Apr 11, 2022 10:58 pm I'm using PVS, not vanilla AB, in fail-soft version. Indeed, adjusting alpha/beta does not change anything, like Joost noticed. What does matter though is whether I return alpha/beta/TT score on cutoff (depending on bounds) instead of TT score always. In the former case I observe 20 Elo gain. It's a bit weird, because it does not fit the fail-soft framework.
I have tried it several times and I always have the same result as you.

I have not been able to take advantage of the result of the tables to improve the static evaluation either.

I have also tried cutting on pv_nodes except when there is an exact (so that the pv is not truncated). This seems to be somewhat better for me.