11.2.1 Calculation of the hash value
The hash algorithm is called Zobrist hashing, and is a standard
technique for go and chess programming. The algorithm as used by us
works as follows:
- First we define a go position. This positions consists of
- the actual board, i.e. the locations and colors of the stones
- A ko point, if a ko is going on. The ko point is defined as
the empty point where the last single stone was situated before
it was captured.
It is not necessary to specify the color to move (white or black)
as part of the position. The reason for this is that read results
are stored separately for the various reading functions such as
attack3
, and it is implicit in the calling function which
player is to move.
- For each location on the board we generate random numbers:
- A number which is used if there is a white stone on this location
- A number which is used if there is a black stone on this location
- A number which is used if there is a ko on this location
These random numbers are generated once at initialization time and
then used throughout the life time of the hash table.
- The hash key for a position is the XOR of all the random numbers
which are applicable for the position (white stones, black stones, and
ko position).