chess icon indicating copy to clipboard operation
chess copied to clipboard

Bug in Board Hash trait implementation

Open barakugav opened this issue 2 years ago • 3 comments

The implementation of the Hash trait uses only the field 'hash' which is only affected by the pieces positions. On the other hand, the implementation of PartialEq compare all fields of the struct. This causes unnecessary collisions in hashmap/hashset. To solve it, the implementation of the Hash trait could simply use the get_hash() func.

barakugav avatar Sep 24 '22 17:09 barakugav

I do not believe this is true. The reason the hash trait is implemented the way it is is to incrementally update the hash function. This is a technique called Zobrist hashing.

If you can find an example of such a collision, I'd love to see it.

jordanbray avatar Feb 12 '23 16:02 jordanbray

The current implementation does not include the castling right for exmaple, or en passant value

barakugav avatar Feb 12 '23 17:02 barakugav

Ahh. You are correct. I misread the comment.

jordanbray avatar Feb 12 '23 18:02 jordanbray