Re: Reflections on BitBoards
- From: Mike <m.fee@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 6 Mar 2008 14:09:43 +1300
In article <b3d29$47cf3be6$5350c6a6$27094@xxxxxxxxxxxxxxxxxxxxxxx>, root@xxxxxxxxxxxxxxxxxxx says...
On Thu, 06 Mar 2008 12:02:33 +1300, Mike wrote:OK - this is not chess (but a different game played on an 8x8 grid), and I need to do this to reduce some thousands of
I am using 64 bit integers to describe the 'state' of each square in an
8x8 board, and need to determine if two boards are equal, i.e. have the
same state for each square. But the boards are also considered equal if
one is the rotation or reflection of the other. I have to do many
billions of such comparisons (and must do this in real time) so need
fast board reflection or rotation algorithms. The seven possible
alternate symmetry states can be cycled through, for example, by
applying H,V,H,D,H,V,H to some board B, where H,V, and D are horizontal,
vertical, and diagonal reflections.
I have fast horizontal plane and vertical plane reflection algorithms,
(in Pascal-like poseudo-code) for example:
The first thing that comes to mind is: *why* do you want to do this ?
(The most common usage for bitboards (chess, Lines Of Action) does not
*need* mirroring)
millions of 'positions' to merely hundreds of millions for further processing. Symmetry positions are, in effect,
identical in this game, and I don't want to process each one more than once.
One way to solve it would be to treat it as a matrix-multiplication:I will look at this. At the moment the diagonal mirror requires 15 ands, 14 ors, and 14 shifts. A lookup could do it in
use
((value) & 0xff)
((value >> 8) & 0xff)
...
((value >> 56) & 0xff)
as an index into a precomputed array of the needed values,
8 ands 8 ors (or 4 of each if I use 16 bits, 'cos I could afford 8x64K of LUT) plus the cost of extracting the values
from the LUT.
and add these up, or "or" them. You can have different lookuptables forNot clear to me that rotations are necessarily more expensive, as any symmetry operation on the bitboard is equivalent
the different transformations. (Hint: don't rotate. Rotations can be
composed of two mirror-ops, which are cheaper.)
to a bit-permutation. If there is a 'short-cut' for rotation it could be possibly be cheaper...and as far as I can see,
your LUT method, for example, would be equally fast for _any_ bit-permutation so is just as good for a rotation as for
a reflection.
[The matrix-mult for bitstrings was mentioned by Knuth in his forthcomingAny reference to 'Morton-like' addressing?
part of TAOCP. He even suggested to extend MIX, IIRC]
Another idea is to treat it as a matrix, and use a Morton-like adressing
scheme for the bit<-->location mapping, which could simplify the
transformations. YMMV.
Thanks
Mike
.
- Follow-Ups:
- Re: Reflections on BitBoards
- From: moi
- Re: Reflections on BitBoards
- References:
- Reflections on BitBoards
- From: Mike
- Re: Reflections on BitBoards
- From: moi
- Reflections on BitBoards
- Prev by Date: Re: Reflections on BitBoards
- Next by Date: Re: Reflections on BitBoards
- Previous by thread: Re: Reflections on BitBoards
- Next by thread: Re: Reflections on BitBoards
- Index(es):
Relevant Pages
|