All tt Entries have depth 0 (and I don't know why)

Discussion of chess software programming and technical issues.

Moderator: Ras

Gioviok
Posts: 5
Joined: Tue Aug 17, 2021 1:08 pm
Full name: Giovanni Maria Manduca

All tt Entries have depth 0 (and I don't know why)

Post by Gioviok »

Hello everyone, it has been a while since I last posted. I hope this post finds all the community well.
So I finally finished the complete rewrite of my engine, and I am getting pretty good results.
Yesterday I was adding various debug prints in the code of the engine, to mesure the metrics of the code. In particular I was concentrating on the Transposition Table, since I had a feeling there may have been problems with it, since I still can't solve Fine#70.

Now in my code, I have this part of the negamax routine:

Code: Select all

// Step 3: TT probe
    Score ttScore = -infinity;
    Move ttMove = 0;
    U8 ttFlag = 255;
    ttEntry* entry = fetchTT(pos.hashKey);
    if (entry) {
        ttScore = entry->score;
        ttMove = entry->bestMove;
        ttFlag = entry->flags;
        // Account for mate values
        ttScore += ply * (ttScore < -mateValue);
        ttScore -= ply * (ttScore > mateValue);
        // Only return value in non pv nodes
        if (!pvNode) {
            if (tt->depth >= depth ) {
                Score toRet = -infinity;
                if (ttFlag == hashEXACT) toRet = ttScore;
                if (ttFlag == hashALPHA && ttScore <= alpha) toRet = alpha;
                if (ttFlag == hashBETA && ttScore >= beta) toRet = beta;
                if (toRet != -infinity) {
                    // Update scores as if we did find the move through a normal search
                    if (ttScore >= beta) {
                        killerTable[1][ply] = killerTable[0][ply];
                        killerTable[0][ply] = ttMove;
                        counterMoveTable[movePiece(pos.lastMove)][moveTarget(pos.lastMove)] = ttMove;
                    }
                    else if (ttScore >= alpha) {
                        historyTable[pos.side][moveSource(ttMove)][moveTarget(ttMove)] += ((int)depth * (int)depth) / 2;
                        localHistory[ply][moveSource(ttMove)][moveTarget(ttMove)] += ((int)depth * (int)depth) / 2;
                    }
                    return toRet;
                }
            }
        }
    }
Where the fetchTT function is the following:

Code: Select all

ttEntry *fetchTT(HashKey key){
    ttEntry *entry = &tt[key % ttSize];
    if (entry->hashKey == key) return entry;
    return 0;
}
When I added the a cout to print whenever I was inside the

Code: Select all

 (tt->depth >= depth ) 
and run the program, it didn't print a single thing.
Now that is, I think, not a normal behaviour.
So I tried doing a depth 18 search on startposition. I then read the depth from every entry from the transposition table and, to my horror, every entry had depth 0.

I don't know what the problem can be.
My tt entry structure is fairly simple:

Code: Select all

struct ttEntry {
	HashKey hashKey;
	U16 bestMove;
	Depth depth;
	U8 flags = 3;
	Score score = -infinity;
};
The hashtable is very basic, only entries with no buckets.
The replacement scheme is the following:
  • If the entry has the same hashKey replace when new depth is greater or equl to the one in the ttEntry
  • If the entry doesn't have the same hashKey (different position), replace when

    Code: Select all

    entry->depth <= depth + 2 * (flags == hashEXACT)
    (where depth is the new depth and flags is the new flag).
I only write to the tt when I get a beta cutoff, when I get a checkmate or a stalemate and when I exhausted all the moves for a node.

The hashKey generation works, having passed a 6300+ positions perft suite with the generated hashKey checked against the incrementally updated, I also made the engine play 100 matches at 1 second per move from book positions with the same check, and there seems to be no problem.

What could it be?
Has anyone ever had this kind of problem?
Will I be able to solve Fine#70 before I die?

Thanks in advance for all the responses.
yeni_sekme
Posts: 40
Joined: Mon Mar 01, 2021 7:51 pm
Location: İstanbul, Turkey
Full name: Ömer Faruk Tutkun

Re: All tt Entries have depth 0 (and I don't know why)

Post by yeni_sekme »

I guess if (tt->depth >= depth ) should be if (entry->depth >= depth ).
Gioviok
Posts: 5
Joined: Tue Aug 17, 2021 1:08 pm
Full name: Giovanni Maria Manduca

Re: All tt Entries have depth 0 (and I don't know why)

Post by Gioviok »

yeni_sekme wrote: Mon May 23, 2022 3:31 pm I guess if (tt->depth >= depth ) should be if (entry->depth >= depth ).
Well that's a nice way to say I am stupid...
I can't believe I missed this. I can't thank you enough, I was going insane.
Fine 70# seems to work.
Life is good. :D