jordanbray / chess

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

Board hash should include side to move #16

Closed fanzier closed 5 years ago

fanzier commented 5 years ago

I'm using your crate (thank you for writing it!) for a chess engine and encountered the following problem: The Zobrist hash does not take into account which side is to move. This is vital information though, for instance this fails:

use chess::Board;
assert_ne!(
    Board::from_fen("8/q7/1q6/2k5/5K2/6Q1/7Q/8 w - - 0 1".into()).unwrap().get_hash(),
    Board::from_fen("8/q7/1q6/2k5/5K2/6Q1/7Q/8 b - - 0 1".into()).unwrap().get_hash());

However the first position is winning for white, the other is winning for black.

But–since both positions have the same hash–the transposition table gave nonsensical results, which confused my engine a lot.

(While we're at it: Is there a reason that from_fen takes a String and not a &str?)

fanzier commented 5 years ago

I'm sorry, I got something confused. The hash function does already take the side to move into account.

Sorry for the spam. :/