Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Reverse Bitboards

Author: Bas Hamstra

Date: 03:04:05 01/15/03

Go up one level in this thread


>>   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? 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? The above BB is the only useable part, no?


Best regards,
Bas.








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.