Dirty hashing trick

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
leanchess
Posts: 176
Joined: Sun Dec 08, 2019 8:16 pm
Full name: Dmitry Shechtman

Re: Dirty hashing trick

Post by leanchess »

hgm wrote: Sun Apr 26, 2020 5:09 pm Micro-Max doesn't bother to hash the castling rights.
How does that work?

Edit: I messed up the timings. I should have made sure -DNDEBUG wasn't commented out :oops:
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Dirty hashing trick

Post by hgm »

Well, I don't think there is much gain in going from a lookup table fo 64 keys to two of 8 keys. That would be different for a 1000 x 1000 board.
User avatar
leanchess
Posts: 176
Joined: Sun Dec 08, 2019 8:16 pm
Full name: Dmitry Shechtman

Re: Dirty hashing trick

Post by leanchess »

The idea is to substitute lookup with addition/subtraction. I tried implementing this in double push, but there seems to be a bug somewhere in my logic.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Dirty hashing trick

Post by hgm »

leanchess wrote: Mon Apr 27, 2020 3:47 pm
hgm wrote: Sun Apr 26, 2020 5:09 pm Micro-Max doesn't bother to hash the castling rights.
How does that work?
You just accept that it confuses position with and without castling rights that are otherwise the same, on hash probes. Almost never happens anyway, and if it does, so what?
Ras
Posts: 2488
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Dirty hashing trick

Post by Ras »

hgm wrote: Mon Apr 27, 2020 6:59 pmYou just accept that it confuses position with and without castling rights that are otherwise the same, on hash probes. Almost never happens anyway, and if it does, so what?
Nearly the same here, except that I verify the hash move for pseudo legality, including castling rights if the move is castling. I treat the lookup as failed if the move doesn't pass this test. Full legality is checked later, not in the hash lookup.
Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Dirty hashing trick

Post by hgm »

I guess it helps that in micro-Max castling can never be a hash move. Castlings and double-pushes need to pass an e.p. square to the daughter, and what that square is can only be known if the move generator generates them, not when they come from the hash table. So they cannot be allowed to become hash move, which is realized by storing them with a recognizably invalid toSquare in the hash table when they end up as best move. Move generation always starts with the piece on the fromSquare of the hash move, though, and castlings would be the first King moves it generates, when these are allowed. (And in Fairy-Max double pushes are the first move it generates on a Pawn). So it isn't a big problem; occasionally it would start trying the wrong castling. But in a node without castling rights the castling would not be generated.