-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement incremental Zobrist hashing #40
Comments
Thanks, that's a useful feature. My concern is that it has some overhead even when unused. It would be great to have a (type-safe) way to opt-in. Not sure how to design it. Maybe something like |
I think the overhead is fairly minimal... a few table lookups and some XORs. That said, I'm not sure I'm getting the information (square and piece mostly) in the most optimal way in all instances, so I'd love some feedback on that. As for creating a wrapper type, it would probably be a trait or something that has it's own |
I am also not sure about the design. I feel like enabling hashing should probably not be a runtime decision, i.e. not an optional argument, because the developer will know if they need hashing or not at compile time. These particular benchmarks are very important to me:
Usually it is hard to improve even a single percent point while keeping the code somewhat idiomatic, so a multiple percent regression is quite significant. It may not seem like much, but for example it would add hours when processing a large database like https://database.lichess.org/ with https://github.com/niklasf/rust-pgn-reader. |
I had not run Regardless, I'll think on ideas on how to add hashing (or not) during compile-time and keep these benchmarks in-tact. I'm just happy I have it working. I would also love to see an efficient |
No concrete ideas, but that would be awesome. I'd probably be greedy, though, accept the performance improvements and still reject hashing with overhead 😄 |
Ha ha ha... totally understood. I'll chew on this and see what I can come up with. Thanks again! |
@niklasf sorry for the long pause on this... life got in the way :-) I thought about this, and I think I have a solution that'll make everyone (well maybe not everyone, but you and me :-) ) happy. I'll create a new struct This way if someone wants Zobrist hashing, they simply create that struct: Before I go too deep on this, let me know your thoughts... playground here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c440472cedfae9d4acb2119568057cd5 |
Yep, that sounds great. |
@niklasf I've updated my repo: https://github.com/wspeirs/shakmaty I ran |
I made some progress on what I think is a reasonably clean interface. The main trait is no longer just a marker, but also contains the implementation. There's an additional trait
|
At least until there is one actual implementation.
I'm working on adding Zobrist hashes to shakmaty: https://github.com/wspeirs/shakmaty
@niklasf would love your feedback on what I have thus far. I still need to implement it for all the variations; however, I have
do_move
complete so it shouldn't be too bad. I have a unit test that computes 100k positions and ensures there are no collisions. I've also gone up to 1m, but it takes a while unless you're running on release.Let me know how to proceed and any feedback... thanks!
The text was updated successfully, but these errors were encountered: