Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: very simple question for hash tables.

Author: Tom Kerrigan

Date: 21:47:11 01/13/00

Go up one level in this thread


'^' is the logical XOR operator in C.

It has the interesting property that (A ^ B) ^ B = A. Example:

12345 ^ 6789 = 10940
10940 ^ 6789 = 12345

To come up with a "unique" number for a particular chess position, you can do
the following:

unique_id = 0 ^ black_rook_on_a8 ^ black_knight_on_b8 ^ ...

Where black_rook_on_a8 is a random (but constant) integer. Now, because of the
property mentioned above, you can easily update this unique ID when a piece is
moved. Let's say you move the rook from a8 to a7:

unique_id = unique_id ^ black_rook_on_a8;
unique_id = unique_id ^ black_rook_on_a7;

The benefit is that you can hash up this unique ID and use it to index a hash
table.

-Tom

On January 13, 2000 at 21:43:09, Antonio Dieguez wrote:

>hi!, I would like to know what is Zorbist? how it works?
>and what does '^' does?
>
>Thanks.Am sorry my foolish questions...
>
>me.



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.