<s>
Board	B-General_Concept
representation	I-General_Concept
in	O
computer	B-Application
chess	I-Application
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
in	O
a	O
chess	B-Application
program	O
representing	O
the	O
position	O
on	O
the	O
chessboard	O
and	O
associated	O
game	O
state	O
.	O
</s>
<s>
Board	B-General_Concept
representation	I-General_Concept
is	O
fundamental	O
to	O
all	O
aspects	O
of	O
a	O
chess	B-Application
program	O
including	O
move	O
generation	O
,	O
the	O
evaluation	B-General_Concept
function	I-General_Concept
,	O
and	O
making	O
and	O
unmaking	O
moves	O
(	O
i.e.	O
</s>
<s>
Several	O
different	O
board	B-General_Concept
representations	I-General_Concept
exist	O
.	O
</s>
<s>
Chess	B-Application
programs	O
often	O
utilize	O
more	O
than	O
one	O
board	B-General_Concept
representation	I-General_Concept
at	O
different	O
times	O
,	O
for	O
efficiency	O
.	O
</s>
<s>
Execution	O
efficiency	O
and	O
memory	O
footprint	O
are	O
the	O
primary	O
factors	O
in	O
choosing	O
a	O
board	B-General_Concept
representation	I-General_Concept
;	O
secondary	O
considerations	O
are	O
effort	O
required	O
to	O
code	O
,	O
test	O
and	O
debug	O
the	O
application	O
.	O
</s>
<s>
Early	O
programs	O
used	O
piece	O
lists	O
and	O
square	O
lists	O
,	O
both	O
array	B-Data_Structure
based	O
.	O
</s>
<s>
Most	O
modern	O
implementations	O
use	O
a	O
more	O
elaborate	O
but	O
more	O
efficient	O
bit	O
array	B-Data_Structure
approach	O
called	O
bitboards	B-Application
which	O
map	O
bits	O
of	O
a	O
64-bit	B-Device
word	O
or	O
double	O
word	O
to	O
squares	O
of	O
the	O
board	O
.	O
</s>
<s>
A	O
full	O
description	O
of	O
a	O
chess	B-Application
position	O
,	O
i.e.	O
</s>
<s>
Board	B-General_Concept
representation	I-General_Concept
typically	O
does	O
not	O
include	O
the	O
status	O
of	O
the	O
threefold	O
repetition	O
draw	O
rule	O
.	O
</s>
<s>
To	O
determine	O
this	O
rule	O
,	O
a	O
complete	O
history	O
of	O
the	O
game	O
from	O
the	O
last	O
irreversible	O
action	O
(	O
capture	O
,	O
pawn	O
movement	O
,	O
or	O
castling	O
)	O
needs	O
to	O
be	O
maintained	O
,	O
and	O
so	O
,	O
is	O
generally	O
tracked	O
in	O
separate	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Some	O
of	O
the	O
very	O
earliest	O
chess	B-Application
programs	O
working	O
with	O
extremely	O
limited	O
amounts	O
of	O
memory	O
maintained	O
serial	O
lists	O
(	O
arrays	O
)	O
of	O
the	O
pieces	O
in	O
a	O
conveniently	O
searchable	O
order	O
,	O
like	O
largest	O
to	O
smallest	O
;	O
associated	O
with	O
each	O
piece	O
was	O
its	O
location	O
on	O
the	O
board	O
as	O
well	O
as	O
other	O
information	O
,	O
such	O
as	O
squares	O
representing	O
its	O
legal	O
moves	O
.	O
</s>
<s>
Piece	O
lists	O
are	O
still	O
used	O
by	O
many	O
of	O
today	O
's	O
programs	O
in	O
conjunction	O
with	O
a	O
separate	O
board	B-General_Concept
representation	I-General_Concept
structure	O
,	O
to	O
give	O
serial	O
access	O
to	O
the	O
pieces	O
without	O
searching	O
the	O
board	O
.	O
</s>
<s>
One	O
of	O
the	O
simplest	O
ways	O
to	O
represent	O
a	O
board	O
is	O
to	O
create	O
an	O
8x8	O
two-dimensional	O
array	B-Data_Structure
(	O
or	O
,	O
equivalently	O
,	O
a	O
64	O
element	O
one-dimensional	O
array	B-Data_Structure
)	O
.	O
</s>
<s>
Each	O
array	B-Data_Structure
element	I-Data_Structure
would	O
identify	O
what	O
piece	O
occupied	O
the	O
given	O
square	O
,	O
or	O
alternatively	O
,	O
if	O
the	O
square	O
is	O
empty	O
.	O
</s>
<s>
One	O
solution	O
is	O
to	O
use	O
a	O
12x12	O
array	B-Data_Structure
instead	O
,	O
with	O
the	O
outer	O
edges	O
filled	O
with	O
,	O
say	O
,	O
the	O
value	O
99	O
.	O
</s>
<s>
Better	O
memory	O
usage	O
can	O
be	O
achieved	O
with	O
a	O
10x12	O
array	B-Data_Structure
,	O
which	O
provides	O
the	O
same	O
functionalities	O
as	O
a	O
12x12	O
one	O
by	O
overlapping	O
the	O
leftmost	O
and	O
rightmost	O
edge	O
files	O
(	O
which	O
are	O
marked	O
as	O
off-the-board	O
)	O
.	O
</s>
<s>
Some	O
chess	B-Application
engines	O
use	O
16x16	O
arrays	O
to	O
improve	O
the	O
speed	O
of	O
the	O
rank	O
and	O
file	O
number	O
conversion	O
and	O
allow	O
some	O
special	O
coding	O
tricks	O
for	O
attacks	O
etc	O
.	O
</s>
<s>
The	O
board	O
uses	O
a	O
one-dimensional	O
array	B-Data_Structure
of	O
size	O
16x8	O
=	O
128	O
,	O
numbered	O
0	O
to	O
127	O
rather	O
than	O
an	O
array	B-Data_Structure
of	O
size	O
64	O
.	O
</s>
<s>
The	O
binary	O
layout	O
for	O
a	O
legal	O
board	O
coordinate	O
's	O
rank	O
and	O
file	O
within	O
the	O
array	B-Data_Structure
is	O
0rrr0fff	O
(	O
The	O
r	O
's	O
are	O
the	O
3	O
bits	O
used	O
to	O
represent	O
the	O
rank	O
.	O
</s>
<s>
When	O
generating	O
moves	O
from	O
the	O
main	O
board	O
,	O
one	O
can	O
check	O
that	O
a	O
destination	O
square	O
is	O
on	O
the	O
main	O
board	O
before	O
consulting	O
the	O
array	B-Data_Structure
simply	O
by	O
ANDing	O
the	O
square	O
number	O
with	O
hexadecimal	O
0x88	O
(	O
binary	O
10001000	O
)	O
.	O
</s>
<s>
A	O
more	O
efficient	O
but	O
more	O
elaborate	O
board	B-General_Concept
representation	I-General_Concept
than	O
the	O
array-based	O
structures	O
is	O
the	O
bitboard	B-Application
.	O
</s>
<s>
A	O
bitboard	B-Application
is	O
a	O
64-bit	B-Device
sequence	O
of	O
bits	O
(	O
0	O
or	O
1	O
)	O
,	O
which	O
indicates	O
the	O
absence	O
or	O
presence	O
(	O
false	O
or	O
true	O
)	O
of	O
some	O
state	O
of	O
each	O
space	O
on	O
the	O
board	O
.	O
</s>
<s>
A	O
board	O
position	O
can	O
then	O
be	O
represented	O
using	O
a	O
series	O
of	O
bitboards	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
a	O
series	O
of	O
bitboards	B-Application
for	O
each	O
piece	O
type	O
,	O
for	O
each	O
side	O
,	O
can	O
represent	O
the	O
board	O
position	O
.	O
</s>
<s>
The	O
advantage	O
to	O
this	O
representation	O
is	O
the	O
ability	O
to	O
use	O
bit	O
parallel	O
operations	O
upon	O
the	O
64-bit	B-Device
entities	O
instead	O
of	O
iteration	O
to	O
manipulate	O
and	O
derive	O
information	O
about	O
the	O
state	O
of	O
the	O
board	O
.	O
</s>
<s>
This	O
makes	O
maximal	O
use	O
of	O
the	O
hardware	O
available	O
,	O
especially	O
as	O
64-bit	B-Device
processors	I-Device
have	O
become	O
mainstream	O
.	O
</s>
<s>
A	O
substantive	O
advantage	O
of	O
bitboards	B-Application
is	O
that	O
enables	O
maps	O
for	O
the	O
spaces	O
attacked	O
by	O
each	O
type	O
of	O
piece	O
on	O
each	O
space	O
of	O
the	O
board	O
to	O
be	O
pre-collated	O
and	O
stored	O
in	O
a	O
table	O
,	O
so	O
that	O
possible	O
moves	O
of	O
the	O
piece	O
can	O
be	O
retrieved	O
in	O
a	O
single	O
memory	O
fetch	O
of	O
the	O
attack	O
map	O
for	O
the	O
square	O
on	O
which	O
the	O
piece	O
resides	O
which	O
,	O
excluding	O
spaces	O
occupied	O
by	O
friendly	O
pieces	O
(	O
one	O
bitwise	O
operation	O
)	O
,	O
yields	O
the	O
legal	O
moves	O
of	O
the	O
piece	O
.	O
</s>
<s>
So	O
special	O
and	O
complex	O
data	B-General_Concept
structures	I-General_Concept
have	O
been	O
devised	O
to	O
represent	O
their	O
moves	O
.	O
</s>
<s>
Rotated	O
bitboards	B-Application
is	O
a	O
move	O
generation	O
technique	O
for	O
the	O
sliding	O
pieces	O
that	O
uses	O
rotated	O
copies	O
of	O
a	O
bitboard	B-Application
to	O
place	O
spaces	O
(	O
bits	O
)	O
in	O
a	O
file	O
or	O
diagonal	O
into	O
adjacent	O
bits	O
analogous	O
to	O
the	O
bits	O
representing	O
a	O
rank	O
.	O
</s>
<s>
The	O
bitboard	B-Application
is	O
rotated	O
90°	O
for	O
file	O
indexing	O
and	O
either	O
45°	O
or	O
-45	O
°	O
for	O
diagonal	O
indexing	O
.	O
</s>
<s>
Rotating	O
a	O
chessboard	O
is	O
conceptually	O
challenging	O
,	O
and	O
rotating	O
a	O
bitboard	B-Application
is	O
computationally	O
inelegant	O
,	O
but	O
the	O
transformation	O
avoids	O
serially	O
enumerating	O
the	O
piece	O
moves	O
,	O
or	O
a	O
lengthy	O
sequence	O
of	O
shifting	O
and	O
masking	O
a	O
bitboard	B-Application
of	O
the	O
attack	O
map	O
of	O
the	O
piece	O
to	O
take	O
into	O
account	O
the	O
board	O
configuration	O
.	O
</s>
<s>
The	O
masked	O
ranks	O
,	O
files	O
and	O
diagonals	O
of	O
sliding	O
pieces	O
can	O
be	O
used	O
via	O
a	O
hash	B-Error_Name
function	I-Error_Name
to	O
directly	O
index	O
a	O
table	O
of	O
precomputed	O
attack	O
vectors	O
based	O
on	O
the	O
occupancy	O
bits	O
in	O
the	O
masked	O
portion	O
.	O
</s>
<s>
One	O
such	O
scheme	O
that	O
uses	O
a	O
perfect	O
hash	B-Error_Name
function	I-Error_Name
along	O
with	O
tricks	O
to	O
minimize	O
the	O
potential	O
size	O
of	O
the	O
table	O
that	O
must	O
be	O
stored	O
in	O
memory	O
,	O
is	O
called	O
"	O
magic	O
bitboards	B-Application
"	O
.	O
</s>
<s>
A	O
transposition	B-General_Concept
table	I-General_Concept
is	O
a	O
cache	O
of	O
previously	O
seen	O
positions	O
,	O
and	O
associated	O
evaluations	B-General_Concept
,	O
in	O
a	O
game	O
tree	O
generated	O
by	O
a	O
computer	O
game	O
playing	O
program	O
.	O
</s>
<s>
For	O
fast	O
searching	O
of	O
the	O
table	O
,	O
a	O
hash	B-Error_Name
function	I-Error_Name
may	O
be	O
used	O
,	O
such	O
as	O
Zobrist	B-Application
hashing	I-Application
,	O
to	O
speed	O
finding	O
matching	O
boards	O
.	O
</s>
