No Zobrist key

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: No Zobrist key

Post by Henk »

Used FNV hash function for computing 64 bit key. Don't know yet if that is an improvement compared to my 8 x 64 bit key. For now I also need to check if hash move is a valid move. Looks like my engine does not crash (very often) though I don't trust these 64 bit keys.

Code: Select all

 
public class Key2: IKey
    {
        public ulong Rep;


        public void Hash(ref ulong hash, ulong x)
        {            
            ulong octetMask = 255;
            for &#40;int j = 0; j < 8; j++)
            &#123;
                hash *= 1099511628211;
                hash ^= &#40;uint&#41;&#40;x & octetMask&#41;;
                octetMask <<= 8;
            &#125;
        &#125;

        public Key2&#40;IChessBoardBits board&#41;
        &#123;
            Rep = 14695981039346656037;
            Hash&#40;ref Rep, board.Pawns&#41;;
            Hash&#40;ref Rep, board.Kings&#41;;
            Hash&#40;ref Rep, board.Knights&#41;;
            Hash&#40;ref Rep, board.Bishops&#41;;
            Hash&#40;ref Rep, board.Rooks&#41;;
            Hash&#40;ref Rep, board.Queens&#41;;
            Hash&#40;ref Rep, board.WhitePieces&#41;;
            Hash&#40;ref Rep, board.Other&#41;;
           
        &#125;
flok

Re: No Zobrist key

Post by flok »

After you have a tt-hit, count how often it was a valid hit (e.g. the move returned is in the current list of valid moves) and which were not.
That way you can verify if your hashing alg. is sufficient or not.

With a tt of 4GB and using md5-chain for randoms I have a false hit percentage of on average 0.011% (5 games played in auto-mode).
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: No Zobrist key

Post by Henk »

Looks like my engine is twice as slow as before. Don't know yet why. Perhaps creating 64 bit hash key costs too much. In previous key implementation I only had to copy 8 x 64 bits (these bit boards).
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: No Zobrist key

Post by bob »

Henk wrote:Looks like my engine is twice as slow as before. Don't know yet why. Perhaps creating 64 bit hash key costs too much. In previous key implementation I only had to copy 8 x 64 bits (these bit boards).
You are doing something badly wrong.

To make a move you simply need to do TWO XOR operations, one to remove the from square, one to add the to square. A capture adds a third XOR to remove the captured piece.

To unmake, you simply restore the original hash signature that you should have saved before updating it...

I can't even measure the cost of this in my engine it is so small.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: No Zobrist key

Post by Henk »

Is that about Zobrist hash key computation ?

[For making and unmaking a move I currently have to update these bit boards and also a chessboard of squares]
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: No Zobrist key

Post by bob »

Henk wrote:Is that about Zobrist hash key computation ?

[For making and unmaking a move I currently have to update these bit boards and also a chessboard of squares]
Yes, it is about the incremental update of the hash signature. That was what you were originally asking about I thought...

The computational cost for this should be near zero.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: No Zobrist key

Post by jwes »

flok wrote:After you have a tt-hit, count how often it was a valid hit (e.g. the move returned is in the current list of valid moves) and which were not.
That way you can verify if your hashing alg. is sufficient or not.

With a tt of 4GB and using md5-chain for randoms I have a false hit percentage of on average 0.011% (5 games played in auto-mode).
That seems extraordinarily high. I just ran a test and had 1 false hit in a week.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: No Zobrist key

Post by Henk »

bob wrote:
Henk wrote:Looks like my engine is twice as slow as before. Don't know yet why. Perhaps creating 64 bit hash key costs too much. In previous key implementation I only had to copy 8 x 64 bits (these bit boards).
You are doing something badly wrong.

To make a move you simply need to do TWO XOR operations, one to remove the from square, one to add the to square. A capture adds a third XOR to remove the captured piece.

To unmake, you simply restore the original hash signature that you should have saved before updating it...

I can't even measure the cost of this in my engine it is so small.
There is also an XOR for side to move.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: No Zobrist key

Post by bob »

Henk wrote:
bob wrote:
Henk wrote:Looks like my engine is twice as slow as before. Don't know yet why. Perhaps creating 64 bit hash key costs too much. In previous key implementation I only had to copy 8 x 64 bits (these bit boards).
You are doing something badly wrong.

To make a move you simply need to do TWO XOR operations, one to remove the from square, one to add the to square. A capture adds a third XOR to remove the captured piece.

To unmake, you simply restore the original hash signature that you should have saved before updating it...

I can't even measure the cost of this in my engine it is so small.
There is also an XOR for side to move.
I don't do that in Make/Unmake. I do that at the time I use the signature to probe or store. You don't want to xor in side to move at ply=1, then xor it in again at ply=3, as you just undid the xor.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: No Zobrist key

Post by Henk »

bob wrote:
Henk wrote:
bob wrote:
Henk wrote:Looks like my engine is twice as slow as before. Don't know yet why. Perhaps creating 64 bit hash key costs too much. In previous key implementation I only had to copy 8 x 64 bits (these bit boards).
You are doing something badly wrong.

To make a move you simply need to do TWO XOR operations, one to remove the from square, one to add the to square. A capture adds a third XOR to remove the captured piece.

To unmake, you simply restore the original hash signature that you should have saved before updating it...

I can't even measure the cost of this in my engine it is so small.
There is also an XOR for side to move.
I don't do that in Make/Unmake. I do that at the time I use the signature to probe or store. You don't want to xor in side to move at ply=1, then xor it in again at ply=3, as you just undid the xor.

In case of a collision there is a possibility of very stupid blunders like incorrect queen sacrifice. Making an engine very foolish.