KPK

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Rebel
Posts: 7296
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

KPK

Post by Rebel »

In eval I have coded the KPK ending. Now I read on the CPW of a 12Kb bitbase file that has all the positions pre-calculated. It does not offer a download. Where can I get it? Would like to throw out my code and replace it with a table look-up.
lucasart
Posts: 3241
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: KPK

Post by lucasart »

Rebel wrote:In eval I have coded the KPK ending. Now I read on the CPW of a 12Kb bitbase file that has all the positions pre-calculated. It does not offer a download. Where can I get it? Would like to throw out my code and replace it with a table look-up.
Stockfish computes the KPK bitbase on the fly, when the program starts:
https://github.com/mcostalba/Stockfish/ ... itbase.cpp

If your engine is GPL, you can simply copy/paste this code (adapting it of course). That's what I did in DiscoCheck, because I really couldn't be bothered to reinvent the KPK wheel.

If not, you can make a trivial modification to Stockfish, and make it spit out the bitbase into a file. Then if you just use that file, and no source code from SF, I guess that's ok GPL-wise ?
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
hgm
Posts: 28331
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: KPK

Post by hgm »

As you are probably not GPL, and already have a fully original version of the necessary eval code, you can just make a triply-nested loop that scans over all KPK positions and applies your eval to it to decide if the corresponding bit should be set or cleared, and run it at startup to create the table and write it to file, if you could not read it from file.
User avatar
Rebel
Posts: 7296
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: KPK

Post by Rebel »

Yes I know, but I am a lazy programmer :wink:
mar
Posts: 2646
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: KPK

Post by mar »

Well, I too calculated the table. A very simple retrograde analysis. I didn't even bother with better indexing - simply used 64*64*48*2 indices, a 48k table.
It was actually pretty fun and creative - in the middle of elo hunting.
What is good that you only need to store one bit for kpk (draw bit).
Safe promotions to queen are considered a win, stalemate or pawn captures are considered draws, invalid positions ignored.
What bothered me however was that there were some "unsolved" positions when the iteration was finished.
I marked them as draws assuming they would result from draw by repetition.
I'm not sure whether that assumption holds however.
But it worked very well for me.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: KPK

Post by bob »

Rebel wrote:In eval I have coded the KPK ending. Now I read on the CPW of a 12Kb bitbase file that has all the positions pre-calculated. It does not offer a download. Where can I get it? Would like to throw out my code and replace it with a table look-up.
This is included in several engines. I can't quote which ones, but on my cluster, I use Fruit, Toga, Arasan, glaurung and stockfish regularly, and at least one of those includes the KPK bit base.

Personally, I think the rules for this are easy enough to code...
User avatar
hgm
Posts: 28331
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: KPK

Post by hgm »

mar wrote:Safe promotions to queen are considered a win,
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.
What bothered me however was that there were some "unsolved" positions when the iteration was finished.
That is normal in EGTB generation. Everything that remains after you found all the wins must be draws.
mar
Posts: 2646
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: KPK

Post by mar »

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.
Yes I did. I also checked whether rook underpromotion is safe (no stalemate), in case queen promotion would be stalemate.
Not sure if this is necessary but I didn't want to miss a single special case.
hgm wrote:
What bothered me however was that there were some "unsolved" positions when the iteration was finished.
That is normal in EGTB generation. Everything that remains after you found all the wins must be draws.
Thanks for clarifying this to me, I always wondered whether it's safe to assume the rest is draw.
For KPK one hasn't to worry about en passant, castling rights or index compression/mirroring.
I always wondered however how to calculate proper minimum index set for EGTBs.
Do you do this automatically (as I suspect) or manually for each piece configuration?
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: KPK

Post by Sven »

hgm wrote:
mar wrote:Safe promotions to queen are considered a win,
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.
Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1

Sven
BubbaTough
Posts: 1154
Joined: Fri Jun 23, 2006 5:18 am

Re: KPK

Post by BubbaTough »

Sven Schüle wrote:
hgm wrote:
mar wrote:Safe promotions to queen are considered a win,
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.
Note that there are also few KPK positions where queening draws due to stalemate but underpromoting to a rook wins, e.g.:
[d]8/k1P5/2K5/8/8/8/8/8 w - - 0 1

Sven
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)?

-Sam