Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question for Gerd: reduce rbb lookup tables

Author: Tim Foden

Date: 13:03:10 07/15/03

Go up one level in this thread


On July 15, 2003 at 11:38:31, Russell Reagan wrote:

>On July 14, 2003 at 18:20:33, Tim Foden wrote:
>
>>inline int  Rank( Sq sq )                   { return sq >> 3; }
>>inline int  File( Sq sq )                   { return sq & 0x7; }
>>
>>inline BYTE     PatMoves( int rf, int pat )
>>                                    { return CStatics::s_patMoves[rf][pat]; }
>>inline UINT64   ExtVert( int pat )  { return CStatics::s_extendVert[pat]; }
>>inline UINT64   ExtHorz( int pat )  { return CStatics::s_extendHorz[pat]; }
>>
>>inline UINT64   RankMask( int r )   { return CStatics::s_rankMask[r]; }
>>inline UINT64   FileMask( int f )   { return CStatics::s_fileMask[f]; }
>>
>>inline UINT64   CBoard::GenRAttacksBitmap( Sq sq ) const
>>{
>>    int     r = Rank(sq);
>>    int     f = File(sq);
>>    BYTE    movesR = PatMoves(f, m_rot[cHorz].bytes[r]);
>>    BYTE    movesF = PatMoves(r, m_rot[cVert].bytes[f]);
>>    UINT64  bitmap = (ExtVert(movesR) & RankMask(r)) |
>>                     (ExtHorz(movesF) & FileMask(f));
>>    return bitmap;
>>}
>
>Hi Tim,
>
>This is very cool. I had to sit here staring at the screen to figure out what
>you were doing at first, but soon light bulbs started going off, and I saw how
>neat, simple, and clean this is.
>
>One question though. How do you compute the diagonal attacks with such small
>tables (15 entries each!)?

Maybe this extra code will give you the clue you need.. :)

inline int  DiagA( int rank, int file ) { return 7 + rank - file; }
inline int  DiagA( Sq sq )              { return DiagA(Rank(sq), File(sq)); }
inline int  DiagH( int rank, int file ) { return rank + file; }
inline int  DiagH( Sq sq )              { return DiagH(Rank(sq), File(sq)); }

inline UINT64   DiagAMask( int a )  { return CStatics::s_diagAMask[a]; }
inline UINT64   DiagHMask( int h )  { return CStatics::s_diagHMask[h]; }

inline UINT64   CBoard::GenBAttacksBitmap( Sq sq ) const
{
    int     r = Rank(sq);
    int     f = File(sq);
    int     a = DiagA(r, f);
    int     h = DiagH(r, f);
    BYTE    movesA = PatMoves(f, m_rot[cDiagA].bytes[a & 7]);
    BYTE    movesH = PatMoves(f, m_rot[cDiagH].bytes[h & 7]);
    UINT64  bitmap = (ExtVert(movesA) & DiagAMask(a)) |
                     (ExtVert(movesH) & DiagHMask(h));
    return bitmap;
}

Maybe to help understand you'd need the order of bits in the rot[cDiagX]
tables...  I can't remember exactly how they pack into an 8 byte array, but this
will give you the idea.

Imagine a board, where we are interested in the diagonals parallel to the one
from A1.

01234567
12345678
23456789
3456789A
456789AB
56789ABC
6789ABCD
789ABCDE

These diagaonals get stored in 8 bytes something like this:

08888888
11999999
222AAAAA
3333BBBB
44444CCC
555555DD
6666666E
77777777

Cheers, Tim.



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.