Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: quick bitboard question

Author: Tony Werten

Date: 23:04:24 08/26/05

Go up one level in this thread


On August 27, 2005 at 01:00:08, Tony Werten wrote:

>On August 26, 2005 at 15:04:55, Robert Hyatt wrote:
>
>>I'm fixing to change the way I number bits to make bit 0 the LSB (as the BSF/BSR
>>instructions count on the X86) rather than the MSB as the leading zero
>>instruction counts on the Cray-1 architecture.
>>
>>I have four choices for which square bit 0 represents (four logical choices,
>>anyway, I guess one could number bits randomly should they choose).
>>
>>A1 = 0
>>H1 = 0
>>A8 = 0
>>H8 = 0
>>
>>For those of you using bitboards, which did you use?  Since it doesn't matter to
>>me at all, since I am having to rewrite a bunch of stuff to make this work, I
>>thought I would try to match the most common layout which will make the programs
>>more compatible if we share any ideas.
>>
>>I am leaning toward H1 = 0, H2 = 8, ..., H8 = 56 and A8 = 63, but I've not made
>>any decision yet...  The reason for this is that it is easier to visualize if
>>you think of the chess board as being composed of the 1 rank and the rightmost 8
>>bits of the bitboard, the 2nd rank is the next 8 bits, etc.
>>
>>The alternative is H8=0, etc, so that the last rank is the rightmost bits, the
>>seventh rank is the next 8 bits, etc.  Anything else requires "mentally
>>mirroring" so that if A1 or A8 is bit zero, the bits are backward, since A8 is
>>the left end of a rank, and bit 0 is the right end of a set of 8 bits...
>
>I use A1=0,H1=7,H8=63.
>
>Same for pawnbytes. A pawn on the A file will the 0 bit set. It seemed logical
>from programming point of view. You just have to get used to it.
>
>I did however make a function ShowBB() wich shows the bitboard in a chessboard
>view, for checking bitboard patterns.
>
>BTW since you start changing anyway, you might want to reconsider your
>diagonally rotated bitboards. Making them 8 times 8 bits each by lining up
>A1-H8,A2-G8+H1,A3-F8+G1-H2  etc makes them a lot easier to visualize.

Let me clarify before I leave for my vacation.

The idea is to reduce the memory needed for bb by a factor of 8, at the cost of
an extra shift.

For rooks it's easy. Pretend your on the 1st rank, get the state for the correct
rank, get the bb for the first rank and shift it up. Same for rotated90. So you
only need 1 rank rather than 8.

For bishops this doesn't work with the usual bb, but changing them so you can
pretend A1-H8 is the main line solves this.

fe My bishop is on B4. I pretend the line A3-F8 is actually A1-H8. The resulting
BB will include G7 and H8 bits, but by shifting it 2 ranks up (to get back to
A3-F8) the 2 bits will automaticly fall into the bitbin. Had the bishop been on
G1 or H2, I would have shifted down 6 ranks, and the other 6 bits would
disappeared.

Tony

>
>In addition it gives the possibility to get "ranks" by charptr[rank] rather than
>a shift. Well, at least that's nice for my program, I swap a lot between bb and
>0x88
>
>Tony



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.