Computer Chess Club Archives




Subject: Re: Some thoughts on Dann Corbit's rotated alternative

Author: Steffan Westcott

Date: 12:58:21 03/03/06

Go up one level in this thread


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

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


This page took 0.06 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

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