I'm relatively new to hashing and wanted to ask a question.
I have this PawnHashElement-record:
Code: Select all
TPawnHashElement = record
Key : U64; // pawnhashkey
CollisionCheck : U64; // board.hashkey to doublecheck collisions
Evaluation : Integer; // pawn evaluation
end;
I noticed that with only one 64-bits number I got a lot of wrong evaluations from the table so I added an extra CollisionCheck 64-bits number and this seems to work well.
The question is: do I really need two 64-bits numbers to avoid retreiving a wrong evaluation from the hash-table? Is one not enough?
BTW: I use random ZobristKeys: for each square/piece a random number which is xor-ed when the board changes.
The code for storing:
Code: Select all
procedure TPawnHash.Store(const B: TBoard; aEvaluation: Integer);
begin
with fArray^[B.PawnHashKey mod Size] do
begin
Key := B.PawnHashKey;
Evaluation := aEvaluation;
CollisionCheck := B.HashKey;
end;
end;Code: Select all
function TPawnHash.Probe(const B: TBoard): Integer;
begin
with fArray^[B.PawnHashKey mod Size] do
begin
if (Key = B.PawnHashKey) and (CollisionCheck = B.HashKey) then
Result := Evaluation
else
Result := PROBE_UNKNOWN;
end;
end;