jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
243 stars 55 forks source link

Bug in Board Hash trait implementation #75

Open barakugav opened 2 years ago

barakugav commented 2 years ago

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.

jordanbray commented 1 year ago

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.

barakugav commented 1 year ago

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

jordanbray commented 1 year ago

Ahh. You are correct. I misread the comment.