Presentation is loading. Please wait.

Transposition Tables Jos Uiterwijk May 3, 2006. Transpositions A transposition is the re-occurrence of a position in a search process. For example, in.

Presentation on theme: "Transposition Tables Jos Uiterwijk May 3, 2006. Transpositions A transposition is the re-occurrence of a position in a search process. For example, in."— Presentation transcript:

Transposition Tables Jos Uiterwijk May 3, 2006

Transpositions A transposition is the re-occurrence of a position in a search process. For example, in Chess the position after 1. e4 e5 2. Nf3 is the same as after 1. Nf3 e5 2. e4.

Transposition tables So, the search tree actually is a search graph Therefore, storing the information in a table can give huge gains. E.g., in an alpha-beta search process, store the: Value Best move/action Search depth Flag (real value, upper bound or lower bound) Identification (hash key, see further)

Transposition tables Normally the number of possible positions largely exceeds the available memory for a transposition table. E.g., Chess has some 10 50 possible positions. Solution: hashing. Requirements: Unique mapping from position to table Quick calculation of table entry Uniform distribution of positions over the table

Zobrist hashing Uses de XOR operator to calculate the table entry Properties of XOR-operator: 1. a XOR (b XOR c) = (a XOR b) XOR c 2. a XOR b = b XOR a 3. a XOR a = 0 4. If s i = r 1 XOR r 2 XOR … XOR r n with r i random numbers, then { s i } also is random 5. { s i } has a uniform distribution

Zobrist hashing Example: suppose we want to hash words of 3 letters, only using ‘A’ – ‘Z’. We start with 78 random numbers: s 1,1 means a letter ‘A’ in position 1 s 1,2 means a letter ‘A’ in position 2 s 1,3 means a letter ‘A’ in position 3 … s 26,1 means a letter ‘Z’ in position 1 s 26,2 means a letter ‘Z’ in position 2 s 26,3 means a letter ‘Z’ in position 3

Zobrist hashing The hash of the word ‘CAT’ is obtained by XORing the concerning random numbers, thus: hash value(CAT) = s 3,1 XOR s 1,2 XOR s 20,3 For a board game: Suppose m different possible pieces on a square (Chess: m = 12, Go: m = 2) Suppose n squares (Chess: n = 64, Go: n = 361) Then m x n different combinations of pieces/square So m x n random numbers needed for calculating the hash value of a position

Zobrist hashing Often possible for incremental updating the hash value: Adding one piece (Go): hash value (new_position) = hash value (old_position) XOR random number (new piece) Moving a piece (Chess): hash value (new_position) = hash value (old_position) XOR random number (from_square) XOR random number (to_square) For “difficult” moves sometimes more operations needed

Transposition table mapping The hash value is used to map a position to a table: ↓

Hash key Since the number of possible hash values normally far exceeds the number of entries, we only use part of the hash value (say, k bits) as a the entry. This is called the primary hash code. Therefore, transposition tables typically have 2 k entries. Another hash value (or typically the remaining bits) are used for identifications purposes (secondary hash code or hash key). E.g., for 64-bits random numbers 20 bits are used as primary hash code for the mapping on a 2 20 entry transposition table, and the remaining 44 bits are used as hash key.

Errors Two types of error: 1. Type-1 error: two positions having the same hash code (primary + secondary). This is serious since this can remain undetected! 2. Type-2 error: two positions having the same primary hash code. This is called a clash or collision. Now we should use a replacement scheme, e.g., keep the deepest investigated, or the newest, or others.

Example 1 Example of a midgame position in Chess:

Example 2 Example of an endgame position in Chess:

Conclusions Transposition tables can be of great importance, with huge savings Importance depends on type of game and type of position Zobrist hashing is a convenient way of storing positions The number of bits must be sufficiently large to avoid errors

Download ppt "Transposition Tables Jos Uiterwijk May 3, 2006. Transpositions A transposition is the re-occurrence of a position in a search process. For example, in."

Similar presentations

Ads by Google