ep and castle rights hashing

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: ep and castle rights hashing

Post by xmas79 »

rtitle wrote:Actually, if your move generator generates only legal moves (not pseudo-legal moves), then #1 is easy to implement.
I have a pseudo-legal movegen. Thinking about it, it's easy in pseudo-legal movegens too.
rtitle wrote:...Therefore, the following algorithm is sufficient:

position->generate_moves(movelist /* output arg */);
if (movelist contains any e.p. captures)
/* don't bother transcribing it's hash to whatever you're using to detect repetitions; it can't repeat */;
else
hash position and transcribe hash to history for detecting repetitions

Then at the point where you want to detect if a move leads to a repletion:

position->make_move(move);
hash position and look up in the history to detect if you've reached a repetition

Rich
Yes, but you always want to detect repetitions and probe TT *BEFORE* generating moves... So this is horrible from a performance point of view.

You can do this: when making a double pawn push, in makemove check if the ep capture is legal (simply remove pushed pawn and the adiacent pawn and see if king is in check, if there are two pawns do this check for both), if it's legal then you set the ep square, else you don't. That's the same as Option 1, as you will set the ep square only on pawn pushses that allows effectively legal ep moves, but is this worth? I mean, you are moving a legality test one ply earlier for (maybe) slightly better TT probes and chances are that you would never needed to do that check because a pawn ep capture is usually bottom in the captures list, so a cut off could occur, and you just did an expensive legality test when none were required... Statistically speaking, how many double pushes cannot lead to ep capture because pawn is pinned on king??? I bet low numbers are involved here, so it will probabilty hurt than help.

Natale.
rtitle
Posts: 33
Joined: Wed Aug 14, 2013 7:23 pm

Re: ep and castle rights hashing

Post by rtitle »

"when making a double pawn push, in makemove check if the ep capture is legal (simply remove pushed pawn and the adiacent pawn and see if king is in check...")

The above doesn't quite work. Consider:

[d]1b5k/8/8/3pP3/8/8/7K/8 w ----

Suppose black has just played ...d7-d5. Then exd6 is legal, but your algorithm ("remove the pushed pawn and capturing pawns and see if the king is in check") will say it's illegal. Point being, after the e.p. capture the pawn on d6 still blocks the bishop check.

One the trickiest parts of my engine is the part of move generator that detects "is legal". To avoid the cost of doing a nested movegen to ask "is my king in check", I mark all pinned pieces with the *directions* they are pinned in (e.g. in the above example the pawn on e5 is pinned from moving in the "up" direction but not in the "up-left" direction). There are tricky special cases in the code to handle e.p. captures, but if you get it right you can build a legal movegen that doesn't cost much more than a pseudo-legal movegen.

Rich
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: ep and castle rights hashing

Post by xmas79 »

Oh yes, my mistake, I thought about this situation only after a while I posted...

As already said, we could do this easily in the double push makemove to avoid setting the ep square, but I really don't think it will give any measurable performance benefits, since a pinned pawn after an opponent double push is a very rare corner case IMHO. But I'm afraid I don't have a valid framework for testing this...

And I also try to defer everything as late as possible w.r.t. the performace...

Natale.