Problems with kpk bitbase from DiscoCheck

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: Problems with kpk bitbase from DiscoCheck

Post by hgm »

True, but to his defense I can bring up that my code was very poorly documented, and did not even contain a probing routine. And the way it uses symmetry by leaving out all odd files might be non-obvious.

Let me also put the corresponding (untested) probing code in the public domain:

Code: Select all

int
KPK_is_won (int stm, int wK, int wP, int bK)
{
  int index = bK ^ 64*wK ^ 32*64*wP;
  index ^= -(wP & 1) & 034707; // flip horizontally if Pawn on odd file
  return bitbase&#91;2*&#40;index>>3&#41; + stm - 64*64&#93; & 1<<&#40;index & 7&#41;;
&#125;
User avatar
Bloodbane
Posts: 154
Joined: Thu Oct 03, 2013 4:17 pm

Re: Problems with kpk bitbase from DiscoCheck

Post by Bloodbane »

You can also modify both engines to print out the file and compare to find where they differ and debug based on that. This way you can keep the code elegant.
Functional programming combines the flexibility and power of abstract mathematics with the intuitive clarity of abstract mathematics.
https://github.com/mAarnos
User avatar
hgm
Posts: 27793
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Problems with kpk bitbase from DiscoCheck

Post by hgm »

But they might not use the same storage format. So comparison could be non-trivial. And you would have to ignore differences for broken and illegal positions. (Note that my code is not from any engine, but just a stand-alone code that does nothing but fill the array bitbase[], and then exit. So one could add a loop to print out this array in main().)

But it should be possible to test data and probing code together, by writing a small program that loops over all possible positions, and compares the probe results for the two formats.

Btw, Ippolit also contains a KPK bitbase, as an array of initialized data (and is public domain).

I now realize that the probing routine I gave above only works when white has the Pawn. A more general routine would take an extra parameter to indicate which side has the Pawn, so that it could be used for KPK as wll as KKP:

Code: Select all

int
KPK_is_won &#40;int stm, int wK, int bK, int wP, int pawnOwner&#41;
&#123;
  int index = bK ^ 64*wK ^ 32*64*wP;
  index ^= -&#40;wP & 1&#41; & 034707; // flip horizontally if Pawn on odd file
  index ^= -pawnOwner & 0347070;
  return bitbase&#91;2*&#40;index>>3&#41; + stm - 64*64&#93; & 1<<&#40;index & 7&#41;;
&#125; 
with the peculiarity that 'stm' would have to specify the 'relative' side to move, i.e. 0 = pawnOwner and 1 = bare King. (For pawnOwner it would be 0 = white, 1 = black, assuming that white plays 'up the board, i.e. square numbers 0-7 are the first rank, etc.')
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: Problems with kpk bitbase from DiscoCheck

Post by vittyvirus »

syzygy wrote:
tttony wrote:But I'm having problems again, I have to debug, debug and debug...
That's how people become good programmers.
+1