Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: EGTB question to Martin Fierz

Author: Alvaro Jose Povoa Cardoso

Date: 00:14:23 05/03/02

Go up one level in this thread


On May 02, 2002 at 21:11:16, martin fierz wrote:

>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

With kings it works 100%
If I add men (checkers) (even if it is only one) it doesn't work anymore.
indextoposition() gives the very same position to any valid index.
positiontoindex() gives the maximum index in some configurations and in others
it gives the same index during n consecutive positions, then it gives another
index for another n positions, and so on

:(

Below I post the actual code in PowerBasic

Best regards,
Alvaro Cardoso





FUNCTION positiontoindex(BYREF p AS position) AS QUAD
    DIM index AS QUAD
DIM tmp AS DWORD

    '// computes an index for a given position

    DIM Nbm AS LONG, Nbk AS LONG, Nwm AS LONG, Nwk AS LONG

    DIM square_one AS DWORD : square_one=1


    DIM i AS LONG
    DIM x AS DWORD, y AS DWORD

    DIM bmindex AS DWORD, bkindex AS DWORD, wmindex AS DWORD, wkindex AS DWORD
    DIM bmrange AS DWORD, wmrange AS DWORD, bkrange AS DWORD

    bmindex=0 : bkindex=0 : wmindex=0 : wkindex=0
    bmrange=1 : wmrange=1 : bkrange=1



    ' set Nbm, Nbk, Nwm, Nwk, and ranks
    Nbm = BitCount((p.bm))
    Nbk = BitCount((p.bk))
    Nwm = BitCount((p.wm))
    Nwk = BitCount((p.wk))

    ' first, we set the index for the black men:
    i=1 : y=p.bm
    WHILE y
        x=FirstBit(y)
        BIT RESET y,x
        bmindex = bmindex + bicoef_array(x,i)
        INCR i
    WEND

    ' next, we set it for the white men, disregarding black men:
    i=1 : y=p.wm
    WHILE y
        x=LastBit(y)
        BIT RESET y,x
        x=31-x
        wmindex = wmindex + bicoef_array(x,i)
        INCR i
    WEND

    ' then, black kings. this time, we include interfering black and white men.
    i=1 : y=p.bk
    WHILE y
        x=FirstBit(y)
        BIT RESET y,x
        ' next line is the count of men on squares 0....x-1, as x-1 of a
0000010000000 number is 0000000111111111
          tmp = square_one : SHIFT LEFT tmp,x
        x = x - BitCount( (p.bm OR p.wm) AND (tmp-1) )
        bkindex = bkindex + bicoef_array(x,i)
        INCR i
    WEND

    ' last, white kings, with interfering other pieces
    i=1 : y=p.wk
    WHILE y
        x=FirstBit(y)
        BIT RESET y,x
          tmp = square_one : SHIFT LEFT tmp,x
        x = x - BitCount((p.bm OR p.bk OR p.wm) AND (tmp-1) )
        wkindex = wkindex + bicoef_array(x,i)
        INCR i
    WEND

    IF Nbm THEN bmrange = bicoef_array(28,Nbm)
    IF Nwm THEN wmrange = bicoef_array(28,Nwm)
    IF Nbk THEN bkrange = bicoef_array(32-Nbm-Nwm,Nbk)


    index = bmindex + wmindex*bmrange + bkindex*bmrange*wmrange +
wkindex*bmrange*wmrange*bkrange

    FUNCTION = index
END FUNCTION








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.