Author: martin fierz
Date: 18:11:16 05/02/02
Go up one level in this thread
On May 02, 2002 at 16:28:16, Alvaro Jose Povoa Cardoso wrote:
>Hi Martin,
>I'm sorry to bother you again, but I spoke too soon yesterday.
>My positiontoindex() function only works correctly with kings. The minute I add
>checkers it breaks. Could you please check if the following code is correct?
>(Please notice that I'm not using the rank of the leading checker for further
>database subdivision).
>I hope you don't mind me posting your code here, if you do please tell me.
>
hi alvaro,
the code looks correct to me on the first glance. what do you mean with "it
breaks"?
aloha
martin
>Thanks in advance,
>Alvaro Cardoso
>
>
>
>void positiontoindex(position *p, int32 *index)
> {
> //
> // computes an index for a given position
> //
> int bm, bk, wm, wk;
>
>
> int i;
> int32 x,y;
> int32 bmindex=0,bkindex=0,wmindex=0,wkindex=0;
> int32 bmrange=1, wmrange=1, bkrange=1;
> int32 posindex=0;
>
>
> // set bm, bk, wm, wk, and ranks
> bm = bitcount(p->bm);
> bk = bitcount(p->bk);
> wm = bitcount(p->wm);
> wk = bitcount(p->wk);
>
> // first, we set the index for the black men:
> i=1;
> y=p->bm;
> while(y)
> {
> x=LSB(y);
> y=y^(1<<x);
> bmindex+=bicoef[x][i];
> i++;
> }
>
> // next, we set it for the white men, disregarding black men:
> i=1;
> y=p->wm;
> while(y)
> {
> x=MSB(y);
> y=y^(1<<x);
> x=31-x;
> wmindex+=bicoef[x][i];
> i++;
> }
>
> // then, black kings. this time, we include interfering black and white men.
> i=1;
> y=p->bk;
> while(y)
> {
> x=LSB(y);
> y=y^(1<<x);
> // next line is the count of men on squares 0....x-1, as x-1 of a
>0000010000000 number is 0000000111111111
> x-=bitcount((p->bm|p->wm)&((1<<x)-1));
> bkindex+=bicoef[x][i];
> i++;
> }
>
> // last, white kings, with interfering other pieces
> i=1;
> y=p->wk;
> while(y)
> {
> x=LSB(y);
> y^=(1<<x);
> x-=bitcount((p->bm|p->bk|p->wm) & ( (1<<x)-1 ) );
> wkindex+=bicoef[x][i];
> i++;
> }
>
> if(bm)
> bmrange = bicoef[28][bm];
> if(wm)
> wmrange = bicoef[28][wm];
> if(bk)
> bkrange = bicoef[32-bm-wm][bk];
>
>
> posindex = bmindex + wmindex*bmrange + bkindex*bmrange*wmrange +
>wkindex*bmrange*wmrange*bkrange;
>
>
> *index = posindex;
> }
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.