Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: can someone help with some simple code for egtb probe from fen?

Author: Anthony Cozzie

Date: 04:45:33 09/27/03

Go up one level in this thread


On September 27, 2003 at 05:15:16, scott farrell wrote:

>I am struggling with reading/understanding the nalimov code, and crafty's probe
>code, and other engines use of egtb (ie. parrot).
>
>My chompster is java, so I am good at java, and not-so-good at C,C++.
>
>Maybe someone has a simple c/c++ program, where I can call a function, just
>passing a FEN string, and get back a nice simple score and move. I am hoping
>someone already has something like this lying around.
>
>I intend to use JNI in java, so I can call the method directly. Currently,
>chompster uses egtb via the lokusoft webservice, and this takes about 0.8
>seconds/probe.
>
>I can compile under linux (gcc etc).
>
>I guess I need the c object (or whatever) to stay resident so the cache is
>effective (I'll just keep a nice global handle to it).
>
>Any help appreciated.
>Scott

It took me several days to figure out nalimov's code, and I'm a c programmer, so
I understand your issues ;)  In a nutshell: Nalimov wanted to make it so that
any programmer could access his TBs regardless of datastructure, so he asks you
to define a datastructure and some macros (java equiv: he gives you a class with
virtual methods that he asks you to build).  Heh its taking me a while to figure
out what Zappa is doing ;)

OK, it works like this in Zappa:
tbv = L_TbtProbeTable(iTb, side, PfnIndCalcFun(iTb, side) (strong, weak,
g->p.ep_square != 0 ? g->p.ep_square : XX, inv));

Lets break this down:

iTb is calculated earlier: it says whether or not we have a TB hit (this is
simple: count all pieces, and ask the TB code: do you have 5R + K  v 2P + K).
Side is "who is to move".

PfnIndCalcFun takes these two and returns a function pointer of type INDEX.
This pointer is code that will compute where to go in the file given your data.
Here is where it gets interesting:

typedef INDEX (TB_FASTCALL * PfnCalcIndex)
    (squaret*, squaret*, squaret, int fInverse);

So it returns a function that takes an array of squaret, another array of
squaret, En Passant Square, and invert result (strong side == white?).  Squaret
is where you work your magic.  You get to define this type, and he accesses it
through macros.

#define  SqFindKing(psq)        (psq[6])
#define  SqFindOne(psq, pi)     (psq[pi] & 63)
#define  SqFindFirst(psq, pi)   (psq[pi] & 63)
#define  SqFindSecond(psq, pi) ((psq[pi] >> 6) & 63)
#define  SqFindThird(psq, pi)  ((psq[pi] >> 12) & 63)

In Zappa I just use an int, and the first piece location is bits 0-6, 2nd is
7-12, etc.  So if I have BK@H8, WK@A1, WP@A2, they look like this:

strong = white = {0, A1, 0, 0, 0, 0, A2}
weak = black = {0, 0, 0, 0, 0, 0, H8}

If you really want to get it fast, then you should build this stuff in your java
and then call the TB functions more directly, not build a fen.  Of course,
nothing about TBs is fast anyway ;)  Hope this helps.

anthony



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.