<s>
A	O
bitboard	B-Application
is	O
a	O
specialized	O
bit	B-Data_Structure
array	I-Data_Structure
data	B-General_Concept
structure	I-General_Concept
commonly	O
used	O
in	O
computer	B-Application
systems	I-Application
that	I-Application
play	I-Application
board	O
games	O
,	O
where	O
each	O
bit	O
corresponds	O
to	O
a	O
game	O
board	O
space	O
or	O
piece	O
.	O
</s>
<s>
Bits	O
in	O
the	O
same	O
bitboard	B-Application
relate	O
to	O
each	O
other	O
by	O
the	O
rules	O
of	O
the	O
game	O
,	O
often	O
forming	O
a	O
game	O
position	O
when	O
taken	O
together	O
.	O
</s>
<s>
Other	O
bitboards	B-Application
are	O
commonly	O
used	O
as	O
masks	O
to	O
transform	O
or	O
answer	O
queries	O
about	O
positions	O
.	O
</s>
<s>
Bitboards	B-Application
are	O
applicable	O
to	O
any	O
game	O
whose	O
progress	O
is	O
represented	O
by	O
the	O
state	O
of	O
,	O
or	O
presence	O
of	O
pieces	O
on	O
,	O
discrete	O
spaces	O
of	O
a	O
gameboard	O
,	O
by	O
mapping	O
of	O
the	O
space	O
states	O
to	O
bits	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Bitboards	B-Application
are	O
a	O
more	O
efficient	O
alternative	O
board	B-General_Concept
representation	I-General_Concept
to	O
the	O
traditional	O
mailbox	O
representation	O
,	O
where	O
each	O
piece	O
or	O
space	O
on	O
the	O
board	O
is	O
an	O
array	O
element	O
.	O
</s>
<s>
Bitboards	B-Application
are	O
especially	O
effective	O
when	O
the	O
associated	O
bits	O
of	O
various	O
related	O
states	O
on	O
the	O
board	O
fit	O
into	O
a	O
single	O
word	O
or	O
double	O
word	O
of	O
the	O
CPU	B-Device
architecture	O
,	O
so	O
that	O
single	O
bitwise	O
operators	O
like	O
AND	O
and	O
OR	O
can	O
be	O
used	O
to	O
build	O
or	O
query	O
game	O
states	O
.	O
</s>
<s>
Among	O
the	O
computer	O
game	O
implementations	O
that	O
use	O
bitboards	B-Application
are	O
chess	B-Application
,	O
checkers	O
,	O
othello	O
and	O
word	O
games	O
.	O
</s>
<s>
The	O
scheme	O
was	O
first	O
employed	O
in	O
checkers	O
programs	O
in	O
the	O
1950s	O
,	O
and	O
since	O
the	O
mid-1970s	O
has	O
been	O
the	O
de	O
facto	O
standard	O
for	O
game	O
board	B-General_Concept
representation	I-General_Concept
in	O
computer	O
automatons	O
.	O
</s>
<s>
A	O
bitboard	B-Application
,	O
a	O
specialized	O
bit	O
field	O
,	O
is	O
a	O
format	O
that	O
packs	O
multiple	O
related	O
boolean	O
variables	O
into	O
the	O
same	O
machine	O
word	O
,	O
typically	O
representing	O
a	O
position	O
on	O
a	O
board	O
game	O
,	O
or	O
state	O
of	O
a	O
game	O
.	O
</s>
<s>
Bitboards	B-Application
allow	O
the	O
computer	O
to	O
answer	O
some	O
questions	O
about	O
game	O
state	O
with	O
one	O
bitwise	O
operation	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
a	O
chess	B-Application
program	O
wants	O
to	O
know	O
if	O
the	O
white	O
player	O
has	O
any	O
pawns	O
in	O
the	O
center	O
of	O
the	O
board	O
(	O
center	O
four	O
squares	O
)	O
it	O
can	O
just	O
compare	O
a	O
bitboard	B-Application
for	O
the	O
player	O
's	O
pawns	O
with	O
one	O
for	O
the	O
center	O
of	O
the	O
board	O
using	O
a	O
bitwise	O
AND	O
operation	O
.	O
</s>
<s>
Multiple	O
bitboards	B-Application
may	O
represent	O
different	O
properties	O
of	O
spaces	O
over	O
the	O
board	O
,	O
and	O
special	O
or	O
temporary	O
bitboards	B-Application
(	O
like	O
temporary	O
variables	O
)	O
may	O
represent	O
local	O
properties	O
or	O
hold	O
intermediate	O
collated	O
results	O
.	O
</s>
<s>
The	O
efficacy	O
of	O
bitboards	B-Application
is	O
augmented	O
by	O
two	O
other	O
properties	O
of	O
the	O
implementation	O
.	O
</s>
<s>
First	O
,	O
bitboards	B-Application
are	O
fast	O
to	O
incrementally	O
update	O
,	O
such	O
as	O
flipping	O
the	O
bits	O
at	O
the	O
source	O
and	O
destination	O
positions	O
in	O
a	O
bitboard	B-Application
for	O
piece	O
location	O
when	O
a	O
piece	O
is	O
moved	O
.	O
</s>
<s>
Bitfield	O
implementations	O
take	O
advantage	O
of	O
the	O
presence	O
of	O
fullword	O
(	O
32-bit	O
or	O
64-bit	O
)	O
bitwise	O
logical	O
operations	O
like	O
AND	O
,	O
OR	O
,	O
NOT	O
and	O
others	O
on	O
modern	O
CPU	B-Device
architectures	O
in	O
order	O
to	O
be	O
efficient	O
.	O
</s>
<s>
Bitboards	B-Application
may	O
not	O
be	O
effective	O
on	O
earlier	O
8	O
-	O
and	O
16-bit	O
minicomputer	O
and	O
microprocessor	O
architectures	O
.	O
</s>
<s>
As	O
a	O
result	O
of	O
necessary	O
compression	O
and	O
encoding	O
of	O
the	O
contents	O
of	O
massive	O
tables	O
and	O
the	O
probability	O
of	O
transcription	O
or	O
encoding	O
errors	O
,	O
bitboard	B-Application
programs	O
are	O
tedious	O
for	O
software	O
developers	O
to	O
either	O
write	O
or	O
debug	O
.	O
</s>
<s>
Bitboard	B-Application
representations	O
use	O
parallel	O
bitwise	O
operations	O
available	O
on	O
nearly	O
all	O
CPUs	B-Device
that	O
complete	O
in	O
one	O
cycle	O
and	O
are	O
fully	O
pipelined	O
and	O
cached	O
etc	O
.	O
</s>
<s>
Nearly	O
all	O
CPUs	B-Device
have	O
AND	O
,	O
OR	O
,	O
NOR	O
,	O
and	O
XOR	O
.	O
</s>
<s>
Furthermore	O
,	O
modern	O
CPUs	B-Device
have	O
instruction	B-General_Concept
pipelines	I-General_Concept
that	O
queue	O
instructions	O
for	O
execution	O
.	O
</s>
<s>
Many	O
bitboard	B-Application
operations	O
require	O
fewer	O
conditionals	O
and	O
therefore	O
increase	O
pipelining	O
and	O
make	O
effective	O
use	O
of	O
multiple	O
execution	O
units	O
on	O
many	O
CPUs	B-Device
.	O
</s>
<s>
CPUs	B-Device
have	O
a	O
bit	O
width	O
which	O
they	O
are	O
designed	O
toward	O
and	O
can	O
carry	O
out	O
bitwise	O
operations	O
in	O
one	O
cycle	O
in	O
this	O
width	O
.	O
</s>
<s>
So	O
,	O
on	O
a	O
64-bit	O
or	O
more	O
CPU	B-Device
,	O
64-bit	O
operations	O
can	O
occur	O
in	O
one	O
instruction	O
.	O
</s>
<s>
Many	O
32-bit	O
CPUs	B-Device
may	O
have	O
some	O
64-bit	O
instructions	O
and	O
those	O
may	O
take	O
more	O
than	O
one	O
cycle	O
or	O
otherwise	O
be	O
handicapped	O
compared	O
to	O
their	O
32-bit	O
instructions	O
.	O
</s>
<s>
If	O
the	O
bitboard	B-Application
is	O
larger	O
than	O
the	O
width	O
of	O
the	O
instruction	O
set	O
,	O
multiple	O
instructions	O
will	O
be	O
required	O
to	O
perform	O
a	O
full-width	O
operation	O
on	O
it	O
.	O
</s>
<s>
So	O
a	O
program	O
using	O
64-bit	O
bitboards	B-Application
would	O
run	O
faster	O
on	O
a	O
64-bit	O
processor	O
than	O
on	O
a	O
32-bit	O
processor	O
.	O
</s>
<s>
Bitboard	B-Application
representations	O
have	O
much	O
longer	O
code	O
,	O
both	O
source	O
and	O
object	O
code	O
.	O
</s>
<s>
The	O
bitboards	B-Application
themselves	O
are	O
sparse	O
,	O
sometimes	O
containing	O
only	O
a	O
single	O
one	O
bit	O
in	O
64	O
,	O
so	O
bitboard	B-Application
implementations	O
are	O
memory-intensive	O
.	O
</s>
<s>
Bitboards	B-Application
require	O
more	O
memory	O
than	O
piece-list	O
board	O
data	B-General_Concept
structures	I-General_Concept
,	O
but	O
are	O
more	O
execution	O
efficient	O
because	O
many	O
loop-and-compare	O
operations	O
are	O
reduced	O
to	O
a	O
single	O
(	O
or	O
small	O
number	O
of	O
)	O
bitwise	O
operation(s )	O
.	O
</s>
<s>
With	O
bitboards	B-Application
,	O
the	O
legal	O
moves	O
of	O
piece	O
are	O
stored	O
in	O
a	O
bitmap	O
,	O
and	O
that	O
map	O
is	O
ANDed	O
with	O
the	O
bitmap	O
for	O
space	O
.	O
</s>
<s>
For	O
some	O
games	O
,	O
writing	O
a	O
bitboard	B-Application
engine	O
requires	O
a	O
fair	O
amount	O
of	O
source	O
code	O
including	O
data	O
tables	O
that	O
will	O
be	O
longer	O
than	O
the	O
compact	O
mailbox/enumeration	O
implementation	O
.	O
</s>
<s>
Some	O
kinds	O
of	O
bitboards	B-Application
are	O
derived	O
from	O
others	O
by	O
an	O
elaborate	O
process	O
of	O
cross-correlation	O
,	O
such	O
as	O
the	O
attack	O
maps	O
in	O
chess	B-Application
.	O
</s>
<s>
Faster	O
,	O
but	O
more	O
elaborate	O
data	B-General_Concept
structures	I-General_Concept
that	O
map	O
pieces	O
to	O
locations	O
are	O
called	O
bitboards	B-Application
.	O
</s>
<s>
In	O
bitboard	B-Application
representations	O
,	O
each	O
bit	O
of	O
a	O
64	O
bit	O
word	O
(	O
or	O
double	O
word	O
on	O
32-bit	O
architectures	O
)	O
is	O
associated	O
with	O
a	O
square	O
of	O
the	O
chessboard	O
.	O
</s>
<s>
Many	O
different	O
configurations	O
of	O
the	O
board	O
are	O
usually	O
represented	O
by	O
their	O
own	O
bitboards	B-Application
including	O
the	O
locations	O
of	O
the	O
kings	O
,	O
all	O
white	O
pawns	O
,	O
all	O
black	O
pawns	O
,	O
as	O
well	O
as	O
bitboards	B-Application
for	O
each	O
of	O
the	O
other	O
piece	O
types	O
or	O
combinations	O
of	O
pieces	O
like	O
all	O
white	O
pieces	O
.	O
</s>
<s>
Two	O
attack	O
bitboards	B-Application
are	O
also	O
universal	O
:	O
one	O
bitboard	B-Application
per	O
square	O
for	O
all	O
pieces	O
attacking	O
the	O
square	O
,	O
and	O
the	O
inverse	O
bitboard	B-Application
for	O
all	O
squares	O
attacked	O
by	O
a	O
piece	O
for	O
each	O
square	O
containing	O
a	O
piece	O
.	O
</s>
<s>
Bitboards	B-Application
can	O
also	O
be	O
constants	O
like	O
one	O
representing	O
the	O
first	O
rank	O
,	O
which	O
would	O
have	O
one	O
bits	O
in	O
positions	O
0	O
-	O
7	O
.	O
</s>
<s>
Other	O
local	O
or	O
transitional	O
bitboards	B-Application
like	O
"	O
all	O
spaces	O
adjacent	O
to	O
the	O
king	O
attacked	O
by	O
opposing	O
pieces	O
"	O
may	O
be	O
collated	O
as	O
necessary	O
or	O
convenient	O
.	O
</s>
<s>
An	O
example	O
of	O
the	O
use	O
of	O
the	O
bitboards	B-Application
would	O
be	O
determining	O
whether	O
a	O
piece	O
is	O
en	O
prise	O
:	O
bitboards	B-Application
for	O
"	O
all	O
friendly	O
pieces	O
guarding	O
space	O
"	O
and	O
"	O
all	O
opposing	O
pieces	O
attacking	O
space	O
"	O
would	O
allow	O
matching	O
the	O
pieces	O
to	O
readily	O
determine	O
whether	O
a	O
target	O
piece	O
on	O
space	O
is	O
en	O
prise	O
.	O
</s>
<s>
One	O
of	O
the	O
drawbacks	O
of	O
standard	O
bitboards	B-Application
is	O
collating	O
the	O
attack	O
vectors	O
of	O
the	O
sliding	O
pieces	O
(	O
rook	O
,	O
bishop	O
,	O
queen	O
)	O
,	O
because	O
they	O
have	O
an	O
indefinite	O
number	O
of	O
attack	O
spaces	O
depending	O
on	O
other	O
occupied	O
spaces	O
.	O
</s>
<s>
In	O
acknowledgement	O
of	O
the	O
code	O
size	O
and	O
computing	O
complexity	O
of	O
generating	O
bitboards	B-Application
for	O
the	O
attack	O
vectors	O
of	O
sliding	O
pieces	O
,	O
alternate	O
bitboard	B-Application
data	B-General_Concept
structures	I-General_Concept
have	O
been	O
devised	O
to	O
collate	O
them	O
.	O
</s>
<s>
The	O
bitboard	B-Application
representations	O
of	O
knights	O
,	O
kings	O
,	O
pawns	O
and	O
other	O
board	O
configurations	O
is	O
unaffected	O
by	O
the	O
use	O
of	O
auxiliary	O
bitboards	B-Application
for	O
the	O
sliding	O
pieces	O
.	O
</s>
<s>
Rotated	O
bitboards	B-Application
are	O
complementary	O
bitboard	B-Application
data	B-General_Concept
structures	I-General_Concept
that	O
enable	O
tabularizing	O
of	O
sliding	O
piece	O
attack	O
vectors	O
,	O
one	O
for	O
file	O
attack	O
vectors	O
of	O
rooks	O
,	O
and	O
one	O
each	O
for	O
the	O
diagonal	O
and	O
anti-diagonal	O
attack	O
vectors	O
of	O
bishops	O
(	O
rank	O
attacks	O
of	O
rooks	O
can	O
be	O
indexed	O
from	O
standard	O
bitboards	B-Application
)	O
.	O
</s>
<s>
With	O
these	O
bitboards	B-Application
,	O
a	O
single	O
table	O
lookup	O
replaces	O
lengthy	O
sequences	O
of	O
bitwise	O
operations	O
.	O
</s>
<s>
These	O
bitboards	B-Application
rotate	O
the	O
board	O
occupancy	O
configuration	O
by	O
90	O
degrees	O
,	O
45	O
degrees	O
,	O
and/or	O
315	O
degrees	O
.	O
</s>
<s>
A	O
standard	O
bitboard	B-Application
will	O
have	O
one	O
byte	O
per	O
rank	O
of	O
the	O
chess	B-Application
board	O
.	O
</s>
<s>
With	O
this	O
bitboard	B-Application
it	O
's	O
easy	O
to	O
determine	O
rook	O
attacks	O
across	O
a	O
rank	O
,	O
using	O
a	O
table	O
indexed	O
by	O
the	O
occupied	O
square	O
and	O
the	O
occupied	O
positions	O
in	O
the	O
rank	O
(	O
because	O
rook	O
attacks	O
stop	O
at	O
the	O
first	O
occupied	O
square	O
)	O
.	O
</s>
<s>
By	O
rotating	O
the	O
bitboard	B-Application
90	O
degrees	O
,	O
rook	O
attacks	O
up	O
and	O
down	O
a	O
file	O
can	O
be	O
examined	O
the	O
same	O
way	O
.	O
</s>
<s>
Adding	O
bitboards	B-Application
rotated	O
45	O
degrees	O
and	O
315	O
degrees	O
(	O
-45	O
degrees	O
)	O
produces	O
bitboards	B-Application
in	O
which	O
the	O
diagonals	O
are	O
easy	O
to	O
examine	O
.	O
</s>
<s>
Actually	O
rotating	O
a	O
bitboard	B-Application
is	O
an	O
inelegant	O
transformation	O
that	O
can	O
take	O
dozens	O
of	O
instructions	O
.	O
</s>
<s>
Magic	O
bitboards	B-Application
are	O
an	O
extrapolation	O
of	O
the	O
time-space	O
tradeoff	O
of	O
direct	O
hashing	O
lookup	O
of	O
attack	O
vectors	O
.	O
</s>
<s>
Magic	O
is	O
a	O
misnomer	O
,	O
and	O
simply	O
refers	O
to	O
the	O
generation	O
and	O
use	O
of	O
a	O
perfect	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
in	O
conjunction	O
with	O
tricks	O
to	O
reduce	O
the	O
potential	O
size	O
of	O
the	O
hash	O
table	O
that	O
would	O
have	O
to	O
be	O
stored	O
in	O
memory	O
,	O
which	O
is	O
8*2^64	O
or	O
144	O
exabytes	O
.	O
</s>
<s>
As	O
with	O
other	O
schemes	O
which	O
require	O
a	O
perfect	B-Algorithm
hashing	I-Algorithm
function	O
,	O
an	O
exhaustive	O
process	O
of	O
enumeration	O
,	O
partly	O
algorithmic	O
and	O
partly	O
trial	O
and	O
error	O
,	O
is	O
necessary	O
to	O
generate	O
the	O
hash	O
function	O
.	O
</s>
<s>
So	O
magic	O
bitboards	B-Application
in	O
many	O
applications	O
provide	O
no	O
performance	O
gain	O
over	O
more	O
modest	O
hashing	O
schemes	O
or	O
rotated	O
bitboards	B-Application
.	O
</s>
<s>
The	O
bitboard	B-Application
method	O
for	O
representing	O
a	O
board	O
game	O
appears	O
to	O
have	O
been	O
invented	O
in	O
the	O
mid-1950s	O
,	O
by	O
Arthur	O
Samuel	O
and	O
was	O
used	O
in	O
his	O
checkers	O
program	O
.	O
</s>
<s>
For	O
the	O
more	O
complicated	O
game	O
of	O
chess	B-Application
,	O
it	O
appears	O
the	O
method	O
was	O
independently	O
rediscovered	O
later	O
by	O
the	O
Kaissa	O
team	O
in	O
the	O
Soviet	O
Union	O
in	O
the	O
late	O
1960s	O
,	O
and	O
again	O
by	O
the	O
authors	O
of	O
the	O
U.S.	O
Northwestern	O
University	O
program	O
"	O
Chess	B-Application
"	O
in	O
the	O
early	O
1970s	O
.	O
</s>
<s>
The	O
64-bit	O
word	O
length	O
of	O
1970s	O
super	O
computers	O
like	O
Amdahl	O
and	O
Cray	O
machines	O
,	O
facilitated	O
the	O
development	O
of	O
bitboard	B-Application
representations	O
which	O
conveniently	O
mapped	O
the	O
64-squares	O
of	O
the	O
chessboard	O
to	O
bits	O
of	O
a	O
word	O
.	O
</s>
<s>
Rotated	O
bitboards	B-Application
for	O
collating	O
the	O
moves	O
of	O
sliding	O
pieces	O
were	O
invented	O
by	O
Professor	O
Robert	O
Hyatt	O
,	O
author	O
of	O
Cray	O
Blitz	O
and	O
Crafty	B-Application
chess	B-Application
engines	O
,	O
sometime	O
in	O
the	O
mid-1990s	O
and	O
shared	O
with	O
the	O
Dark	O
Thought	O
programming	O
team	O
.	O
</s>
<s>
They	O
were	O
later	O
implemented	O
in	O
Crafty	B-Application
and	O
Dark	O
Thought	O
,	O
but	O
the	O
first	O
published	O
description	O
was	O
n't	O
until	O
1997	O
.	O
</s>
<s>
One	O
such	O
scheme	O
utilizing	O
a	O
perfect	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
to	O
eliminate	O
hash	O
collisions	O
,	O
was	O
termed	O
"	O
magic	O
bitboards	B-Application
"	O
.	O
</s>
<s>
Nonetheless	O
,	O
the	O
large	O
size	O
and	O
high	O
access	O
rates	O
of	O
such	O
tables	O
caused	O
memory	O
occupancy	O
and	O
cache	O
contention	O
issues	O
,	O
and	O
were	O
n't	O
necessarily	O
more	O
efficacious	O
than	O
the	O
rotated	O
bitboard	B-Application
approach	O
.	O
</s>
<s>
Many	O
other	O
games	O
besides	O
chess	B-Application
benefit	O
from	O
bitboards	B-Application
.	O
</s>
