Implementation and consideration of Go game program (8) -- Zobrist hash

Source: Internet
Author: User

I didn't want to write an article, because the Zobrist hashing entry on the English wiki is already detailed enough. Later I found that my thesis had a illustrated section about the Zobrist hash. I wanted to write it for word and image sharing. It was also convenient to paste it out:

The Zobrist hash is an encoding method specifically designed for chess games, named by Albert L. Zobrist, its inventor. The Zobrist hash uses a special replacement table, that is, to assign an encoded index value to the various possible States at each position on the board, to realize the extremely low conflict rate, encode the Board on an integer data. The encoding steps are described as follows:

1) divide the board into the smallest unit (if the 9x9 circle board is divided into 81 intersections), find the number of different States on each unit (for example, there are 3 states at one intersection on the Board ).

2) generates a random number within a certain range (such as a 64-bit integer) for each State in each unit.

3) for a specific game board, the random number corresponding to the state in each unit is used as an exclusive or operation, and the obtained result is a hash value.

Using a Zobrist hash to encode a game status has at least two advantages:

1) when the range of a random number is large enough, the probability of hash conflicts between different chess and board games is very small, which can be ignored in practical applications.

2) You do not need to re-calculate the hash value of the Board every time during the process of playing a board. You only need to calculate the part where the Board status changes.

The following uses a go board as an example to describe the Zobrist hash:

    1. The 2x2 go board has a total of four units, each of which has three States (Sunday, white child, empty point). An 8-digit random number is generated for each state:

      For the following games:

      Well, the image and text are mixed, and the effect is not very good ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.