Download presentation

Presentation is loading. Please wait.

Published byAlexandra Dalton Modified over 2 years ago

1
Transposition Tables Jos Uiterwijk May 3, 2006

2
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.

3
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)

4
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

5
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

6
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

7
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

8
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

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

10
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.

11
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.

12
Example 1 Example of a midgame position in Chess:

13
Example 2 Example of an endgame position in Chess:

14
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

Similar presentations

OK

Hash Tables CSIT 402 Data Structures II. Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions.

Hash Tables CSIT 402 Data Structures II. Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

One act play ppt on tv Ppt on 21st century skills for students Ppt on object-oriented programming concepts pdf Ppt on coffee shop business plan Ppt on javascript events mouse Ppt on cse related topics about economics Marketing mix ppt on nokia pc Download ppt on poem song of the rain Ppt on odisha culture of india Ppt on needle stick injuries reports