ep and castle rights hashing

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: ep and castle rights hashing

Post by syzygy »

hgm wrote:I think Edmund's statement is more general: any position that has castling rights (check or not) is upward compatible with corresponding position where you have none. (...)
This seems to be behind his last paragraph, but I don't see the connection with the second paragraph.

I might have misinterpreted what he meant with "static evaluation", though. I understood this as referring to "the" static evaluation of a chess engine, but maybe he is thinking of a static detection of whether still having the right to castle is potentially useful. Even then I do not agree with his statement. It should be: even if there is just 0.001% change that P1 is better (or worse) than P2, they need different hash keys (but if you want to get 3-fold repetition right, this is still not enough). Maybe just a case of inaccurate formulation.
User avatar
hgm
Posts: 27822
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: ep and castle rights hashing

Post by hgm »

I read it as 'static' meaning you only have to look at static properties of the position (i.e. piece locations and castling rights) to conclude with certainty that the one with the castling rights is better or equal. (And perhaps give a minimum of how much it is better.)
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: ep and castle rights hashing

Post by Edmund »

syzygy wrote:
hgm wrote:I think Edmund's statement is more general: any position that has castling rights (check or not) is upward compatible with corresponding position where you have none. (...)
This seems to be behind his last paragraph, but I don't see the connection with the second paragraph.

I might have misinterpreted what he meant with "static evaluation", though. I understood this as referring to "the" static evaluation of a chess engine, but maybe he is thinking of a static detection of whether still having the right to castle is potentially useful. Even then I do not agree with his statement. It should be: even if there is just 0.001% change that P1 is better (or worse) than P2, they need different hash keys (but if you want to get 3-fold repetition right, this is still not enough). Maybe just a case of inaccurate formulation.
What I am saying is, all else being equal (equal piece placement) having the right to castle is always better or equal than not having this right. After all it is a right to do and no obligation. You can decide not to take advantage of it and will be at least equally good as in a position where you wouldn't have had the right to castle in the first place.

Now to the static evaluation part. Usually it takes a search or prior knowledge for an evaluation of a certain position. And now I am saying that in that particular case you can get an upper/lower bound statically (without doing any search) if you have certain information about the equal position where just the castling rights are changed.
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: ep and castle rights hashing

Post by Edmund »

hgm wrote:This would be an argument to not distinguish them by hash key. (But then you should have a flag in the hash table that tells you the castling rights for which the recorded score was calculated, so that you know how to make the correction.
Either that or to save the 4bit per hash entry just probe more than one hash key at nodes that are close to the root.
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: ep and castle rights hashing

Post by syzygy »

Edmund wrote:What I am saying is, all else being equal (equal piece placement) having the right to castle is always better or equal than not having this right. After all it is a right to do and no obligation. You can decide not to take advantage of it and will be at least equally good as in a position where you wouldn't have had the right to castle in the first place.
The exception being stalemate situations.
Now to the static evaluation part. Usually it takes a search or prior knowledge for an evaluation of a certain position. And now I am saying that in that particular case you can get an upper/lower bound statically (without doing any search) if you have certain information about the equal position where just the castling rights are changed.
But you were drawing a conclusion regarding the need or not to assign such positions different hash keys. This is what I am objecting to.

I agree that, outside stalemate situations, when searching a position that has castling rights or a position that has e.p. rights, the search could probe the hashtable for the identical position without castling or e.p. rights in order to look for a cut off. But this bears little connection with not having to assign different hash keys.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: ep and castle rights hashing

Post by Sven »

syzygy wrote:
Edmund wrote:What I am saying is, all else being equal (equal piece placement) having the right to castle is always better or equal than not having this right. After all it is a right to do and no obligation. You can decide not to take advantage of it and will be at least equally good as in a position where you wouldn't have had the right to castle in the first place.
The exception being stalemate situations.
Impossible IMO. In a position where castling is not available for the only reason that the king or rook was already moved, you can always move the rook since a rook in the corner can't be pinned and the squares between king and rook are empty. So this can never be stalemate.

A better example would be that castling is answered by checkmate on h2, or at least by a kingside attack. Indeed there are enough examples where the king is actually safer when kept in the middle.

Sven
User avatar
hgm
Posts: 27822
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: ep and castle rights hashing

Post by hgm »

syzygy wrote:The exception being stalemate situations.
Indeed, that was the first thing that occurred to me too. But on second thought I decided it could not happen. In a position where castling is legal, you will always have a legal normal King move, to the square that you would otherwise skip.

This is not true inChess960, though.

[d]4k3/8/8/8/8/6p1/3q2P1/5KRB w
With castling rights: loss, without them: draw

In Shogi having an extra Pawn (or whatever) in the hand (and the opponent one less) is always better. Stalemate is a win in Shogi.
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: ep and castle rights hashing

Post by syzygy »

Sven Schüle wrote:
syzygy wrote:
Edmund wrote:What I am saying is, all else being equal (equal piece placement) having the right to castle is always better or equal than not having this right. After all it is a right to do and no obligation. You can decide not to take advantage of it and will be at least equally good as in a position where you wouldn't have had the right to castle in the first place.
The exception being stalemate situations.
Impossible IMO. In a position where castling is not available for the only reason that the king or rook was already moved, you can always move the rook since a rook in the corner can't be pinned and the squares between king and rook are empty. So this can never be stalemate.
If think you are correct. It is different with having e.p. rights, which can really be a disadvantage.
A better example would be that castling is answered by checkmate on h2, or at least by a kingside attack. Indeed there are enough examples where the king is actually safer when kept in the middle.
This is not an example where having castling rights is a disadvantage, because you are never forced to castle. As you have pointed out, in a position where castling is legal, castling is never the only legal move available.

But how about this one:
[D]8/2q5/8/5p1p/1q2pPpP/3kPpP1/3P1PN1/4BKRN w K -
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: ep and castle rights hashing

Post by syzygy »

hgm wrote:This is not true inChess960, though.

[d]4k3/8/8/8/8/6p1/3q2P1/5KRB w
With castling rights: loss, without them: draw
Ha, this one is a bit simpler than what I came up with :-). And I think mine is unreachable...
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: ep and castle rights hashing

Post by syzygy »

Slightly simpler still:
[D]8/8/8/8/8/6k1/3q2P1/5KRB w K -