Page 1 of 1

Zobrist hashing tutorials on YouTube

Posted: Sat Sep 19, 2020 12:49 pm
by maksimKorzh
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


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:
http://talkchess.com/forum3/viewtopic.php?f=7&t=75126

Hope this would be useful to someone.

Re: Zobrist hashing tutorials on YouTube

Posted: Sat Sep 19, 2020 3:50 pm
by MOBMAT
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.

Re: Zobrist hashing tutorials on YouTube

Posted: Mon Sep 21, 2020 2:01 am
by maksimKorzh
MOBMAT wrote: Sat Sep 19, 2020 3: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

Re: Zobrist hashing tutorials on YouTube

Posted: Mon Sep 21, 2020 3:26 pm
by MOBMAT
maksimKorzh wrote: Mon Sep 21, 2020 2:01 am
MOBMAT wrote: Sat Sep 19, 2020 3: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.

Re: Zobrist hashing tutorials on YouTube

Posted: Mon Sep 21, 2020 3:44 pm
by maksimKorzh
MOBMAT wrote: Mon Sep 21, 2020 3:26 pm
maksimKorzh wrote: Mon Sep 21, 2020 2:01 am
MOBMAT wrote: Sat Sep 19, 2020 3: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.