Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Reverse Bitboards

Author: Gerd Isenberg

Date: 04:28:20 01/15/03

Go up one level in this thread


On January 15, 2003 at 06:04:05, Bas Hamstra wrote:

>>>   Occupied         Rooks       Occupied-Rooks  Occupied-2Rooks...^Occupied
>- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -
>- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -
>- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -
>- 1 - 1 - - 1 -|- - - 1 - - - -|- 1 - - - - 1 -|- 1 - 1 1 1 - -|- - - - 1 1 1 -
>- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -
>- 1 1 - 1 - 1 -|- 1 - - 1 - - -|- - 1 - - - 1 -|- 1 - - 1 1 - -|- - 1 - - 1 1 -
>- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -|- - - - - - - -
>1 - - - - - - -|1 - - - - - - -|- - - - - - - -|1 1 1 1 1 1 1 1|- 1 1 1 1 1 1 1
>>       x               1              x-1             x-2           x^(x-2)
>>
>>The first subtraction "resets" the rook bits.
>>The second subtraction toggles the bits from the rook bit positions until the
>>first occupied is toggled and becomes zero.
>>The final xor resets the remaining rook bits, but sets all occupied bits that
>>became previously reset by the second subtraction.
>>
>>For single attackers the trick also works in other positive (or reversed
>>negative) directions with some additional ray masks and 64-bit arithmetic.
>
>I am trying to understand this. First of all the above does not seem like X ^
>(X-2) to me, but rather X ^ (X - 2*Y). But the idea seems the same, right?

Hi Bas,

Yes, the idea is to get "right" attacks for multiple rooks instead of only one
rook on a1.

>If
>you subtract 1ui64 you toggle the first bit, which is in fact what you do too
>with the rookmask. I
>
>To prove this here is the output of Occupied ^ (Occupied-2):
>
>Occupied:
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>- 1 - 1 - - 1 -
>- - - - - - - -
>- 1 1 - 1 - 1 -
>- - - - - - - -
>1 - - - - - - -
>
>Occupied-1
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>- 1 - 1 - - 1 -
>- - - - - - - -
>- 1 1 - 1 - 1 -
>- - - - - - - -
>- - - - - - - -
>
>Occupied-2
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>- 1 - 1 - - 1 -
>- - - - - - - -
>1 - 1 - 1 - 1 -
>1 1 1 1 1 1 1 1
>1 1 1 1 1 1 1 1
>
>Occupied ^ (Occupied-2)
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>- - - - - - - -
>1 1 - - - - - -
>1 1 1 1 1 1 1 1
>- 1 1 1 1 1 1 1
>
>Which gives a sort of flood-fill up starting at Bit 0 and stopping at the first
>set bit. So why don't you just do it this way in stead of sutracting multiple
>rooks?

Hmm, doing it bytewise or rankwise with multiple rooks works like
KoggeStone-fill but only with four MMX-instructions.

movq
psubb
psubb
pxor

>The above BB is the only useable part, no?

Sorry, don't know exactly what you mean. If you use 64-bit arithmetic and a
single rook (on A1) you have to mask the rank the rook is on.

>
>
>Best regards,
>Bas.

Regards,
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.