Zobrist hashing tutorials on YouTube

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
User avatar
maksimKorzh
Posts: 630
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Zobrist hashing tutorials on YouTube

Post by maksimKorzh » Sat Sep 19, 2020 10:49 am

Hey what's up guys, Code Monkey King's here.

I've never been implementing Zobrist hashing before.
A couple of days ago I've successfully(hopefully) embedded it into my chess engine (covered on YT like many of you know).
So obviously I've covered Zobrist hashing along with other engine development topics in the series as well.
Now assuming the style I'm using (which is hated by many for it's dumbness which I consider to be a benefit)
these tutorials (3 videos) might be considered as STAND ALONE Zobrist hashing tutorials that beginners
can make use of regardless of the entire engine.

So here are the links with a quick descriptions:
https://www.youtube.com/watch?v=W7dah-d ... s&index=67
defining and initializing random keys to hash position key, based on PRMG I made before for generating magic numbers for magic bitboards.
so it creates SAME hash keys regardless of environment

https://www.youtube.com/watch?v=sV2C7hx ... s&index=68
generating of a "almost" unique position identifier aka hash key from scratch
so it can be later used for indexing of transposition table and detecting 3 fold repetitions

https://www.youtube.com/watch?v=5EMLgIF ... s&index=69
And finally the most intriguing part - INCREMENTAL UPDATES of hash keys within a make move function.
Obviously this part is implementation dependent but the debugging scheme I use here is very clear and straightforward.
Also I want to give a credit to Pedro Castro who has kindly explained to me how this debugging is done:
viewtopic.php?f=7&t=75126

Hope this would be useful to someone.
Wukong Xiangqi (Chinese chess engine + apps to embed into 3rd party websites):
https://github.com/maksimKorzh/wukong-xiangqi

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

MOBMAT
Posts: 327
Joined: Sat Feb 04, 2017 10:57 pm
Location: USA

Re: Zobrist hashing tutorials on YouTube

Post by MOBMAT » Sat Sep 19, 2020 1:50 pm

I use the Polyglot random numbers for my Zobrist hashing for the following reasons:

1. they already exist, why reinvent the wheel.
2. the position hash will always match what the polyglot books require for lookup, so there isn't any further regeneration of another hash needed to probe the book.
3. it saves memory space.
4. it provides a way to validate the hash algorithm. make moves from the starting position and then probe the book. if you get the correct hit, you know both the hashing and probing are working.

here is the link to Harm's write up...
http://hgm.nubati.net/book_format.html
I created a C++ class to wrap everything into a nice tidy package.
i7-6700K @ 4.00Ghz (using 6 threads), EGTBs on PCI SSD
Benchmark: Stockfish 11 64 bmi2 (nps): 2067669

User avatar
maksimKorzh
Posts: 630
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Zobrist hashing tutorials on YouTube

Post by maksimKorzh » Mon Sep 21, 2020 12:01 am

MOBMAT wrote:
Sat Sep 19, 2020 1:50 pm
I use the Polyglot random numbers for my Zobrist hashing for the following reasons:

1. they already exist, why reinvent the wheel.
2. the position hash will always match what the polyglot books require for lookup, so there isn't any further regeneration of another hash needed to probe the book.
3. it saves memory space.
4. it provides a way to validate the hash algorithm. make moves from the starting position and then probe the book. if you get the correct hit, you know both the hashing and probing are working.

here is the link to Harm's write up...
http://hgm.nubati.net/book_format.html
I created a C++ class to wrap everything into a nice tidy package.
1. they already exist, why reinvent the wheel.
Cool. Didn't know about that, thanks.
I created a C++ class to wrap everything into a nice tidy package.
C++ is rocket science for me...
I'm forced to use OOP in my freelance jobs, so at least in chess programming I can go for good old plain functional C
Wukong Xiangqi (Chinese chess engine + apps to embed into 3rd party websites):
https://github.com/maksimKorzh/wukong-xiangqi

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

