Author: Tony Werten
Date: 14:14:54 03/03/06
Go up one level in this thread
On March 03, 2006 at 15:58:21, Steffan Westcott wrote:
>Gerd,
>
>I may have terribly misunderstood things, but there is direct algorithm for
>mapping the 128 possible attack bitboards to 7 bit numbers. Additionally, the
>algorithm does not need the location of the ray source square, nor any lookup
>tables.
>
>For a ray along a rank or diagonal, it is sufficient to collapse the files:
>
>typedef unsigned __int64 BitBoard;
>
>int collapsed_files_index(BitBoard b)
>{
> b |= b >> 32;
> b |= b >> 16;
> b |= b >> 8;
> return b & 0xFF;
>}
>
>For a ray along a file, a little more trickery is needed:
>
>int collapsed_ranks_index(BitBoard b)
>{
> b |= b >> 4; // No masking needed
> b |= b >> 2; // " "
> b |= b >> 1; // " "
> return ((b & 0x0101010101010101) * 0x0102040810204080) >> 56;
>}
>
>Both of the above routines return 8 bit results. Depending on the left/right
>orientation of the ray in relation to your chosen bitboard bit numbering scheme,
>you may need to shift the result right by 1 bit.
>
>In addition, if you know the co-ordinates of the source square (either at
>runtime or compile time), simpler variants of the above routines are possible.
>
>I don't use techniques like these as I avoid serialisation of moves or features
>as much as possible. However, I offer you and Dann the above as it may be of
>interest.
Hi Steffan,
although the algoritm looks simpler (allthough I'm not sure I understand) , (BB
& mask)*magic_number will give a better performance.
Tony
>
>
>Cheers,
>Steffan
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.