Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Reversed vs. Rotated Bitboards (correction)

Author: Sune Fischer

Date: 04:03:24 01/29/02

Go up one level in this thread


On January 29, 2002 at 06:10:53, Ralf Elvsén wrote:

>On January 29, 2002 at 04:10:07, Sune Fischer wrote:
>
>>On January 28, 2002 at 21:00:46, Ralf Elvsén wrote:
>>
>>>On January 28, 2002 at 20:46:04, Ralf Elvsén wrote:
>>>
>>>>On January 28, 2002 at 13:26:02, Sune Fischer wrote:
>>>>
>>>>>On January 28, 2002 at 13:04:05, Sune Fischer wrote:
>>>>>
>>>>>This is what I get for half the rook, similar stuff is done for the backwards
>>>>>attacks using the reversed occupied bitboard.
>>>>>
>>>>>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;
>>>>>}
>>>>>
>>>>>
>>>>>..untested, but something along those lines.
>>>>>Not entirely sure how to do it for the bishop, I guess we just shift to the
>>>>>lower right corner when attacking north-west and lower left when attacking
>>>>>north-east.
>>>>>
>>>>>But what happens if x=0?
>>>>>Will y then be 0 or something strange, the bitboard is unsigned so it should
>>>>>remain 0 right?
>>>>>
>>>>>-S.
>>>>
>>>>I think one should change
>>>>
>>>>y = x&RANK1
>>>>
>>>>to
>>>>
>>>>y = x|0x80
>>>
>>>The above is not correct. The most significant bit in the rank
>>>is not nr 7 any longer. I should know better then improvise
>>>bit manipulation 3 am, sorry :)
>>>
>>>Ralf
>>>
>>>>
>>>>That way the most significant bit in the rank will be set and when
>>>>you do the x^(x-2)-thing you will get a correct answer.
>>>>
>>>>I don't understand how you can use the same "occupied" to get
>>>>the file attacks but it's late here... :)
>>>>
>>>>x will never be zero since there is slider at "square".
>>
>>
>>the idea is this:
>>
>>occupied = 110110011000111
>>x=8
>>occupied^(occypied-x*2)= 000000001111100
>>
>>which are the attacked squares after you mask it in the direction you need.
>>
>>There are some wrap-around problems for the diagonals and for the rank (the file
>>is no problem).
>>Example: when a rook on b1 is shifted to a1, the square a2 becomes h1 (a first
>>rank square), this is bad because a rook on b1 can't attack a piece on a2 and
>>this bit will be set if a2 is occupied and the rest of first rank is empty.
>>So I think my above code was not completely correct,
>>one more masking at the beginning or end is needed to fix that problem.
>
>Yes, that was what I was trying to do. If (in this case) h1 is set you
>don't have to mask after the occ^(occ-2) -thing. I think the easiest way
>maybe is.
>
>x = (occ | 0x8080808080808080) >> square
>a = (x^(x-2)) >> square

Could be, hopefully there were a few redundant operations;)

but 0x8080808080808080 is FILE8:
-------x
-------x
-------x
-------x
-------x
-------x
-------x
-------x

how do you know what to mask with, a small table would be needed right?

>>Anyway, it is easier to test and debug than rotated and it may even be faster >on some machines where memory bandwith is a huge bottleneck.
>
>Yes, I think it can be just fine for move generation. But I'm not so
>sure how it fits in regarding the other things now handled by e.g.
>rotated bitboards.

We end up with two attack boards instead of one, so to check if a square is
attacked we need to check both boards, in principle.
If the attack boards are used frequently for other things than move generation,
then at some point it will be worth reversing the reversed board to get only one
attack board.


>Ralf
>
>>
>>>>Ralf



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.