Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Reversed vs. Rotated Bitboards

Author: Sune Fischer

Date: 01:47:53 01/30/02

Go up one level in this thread


On January 29, 2002 at 19:21:19, Vincent Diepeveen wrote:

>On January 28, 2002 at 16:48:53, Gerd Isenberg wrote:
>
>>On January 28, 2002 at 15:23:09, Gerd Isenberg wrote:
>
>it is both working of course, but the question for me
>is 'how do i get the stuff out of the bitboard' cheaper?
>
>In DIEP 2.0 without bitboards i need less clocks than all the
>clocks needed for reversed/rotated.
>
>The problem below is that the code looks nice to get
>the attackers, but that you need loads of arrays and extra
>instructions to get just the squares, also
>an inversed array for each piece, to generate the rook moves
>the other side.

That I don't understand, what arrays are needed?
The square transformation to and from reversed is: 63-square, no table.

You're right that reading the bits off the bitboard is exspensive,
but in some cases I'm sure it will be cheaper, like when generate king moves you
simply mask out all the bits the opponent attacks.
And you need not check all the time that you are still on the board, because the
moves generated will always be on the board, obviously.
And in the beginning of the game when the rook is still on a1 with frindly
pieces all around, the "move" board will be empty and you see instantly there
are no moves for the rook, there's no need to even call FirstBit(). In those
special cases i think nothing compares to the speed of bitboards.

>If my rook is on e4, with the below trick (note i thought you
>should first do occupiedRANK1 and only after that you
>can do occupied>>square) you can get a bitmap with the
>attacked squares from f4 to h4 and from e5 to e8.

Forget that algorithm, it was an untestet draft, the principle works though, it
is even possible to shave a few operations off.

>Now the problem is i need to first 'convert' the square
>to an inverse or whatever and then use that to get on the rest
>of the bitmap and then convert every square of that back to
>normal square numbers again.

Again, this is just 63-square, what is the big deal?

>This where in DIEP i directly have the squares already to do all
>kind of cool stuff with it, with both rotated and/or reversed do
>need to do all kind of stuff to just get a bitmap with the squares,
>then again you need the nowadays bit faster but still dead slow
>functions to get a bit out of the bitboards.
>
>Only when BSF works on a 64 bits register and when bsf can be
>executed with several instructions at the same time, then it gets
>more interesting to again look again at adding a pawn board for me in
>DIEP:

That is true.

>bitboard pawns[2]; /* indexed on color of course it's
>                    * stupid to write all code twice.
>                    */
>
>>>BITBOARD RookAttacksForward(BOARD &occupied, char square)
>>>{
>>>	BITBOARD a,x,y;
>>>
>>>	x=occupied>>square;  // shift board so square ends in lower left corner
>>>	y=x&RANK1;           // mask out ewerything but the first rank
>>>	a=y^(y-2);           // get the attacked bits on this rank
>>>	y=x&FILE1;           // now mask so we get a clean first file
>>>	y=y^(y-2);           // get the attacked squares
>>>	a=a|(y&FILE1);       // add the attacked bits after masking with the file again
>>>	a=a<<square;        // shift the attacked bits back (for ease of readability)
>>>
>>>	return a;
>>>}
>>>
>>>Thanks, very interesting. I can imagine, that this is faster than a table lookup
>>>with the risc of cache miss, specially when you do it with assembler with mmx
>>>registers (or waiting for hammer and 64bit compiler). Impressed about the
>>>y^(y-2) operation, to get the attacked squares. I have to study it a while.
>>>
>>>Gerd
>>
>>OK, i understood. Nice for rooks on a1. The RookAttacksBackward(BOARD &occupied,
>>char square) using the Reversed BitBoard is also "Reversed", and than the
>>Bishops... You have to use Foreward and Reverse BitBoards for all Sliders or you
>>have to reverse the "Reverse" Bitboard before oring them together.
>>
>>I use rotated, but i reduce the occupied state to 6Bits, ignoring the outer
>>ones. Some lines of code:
>>
>>BitBoard sRankAtta[64][64];	// [square][six inner square state]
>>BitBoard sFileAtta[64][64];	// [square][six inner square state]
>>BitBoard sA1H8Atta[64][64];	// [square][six inner square state]
>>BitBoard sH1A8Atta[64][64];	// [square][six inner square state]
>>
>>__forceinline unsigned int Square(unsigned int file, unsigned int rank)
>> {return (rank<<3) | file;}
>>__forceinline unsigned int Rank  (unsigned int sq)
>> {return sq >> 3;}
>>__forceinline unsigned int File	(unsigned int sq)
>> {return sq & 7;}
>>
>>
>>__forceinline BitBoard FileAttacks(unsigned int sq) const
>>{
>> return sFileAtta[sq][(*(((BYTE*)&(m_Inc.m_OccuBB90))+File(sq))
>>   >> 1) & 0x3f];
>>}
>>__forceinline BitBoard RankAttacks(unsigned int sq) const
>>{
>> return sRankAtta[sq][(*(((BYTE*)&(m_Inc.m_PieceBB[ALLPIECES]))+Rank(sq))
>>   >> 1) & 0x3f];
>>}
>>
>>__forceinline BitBoard A1H8Attacks(unsigned int sq) const
>>{
>> return sA1H8Atta[sq][(*(((BYTE*)&(m_Inc.m_OccuBBA1H8))+((sq-Rank(sq)) & 7))
>>   >> 1) & 0x3f];	// (file-rank) & 7
>>}
>>__forceinline BitBoard H1A8Attacks(unsigned int sq) const
>>{
>> return sH1A8Atta[sq][(*(((BYTE*)&(m_Inc.m_OccuBBH1A8))+(((~sq)-Rank(sq)) & 7))
>>   >> 1) & 0x3f];// (mirrorfile-rank) & 7
>>}
>>
>>...
>>
>>Gerd



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.