Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Hash table allocation

Author: Dieter Buerssner

Date: 13:49:50 08/26/03

Go up one level in this thread


Another idea, that probably is not used in any chess engine yet, and that will
work without modulo (but will need branches instead). When you know the number
of entries, create a random table (just like for Zorbrist hashing) of numbers
that are uniformly ditributed between 0 and max_index. Have a 32 bit number for
indexing. When putting a piece on the board, instead of

  idx ^= table[piece][sq][side];

use

  idx += table[piece][sq][side];
  if (idx >= max_index)
    idx -= max_index;

which is the same as

  idx = (idx + table[piece][sq][side]) % max_index;

under these conditions.

So, use add instead of xor. For removing a piece, use sub. The idx will always
stay between 0 (inclusive) and max_idx (exclusive) this way, and will be
distributed randomly.

BTW. the same method (using add/sub instead of xor) would also work without the
need of branches for the normal key generation. Just let the results
overflow/underflow, as is the case for normal unsigned arithmetics in C.

Regards,
Dieter



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.