Author: Dave Gomboc
Date: 12:22:54 01/14/00
Go up one level in this thread
On January 14, 2000 at 13:38:19, Jesus de la Villa wrote: >On January 14, 2000 at 00:55:43, Frank Schneider wrote: > >>On January 14, 2000 at 00:47:11, Tom Kerrigan wrote: >> >>>'^' 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 >>Yes, I think everyone does it like this and it works great. >>Be careful that your numbers are long enough - use 64bit to >>make sure you don't get collisions. 32 bit is not enough - do you know the >>'birthday paradoxon'? >> >>Frank >> > >No, can you tell me ? How many people do you need in a room before it is at least 50% probable that two or more of them have the same birthday (month and day, but not year)? Dave
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.