<s>
Zobrist	B-Application
hashing	I-Application
(	O
also	O
referred	O
to	O
as	O
Zobrist	O
keys	O
or	O
Zobrist	O
signatures	O
)	O
is	O
a	O
hash	B-Error_Name
function	I-Error_Name
construction	O
used	O
in	O
computer	B-Application
programs	I-Application
that	O
play	O
abstract	O
board	O
games	O
,	O
such	O
as	O
chess	B-Application
and	O
Go	B-Application
,	O
to	O
implement	O
transposition	B-General_Concept
tables	I-General_Concept
,	O
a	O
special	O
kind	O
of	O
hash	B-Algorithm
table	I-Algorithm
that	O
is	O
indexed	O
by	O
a	O
board	O
position	O
and	O
used	O
to	O
avoid	O
analyzing	O
the	O
same	O
position	O
more	O
than	O
once	O
.	O
</s>
<s>
Zobrist	B-Application
hashing	I-Application
is	O
named	O
for	O
its	O
inventor	O
,	O
Albert	O
Lindsey	O
Zobrist	O
.	O
</s>
<s>
Zobrist	B-Application
hashing	I-Application
is	O
the	O
first	O
known	O
instance	O
of	O
the	O
generally	O
useful	O
underlying	O
technique	O
called	O
tabulation	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
Zobrist	B-Application
hashing	I-Application
starts	O
by	O
randomly	B-Algorithm
generating	I-Algorithm
bitstrings	B-Data_Structure
for	O
each	O
possible	O
element	O
of	O
a	O
board	O
game	O
,	O
i.e.	O
</s>
<s>
for	O
each	O
combination	O
of	O
a	O
piece	O
and	O
a	O
position	O
(	O
in	O
the	O
game	O
of	O
chess	B-Application
,	O
that	O
's	O
12	O
pieces	O
×	O
64	O
board	O
positions	O
,	O
or	O
18	O
×	O
64	O
if	O
kings	O
and	O
rooks	O
that	O
may	O
still	O
castle	O
,	O
and	O
pawns	O
that	O
may	O
capture	O
en	O
passant	O
,	O
are	O
treated	O
separately	O
for	O
both	O
colors	O
)	O
.	O
</s>
<s>
Now	O
any	O
board	O
configuration	O
can	O
be	O
broken	O
up	O
into	O
independent	O
piece/position	O
components	O
,	O
which	O
are	O
mapped	O
to	O
the	O
random	O
bitstrings	B-Data_Structure
generated	O
earlier	O
.	O
</s>
<s>
The	O
final	O
Zobrist	O
hash	B-Error_Name
is	O
computed	O
by	O
combining	O
those	O
bitstrings	B-Data_Structure
using	O
bitwise	O
XOR	B-Application
.	O
</s>
<s>
Example	O
pseudocode	O
for	O
the	O
game	O
of	O
chess	B-Application
:	O
</s>
<s>
function	O
hash(board )	O
:	O
</s>
<s>
If	O
the	O
bitstrings	B-Data_Structure
are	O
long	O
enough	O
,	O
different	O
board	O
positions	O
will	O
almost	O
certainly	O
hash	B-Error_Name
to	O
different	O
values	O
;	O
however	O
longer	O
bitstrings	B-Data_Structure
require	O
proportionally	O
more	O
computer	O
resources	O
to	O
manipulate	O
.	O
</s>
<s>
The	O
most	O
commonly	O
used	O
bitstring	B-Data_Structure
(	O
key	O
)	O
length	O
is	O
64	O
bits	O
.	O
</s>
<s>
Many	O
game	O
engines	O
store	O
only	O
the	O
hash	B-Error_Name
values	I-Error_Name
in	O
the	O
transposition	B-General_Concept
table	I-General_Concept
,	O
omitting	O
the	O
position	O
information	O
itself	O
entirely	O
to	O
reduce	O
memory	O
usage	O
,	O
and	O
assuming	O
that	O
hash	B-Algorithm
collisions	I-Algorithm
will	O
not	O
occur	O
,	O
or	O
will	O
not	O
greatly	O
influence	O
the	O
results	O
of	O
the	O
table	O
if	O
they	O
do	O
.	O
</s>
<s>
Zobrist	B-Application
hashing	I-Application
is	O
the	O
first	O
known	O
instance	O
of	O
tabulation	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
The	O
result	O
is	O
a	O
3-wise	B-Error_Name
independent	I-Error_Name
hash	I-Error_Name
family	I-Error_Name
.	O
</s>
<s>
In	O
particular	O
,	O
it	O
is	O
strongly	O
universal	B-Algorithm
.	O
</s>
<s>
As	O
an	O
example	O
,	O
in	O
chess	B-Application
,	O
at	O
any	O
one	O
time	O
each	O
of	O
the	O
64	O
squares	O
can	O
at	O
any	O
time	O
be	O
empty	O
,	O
or	O
contain	O
one	O
of	O
the	O
6	O
game	O
pieces	O
,	O
which	O
are	O
either	O
black	O
or	O
white	O
.	O
</s>
<s>
Thus	O
one	O
needs	O
to	O
generate	O
6	O
x	O
2	O
x	O
64	O
+	O
1	O
=	O
769	O
random	O
bitstrings	B-Data_Structure
.	O
</s>
<s>
Given	O
a	O
position	O
,	O
one	O
obtains	O
its	O
Zobrist	O
hash	B-Error_Name
by	O
finding	O
out	O
which	O
pieces	O
are	O
on	O
which	O
squares	O
,	O
and	O
combining	O
the	O
relevant	O
bitstrings	B-Data_Structure
together	O
.	O
</s>
<s>
If	O
the	O
position	O
is	O
black	O
to	O
move	O
,	O
the	O
black-to-move	O
bitstring	B-Data_Structure
is	O
also	O
included	O
in	O
the	O
Zobrist	O
hash	B-Error_Name
.	O
</s>
<s>
Rather	O
than	O
computing	O
the	O
hash	B-Error_Name
for	O
the	O
entire	O
board	O
every	O
time	O
,	O
as	O
the	O
pseudocode	O
above	O
does	O
,	O
the	O
hash	B-Error_Name
value	I-Error_Name
of	O
a	O
board	O
can	O
be	O
incrementally	O
updated	O
simply	O
by	O
XORing	O
out	O
the	O
bitstring(s )	O
for	O
positions	O
that	O
have	O
changed	O
,	O
and	O
XORing	O
in	O
the	O
bitstrings	B-Data_Structure
for	O
the	O
new	O
positions	O
.	O
</s>
<s>
For	O
instance	O
,	O
if	O
a	O
pawn	O
on	O
a	O
chessboard	O
square	O
is	O
replaced	O
by	O
a	O
rook	O
from	O
another	O
square	O
,	O
the	O
resulting	O
position	O
would	O
be	O
produced	O
by	O
XORing	O
the	O
existing	O
hash	B-Error_Name
with	O
the	O
bitstrings	B-Data_Structure
for	O
:	O
</s>
<s>
This	O
makes	O
Zobrist	B-Application
hashing	I-Application
very	O
efficient	O
for	O
traversing	O
a	O
game	O
tree	O
.	O
</s>
<s>
In	O
computer	B-Application
Go	I-Application
,	O
this	O
technique	O
is	O
also	O
used	O
for	O
superko	O
detection	O
.	O
</s>
<s>
More	O
generically	O
,	O
Zobrist	B-Application
hashing	I-Application
can	O
be	O
applied	O
over	O
finite	O
sets	O
of	O
elements	O
(	O
in	O
the	O
chess	B-Application
example	O
,	O
these	O
elements	O
are	O
tuples	B-Application
)	O
,	O
as	O
long	O
as	O
a	O
random	O
bitstring	B-Data_Structure
can	O
be	O
assigned	O
to	O
each	O
possible	O
element	O
.	O
</s>
<s>
This	O
can	O
be	O
either	O
done	O
with	O
a	O
random	O
number	O
generator	O
for	O
smaller	O
element	O
spaces	O
,	O
or	O
with	O
a	O
hash	B-Error_Name
function	I-Error_Name
for	O
larger	O
ones	O
.	O
</s>
<s>
This	O
method	O
has	O
been	O
used	O
to	O
recognize	O
substitutional	O
alloy	O
configurations	O
during	O
Monte	B-Algorithm
Carlo	I-Algorithm
simulations	I-Algorithm
in	O
order	O
to	O
prevent	O
wasting	O
computational	O
effort	O
on	O
states	O
that	O
have	O
already	O
been	O
calculated	O
.	O
</s>
