niklasf / shakmaty

A Rust library for chess and chess variant rules and operations
https://docs.rs/shakmaty
GNU General Public License v3.0
210 stars 41 forks source link

zobrist hashing #45

Closed niklasf closed 3 years ago

niklasf commented 3 years ago

for #40

niklasf commented 3 years ago

@wspeirs Thanks, this looks good so far. There are a few issues with chess variants. I believe it does not handle explosions in Atomic (a bug), and does not consider remaining checks in ThreeCheck (avoidable collisions).

Maybe you can make the variants implement a supporting trait ZobristHashable? That would allow skipping those variants and third-party variants.

wspeirs commented 3 years ago

@niklasf I did not take into account any of the variants. Looking at the code around play_unchecked for Atomic, it wouldn't be hard to encode the logic (removing the piece hashes when "exploding"); however, I'm unsure how to work this in via the feature gate mechanism in Rust. I think I need specialization, unless there's some "magic" we can perform with the feature-gate code. Any ideas on how to implement would be great!

Assuming we figure out the specialization/feature-gate stuff for Atomic, then it would be a bit more work to get ThreeCheck working. I'd need to add 6 more values to build.rs that represent how many checks are left for each side. Not terribly difficult, but slightly more work than Atomic.

niklasf commented 3 years ago

Continued in #46.