transposition tables

14
Transposition Tables Jos Uiterwijk May 3, 2006

Upload: danil

Post on 22-Feb-2016

63 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Transposition Tables

Transposition Tables

Jos UiterwijkMay 3, 2006

Page 2: Transposition Tables

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.

Page 3: Transposition Tables

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)

Page 4: Transposition Tables

Transposition tables Normally the number of possible positions

largely exceeds the available memory for a transposition table. E.g., Chess has some 1050 possible positions.

Solution: hashing. Requirements:

Unique mapping from position to table Quick calculation of table entry Uniform distribution of positions over the table

Page 5: Transposition Tables

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 a3. a XOR a = 04. If si = r1 XOR r2 XOR … XOR rn with ri random

numbers, then { si } also is random5. { si } has a uniform distribution

Page 6: Transposition Tables

Zobrist hashing Example: suppose we want to hash words of

3 letters, only using ‘A’ – ‘Z’. We start with 78 random numbers:

s1,1 means a letter ‘A’ in position 1s1,2 means a letter ‘A’ in position 2s1,3 means a letter ‘A’ in position 3…s26,1 means a letter ‘Z’ in position 1s26,2 means a letter ‘Z’ in position 2s26,3 means a letter ‘Z’ in position 3

Page 7: Transposition Tables

Zobrist hashing The hash of the word ‘CAT’ is obtained by XORing the

concerning random numbers, thus:hash value(CAT) = s3,1 XOR s1,2 XOR s20,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

Page 8: Transposition Tables

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

Page 9: Transposition Tables

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

Page 10: Transposition Tables

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 2k 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 220 entry transposition table, and the remaining 44 bits are used as hash key.

Page 11: Transposition Tables

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.

Page 12: Transposition Tables

Example 1 Example of a midgame

position in Chess:

Page 13: Transposition Tables

Example 2 Example of an

endgame position in Chess:

Page 14: Transposition Tables

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