MOBMAT
Posts: 327
Joined: Sat Feb 04, 2017 10:57 pm
Location: USA

Re: Zobrist hashing tutorials on YouTube

Post by MOBMAT » Mon Sep 21, 2020 1:26 pm

maksimKorzh wrote:
Mon Sep 21, 2020 12:01 am
MOBMAT wrote:
Sat Sep 19, 2020 1:50 pm
I use the Polyglot random numbers for my Zobrist hashing for the following reasons:

1. they already exist, why reinvent the wheel.
2. the position hash will always match what the polyglot books require for lookup, so there isn't any further regeneration of another hash needed to probe the book.
3. it saves memory space.
4. it provides a way to validate the hash algorithm. make moves from the starting position and then probe the book. if you get the correct hit, you know both the hashing and probing are working.

here is the link to Harm's write up...
http://hgm.nubati.net/book_format.html
I created a C++ class to wrap everything into a nice tidy package.
1. they already exist, why reinvent the wheel.
Cool. Didn't know about that, thanks.
I created a C++ class to wrap everything into a nice tidy package.
C++ is rocket science for me...
I'm forced to use OOP in my freelance jobs, so at least in chess programming I can go for good old plain functional C
I code in what I call C+. No, not C or C++, but C+.
That refers to using features of both languages, mostly being what C developers really wanted in a OO language, such as classes. The language should be used to support the requirements, not the other way around. I recall once a conversation with a colleague who used the following example. If you are writing code to send rockets into space, you aren't going to chose a language that at any time, can arbitrarily decide when it is going to do memory garbage collection. But don't get me started... LOL

Knowing C makes it easy to understand what C++ is doing. If you learn C++ first, a lot of the underlying processes are glossed over. I like to know what my code is doing.
i7-6700K @ 4.00Ghz (using 6 threads), EGTBs on PCI SSD
Benchmark: Stockfish 11 64 bmi2 (nps): 2067669

User avatar
maksimKorzh
Posts: 630
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Zobrist hashing tutorials on YouTube

Post by maksimKorzh » Mon Sep 21, 2020 1:44 pm

MOBMAT wrote:
Mon Sep 21, 2020 1:26 pm
maksimKorzh wrote:
Mon Sep 21, 2020 12:01 am
MOBMAT wrote:
Sat Sep 19, 2020 1:50 pm
I use the Polyglot random numbers for my Zobrist hashing for the following reasons:

1. they already exist, why reinvent the wheel.
2. the position hash will always match what the polyglot books require for lookup, so there isn't any further regeneration of another hash needed to probe the book.
3. it saves memory space.
4. it provides a way to validate the hash algorithm. make moves from the starting position and then probe the book. if you get the correct hit, you know both the hashing and probing are working.

here is the link to Harm's write up...
http://hgm.nubati.net/book_format.html
I created a C++ class to wrap everything into a nice tidy package.
1. they already exist, why reinvent the wheel.
Cool. Didn't know about that, thanks.
I created a C++ class to wrap everything into a nice tidy package.
C++ is rocket science for me...
I'm forced to use OOP in my freelance jobs, so at least in chess programming I can go for good old plain functional C
Thanks for clarification

I code in what I call C+. No, not C or C++, but C+.
That refers to using features of both languages, mostly being what C developers really wanted in a OO language, such as classes. The language should be used to support the requirements, not the other way around. I recall once a conversation with a colleague who used the following example. If you are writing code to send rockets into space, you aren't going to chose a language that at any time, can arbitrarily decide when it is going to do memory garbage collection. But don't get me started... LOL

Knowing C makes it easy to understand what C++ is doing. If you learn C++ first, a lot of the underlying processes are glossed over. I like to know what my code is doing.
Wukong Xiangqi (Chinese chess engine + apps to embed into 3rd party websites):
https://github.com/maksimKorzh/wukong-xiangqi

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

Post Reply