Problems with kpk bitbase from DiscoCheck

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Problems with kpk bitbase from DiscoCheck

Post by tttony »

I've ported the kpk.cc from DiscoCheck to my engine in C99, but I'm running with a problem, the function:

Code: Select all

int encode(int wk, int bk, int stm, int wp);
returns a signed int: -2256895, the debugger return a Segmentation fault, I compile with: TDM-GCC 4.8.1 64-bit Debug using Dev-C++ 5.6.2

Here is the code: http://hastebin.com/akuhokococ.m, see the lines: 109 and 110

What could be the problem? My head cant think right now...

Thanks
flok

Re: Problems with kpk bitbase from DiscoCheck

Post by flok »

Have you tried:

- valgrind
to check for any memory corruption

- helgrind (yes)
to check for concurrency issues

- make clean && make
in case dependency tracking is not correctly configured and some structure (or whatever) has changed size
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Problems with kpk bitbase from DiscoCheck

Post by tttony »

I'm on Windows, I've heard of valgrind but it does not support windows

Any other alternatives?

Can't use Visual Studio because it does not support C99, with Dev-C++ for debug is fine, in fact it has a CPU window that show where it was the error but in assembler and I'm not good in assembler

I will try to run it in ubuntu VM...

Thanks Folkert !!
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Problems with kpk bitbase from DiscoCheck

Post by tttony »

Well I found the problem, it was the rank() and file() functions, the engine that I'm modifying is derived from Vice and it uses an 120 array board, I had to convert it to 64 square

Now I have another problem... the kpk_ok() funtion returns:

illegal = 29360 and it must return: 30932
win = 155244 and it must return: 111282

Even I copied the kdist() function from DiscoCheck source, but the problem is still there, now I have to check the bitboards attacks from king and pawns

Hope that the problem is in the attacks bitboard
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Problems with kpk bitbase from DiscoCheck

Post by Ron Murawski »

tttony wrote:I'm on Windows, I've heard of valgrind but it does not support windows

Any other alternatives?
You can try Dr. Memory
https://code.google.com/p/drmemory/

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

Re: Problems with kpk bitbase from DiscoCheck

Post by syzygy »

tttony wrote:I've ported the kpk.cc from DiscoCheck to my engine in C99, but I'm running with a problem, the function:

Code: Select all

int encode(int wk, int bk, int stm, int wp);
returns a signed int: -2256895, the debugger return a Segmentation fault, I compile with: TDM-GCC 4.8.1 64-bit Debug using Dev-C++ 5.6.2

Here is the code: http://hastebin.com/akuhokococ.m, see the lines: 109 and 110

What could be the problem? My head cant think right now...
If you don't see it, a little debugging should help. Finding out for which argument values lead to the erroneous negative value would be the first step. This is easy even without a debugger: just add some checks.
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Problems with kpk bitbase from DiscoCheck

Post by tttony »

The debug helped me alot finding the problem, as I said it was the RANK() function, but after the solution, the kpk_ok() function does not returns the correct illegals and wins positions and I just give up trying this, I have not changed anything in the code, just replacing some functions with my functions

Now I'm testing the kpk bitbase from H.G.Muller here --> http://www.talkchess.com/forum/viewtopi ... at&start=0

But I'm having problems again, I have to debug, debug and debug...

I think I just want the things just works without errors and fast as possible, sometimes I don't have patience, and for that I have not released the engine
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problems with kpk bitbase from DiscoCheck

Post by lucasart »

tttony wrote:The debug helped me alot finding the problem, as I said it was the RANK() function, but after the solution, the kpk_ok() function does not returns the correct illegals and wins positions and I just give up trying this, I have not changed anything in the code, just replacing some functions with my functions

Now I'm testing the kpk bitbase from H.G.Muller here --> http://www.talkchess.com/forum/viewtopi ... at&start=0

But I'm having problems again, I have to debug, debug and debug...

I think I just want the things just works without errors and fast as possible, sometimes I don't have patience, and for that I have not released the engine
Why don't you just:
  • modify DiscoCheck to make it spit out the KPK bitbase in a file
  • Load the file at the startup of your engine
Generating the KPK bitbase on the fly is just more elegant. But it is not necessary if you're looking for the minimum effort solution.

If you're interested in portability, beware of Little Endian vs. Big Endian...

PS: The binary file with the KPK bitbase is not copyrightable material, so you can use it however you want (even in a commercial and closed source engine). It's the code of DiscoCheck that is GPL, and would force you to release your entire source code under GPL (if you ever do release).
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
hgm
Posts: 27790
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 »

Of course people that do not want any strings attached can simply use the public-domain code for KPK generation.

http://www.talkchess.com/forum/viewtopi ... 71&t=47557
syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: Problems with kpk bitbase from DiscoCheck

Post by syzygy »

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