I never use non-trivial indexing (as if accessing a multidimensional array indexed by the square numbers). Indexes outside the canonical symmetry sector are mapped into it by manipulation of the index, however, to exploit symmetry. For 8x8 boards this easy (e.g. XORing with 070707070).mar wrote:Do you do this automatically (as I suspect) or manually for each piece configuration?
KPK
Moderator: Ras
-
- Posts: 28354
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: KPK
-
- Posts: 373
- Joined: Wed Mar 22, 2006 10:17 am
- Location: Novi Sad, Serbia
- Full name: Karlo Balla
Re: KPK
Probably.BubbaTough wrote:Just out of curiosity, are there any where you need to know about under promotion to judge them accurately, or are they all positions where not knowing about under promotion just causes you to mate a few moves later (like this one)?Sven Schüle wrote:Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:hgm wrote:I suppose you do test for stalemate after the promotion, not just for recapture of the Queen. Having a Queen and the move is always a win.mar wrote:Safe promotions to queen are considered a win,
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1
Sven
-Sam
[d]8/k1P5/8/K7/8/8/8/8 w - - 0 1
Best Regards,
Karlo Balla Jr.
Karlo Balla Jr.
-
- Posts: 2656
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: KPK
I see, so you mirror horizontally, vertically or both.hgm wrote:I never use non-trivial indexing (as if accessing a multidimensional array indexed by the square numbers). Indexes outside the canonical symmetry sector are mapped into it by manipulation of the index, however, to exploit symmetry. For 8x8 boards this easy (e.g. XORing with 070707070).
I thought that in pawnless positions (8x8 boards), one could try 90-degrees rotations as well (I hope it's not nonsense).
-
- Posts: 28354
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: KPK
Yes, diagonal mirroring is slightly more expensive:
address = index>>3 & 0707070707 | index<<3 & 0x7070707070
If the board is not 8x8 it is not so straightforward, and the only generator I have for arbitrary boards does not use symmetry at all. It should be possible, however, by keeping the contribution of file and rank coords to the index separately. E.g. on a 10x10 board you could do
indexh = file1 + 100* file2 + 10000*file3 ...
indexv = rank1 + 100*rank2 + 10000*rank3 ...
index = indexh + 10*indexv
Then you can use 90909 - indexh for left-right flip, and 90909 - indexv for top-bottom flip. And index = 10*indexh + indexv for a diagonal reflection. indexh and indexv can then be each updated incrementally in the scanning and moving routines. On non-square boards there is no diagonal symmetry, and you could directly update 10*indexv incrementally.
address = index>>3 & 0707070707 | index<<3 & 0x7070707070
If the board is not 8x8 it is not so straightforward, and the only generator I have for arbitrary boards does not use symmetry at all. It should be possible, however, by keeping the contribution of file and rank coords to the index separately. E.g. on a 10x10 board you could do
indexh = file1 + 100* file2 + 10000*file3 ...
indexv = rank1 + 100*rank2 + 10000*rank3 ...
index = indexh + 10*indexv
Then you can use 90909 - indexh for left-right flip, and 90909 - indexv for top-bottom flip. And index = 10*indexh + indexv for a diagonal reflection. indexh and indexv can then be each updated incrementally in the scanning and moving routines. On non-square boards there is no diagonal symmetry, and you could directly update 10*indexv incrementally.
-
- Posts: 1154
- Joined: Fri Jun 23, 2006 5:18 am
Re: KPK
Nice, I like itKarlo Bala wrote:Probably.BubbaTough wrote:Just out of curiosity, are there any where you need to know about under promotion to judge them accurately, or are they all positions where not knowing about under promotion just causes you to mate a few moves later (like this one)?Sven Schüle wrote:Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:hgm wrote:I suppose you do test for stalemate after the promotion, not just for recapture of the Queen. Having a Queen and the move is always a win.mar wrote:Safe promotions to queen are considered a win,
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1
Sven
-Sam
[d]8/k1P5/8/K7/8/8/8/8 w - - 0 1

-Sam
-
- Posts: 2656
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: KPK
I see, clever, so only one diagonal mirroring (or transposition) will do.hgm wrote:Yes, diagonal mirroring is slightly more expensive:
address = index>>3 & 0707070707 | index<<3 & 0x7070707070
If the board is not 8x8 it is not so straightforward, and the only generator I have for arbitrary boards does not use symmetry at all. It should be possible, however, by keeping the contribution of file and rank coords to the index separately. E.g. on a 10x10 board you could do
indexh = file1 + 100* file2 + 10000*file3 ...
indexv = rank1 + 100*rank2 + 10000*rank3 ...
index = indexh + 10*indexv
Then you can use 90909 - indexh for left-right flip, and 90909 - indexv for top-bottom flip. And index = 10*indexh + indexv for a diagonal reflection. indexh and indexv can then be each updated incrementally in the scanning and moving routines. On non-square boards there is no diagonal symmetry, and you could directly update 10*indexv incrementally.
So the rotations then become HD, HV and VD.
-
- Posts: 3241
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: KPK
Good spot.Sven Schüle wrote:Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:hgm wrote:I suppose you do test for stalemate after the promotion, not just for recapture of the Queen. Having a Queen and the move is always a win.mar wrote:Safe promotions to queen are considered a win,
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1
Sven
But that is not a problem. In practice the KPK bitbase only tells you if it's a draw or not (1 bit per position). It doesn't tell you that you should do a queen promotion. So it's not a problem.
I don't think there are positions where white can promote (w/o being captured) and it's draw regardless of the promotion piece he chooses (or even if he chooses a king move instead).
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
- Posts: 28354
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: KPK
[d]8/1P6/8/8/8/K7/8/k7 wlucasart wrote:I don't think there are positions where white can promote (w/o being captured) and it's draw regardless of the promotion piece he chooses (or even if he chooses a king move instead).
But it is won after a King move, so still no problem.
-
- Posts: 3241
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: KPK
Nice one! Anyway, the Stockfish code is correct to assume that in all cases where white can promote (w/o losing the pawn) it's a win. KPK bitbases don't tell what move you should play to win (but that's trivial for the search to find), they just tell you if it's draw or not. So unless we can find a position where white can promote and it's still a draw, regardless of what white plays, then we're fine with the plain and simple promotion condition.hgm wrote:[d]8/1P6/8/8/8/K7/8/k7 wlucasart wrote:I don't think there are positions where white can promote (w/o being captured) and it's draw regardless of the promotion piece he chooses (or even if he chooses a king move instead).
But it is won after a King move, so still no problem.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: KPK
My point was different. The bitbase generation algorithm "check whether queening creates stalemate; if so => draw, otherwise => won" would misevaluate the position above (provided there is no king move creating a known win), and some similar ones. Of course a full EGTB generation would not suffer from that problem since it would be based on already generated KQK, KRK databases. But as I understood the "short cut" way of generating the KPK bitbase should include to statically evaluate those positions where promotion is possible, and I only wanted to point out that doing this correctly would require more than just checking queen promotions and a possible stalemate.lucasart wrote:Good spot.Sven Schüle wrote:Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:hgm wrote:I suppose you do test for stalemate after the promotion, not just for recapture of the Queen. Having a Queen and the move is always a win.mar wrote:Safe promotions to queen are considered a win,
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1
Sven
But that is not a problem. In practice the KPK bitbase only tells you if it's a draw or not (1 bit per position). It doesn't tell you that you should do a queen promotion. So it's not a problem.
I don't think there are positions where white can promote (w/o being captured) and it's draw regardless of the promotion piece he chooses (or even if he chooses a king move instead).
Sven