chess icon indicating copy to clipboard operation
chess copied to clipboard

Replace Hashing method

Open Kerrigan29a opened this issue 6 years ago • 4 comments

The hashing method it's very expensive (because of the MD5 dependency) to use it in any cache or transposition table. I suggest to implement Zobrist hashing wich is the de-facto standard.

Possible reference implementations:

  • dylhunn/dragontoothmg (Go): https://github.com/dylhunn/dragontoothmg/blob/b0146de1e275d419ae46e1f36d3cec255d5a2a7b/util.go#L11
  • niklasf/python-chess (Python): https://github.com/niklasf/python-chess/blob/f4e7c53a3695af6d5e14da04e69fcb862f378cac/chess/polyglot.py#L230, https://github.com/dylhunn/dragontoothmg/blob/b0146de1e275d419ae46e1f36d3cec255d5a2a7b/constants.go#L21
  • lemire/zobristhashing (C): https://github.com/lemire/zobristhashing/blob/f51882643d27845e5017bcbdcac79f2522c33532/src/zobrist.c

Kerrigan29a avatar Dec 17 '18 00:12 Kerrigan29a

Love it. Ill take a look at it this weekend. @Kerrigan29a if you want to take a stab to compare benchmarks Ill review before then. Also the CPU profiler might be useful.

notnil avatar Dec 17 '18 20:12 notnil

I have implemented it. You can find in #49

Kerrigan29a avatar Mar 22 '20 18:03 Kerrigan29a

@Kerrigan29a thanks for the pull. I will review it. Definitely a better approach than the current implementation, but I don't like the dependencies outside the standard lib. I have tried to keep those down historically (not as relevant today with module additions). They seem to be used to test for collisions which I totally get but adds a lot of distraction to the repo for just the hash. Let me think on it.

notnil avatar Mar 24 '20 23:03 notnil

You are welcome. I used golang.org/x/text/language and golang.org/x/text/message in the tool to view big numbers with thousands separator. Remove it if you want and just use fmt.Printf or remove the entire collision checking tools.

Kerrigan29a avatar Mar 25 '20 00:03 Kerrigan29a