skip to content

After adding a transposition table keyed by Zobrist hashes, a board-game AI occasionally blunders; what are the likely causes, and how do you track them down?

level: seniorimportance: should knowfreq 30%

answer

  1. exact score or only a bound
  2. stored depth against remaining depth
  3. what the hash leaves out
  4. recompute the hash from scratch

basics

~20 s

Usual causes: an alpha-beta bound stored as an exact score, shallow entries used for cutoffs, a hash missing side to move or other state, unverified collisions, and mate scores not adjusted by ply. Compare against a table-free search.

solid answer

~50 s

A transposition table entry is only safe if it records **what kind** of score it holds: a search that failed high only proves a **lower bound**, one that failed low an **upper bound**, and only a score inside the window is **exact**. Storing bounds as exact is the classic bug. Next check **depth**: an entry from a shallower search may supply a move to try first, but not a cutoff. Then the **key**: the Zobrist hash must cover everything that changes legal moves or value, including side to move and special rights, and incremental XOR updates must undo exactly what each move did. Collisions need verification bits and a legality check on the stored move. **Mate scores** must be stored relative to the node and converted on reading. To find the bug, assert the incremental hash against a from-scratch recompute, and compare fixed-depth root scores with the table on and off over a set of test positions.

go deeper

for a junior

Recall what a transposition table stores, a key, depth, score and best move, and that Zobrist hashing XORs random numbers for the pieces present.

for a middle

Explain exact, lower-bound and upper-bound entries and the stored-depth rule for using a score versus only its move.

for a senior

Diagnose blunders systematically: hash assertions, differential runs with the table on and off, isolating bounds from keys, and measuring collisions.

for a principal

Decide how much memory and verification the table gets against the strength it buys, based on measured hit rates and blunder rates.

## What a transposition table entry must hold A **transposition** is the same position reached by different move orders. A **transposition table (TT)** is a hash table, usually fixed-size, that stores what the search learned about each position so it can be reused. A sound entry holds: - a **key** or verification bits, to confirm the slot holds this position; - the **depth** the position was searched to; - the **score** and its **bound type**: exact, lower bound or upper bound; - the **best move** found, for move ordering; - often an **age** or generation, for the replacement policy. ## Zobrist hashing in brief **Zobrist hashing** assigns a random 64-bit number to every (piece type, square) pair, plus numbers for the side to move and for any other state that affects the game, such as special-move rights or a capture-in-passing square in chess. A position's key is the XOR of the numbers for everything present. Because XOR undoes itself, making a move updates the key cheaply: XOR out the piece on its origin square, XOR it in on its destination, XOR out any captured piece, and toggle the side-to-move number. Unmaking a move applies the same XORs again. ## The usual bugs, by symptom | Bug | Why it causes blunders | Fix | |---|---|---| | Bound stored as exact | a fail-high score is only "at least", so reusing it as exact overrates the line | store the bound type and use the score only where the bound decides the probe | | Shallow entry used for a cutoff | a depth-3 result cuts a node that needed depth 6, hiding a deeper tactic | cut only when stored depth is at least the remaining depth; still use the move for ordering | | Hash ignores side to move or special rights | two positions with different values share a key | XOR in every piece of state that changes legal moves or value | | Incremental update slip | a missed capture, promotion or rights change makes the key drift from the board | debug-assert against a full recompute after each make and unmake | | Index collision without verification | the slot holds another position whose low bits match | store remaining key bits, compare on probe, check the stored move is legal | | Mate score stored from the root | "mate in 5 from the root" is wrong when the same position is reached at another ply | store mate distance from the node, convert by the current ply on store and on read | | Path-dependent results | repetition or move-count draws depend on history the key does not include | accept a small error, or avoid storing draw scores found by repetition | ## How to track it down 1. **Check the key.** In debug builds, after every make and unmake, recompute the hash from the whole board and assert it equals the incremental one. This catches update slips immediately and points at the offending move type. 2. **Make the bug reproducible.** Run single-threaded at fixed depth, clear the table between test positions, and log any position where the AI blundered. 3. **Differential test.** For a plain fixed-depth alpha-beta search, letting cutoffs use only entries of exactly the requested depth should leave the root score unchanged apart from repetition-dependent cases. Run a suite of positions with the table on and off; any mismatch isolates a position small enough to trace. 4. **Narrow by feature.** Turn off score cutoffs but keep move ordering from the table. If the blunders vanish, the bug is in bounds, depth or mate handling, not in the key. 5. **Count collisions.** Temporarily store the full 64-bit key next to each entry and count probes whose verification bits match while the full keys differ. ## Living with collisions Short of storing the whole position in each entry, collisions cannot be removed, only made rare. If a table indexes by the low bits of the key and stores, say, 16 further bits for verification, a probe that lands on a slot holding a different position falsely matches about once in 65,536 tries. At millions of probes per second that can happen many times per move. Two defences keep it harmless: - **Validate the stored move** for legality before making it, so a false hit can never play an impossible move or corrupt the board. - **Store more verification bits** if measurement shows false hits changing results. Research on engines deliberately run with high collision rates found that occasional false scores rarely change the move chosen at the root, because one bad leaf seldom survives the minimax backing-up. That robustness is why a rare collision is tolerable, and also why a **systematic** bug such as a wrong bound type is the more likely cause of repeated blunders.

  • How should mate scores be stored in a transposition table, and what goes wrong if they are not adjusted?
    Store a mate as distance from the node being stored, not from the root: on store, convert root-relative 'mate in N plies' by subtracting the current ply; on read, add the current ply back. Unadjusted scores make the same position report different mate distances depending on where it was reached, so the AI misjudges which mate is faster or chases a mate that is not there.
  • Which entry should a full transposition table slot keep when two positions compete for it?
    Common policies prefer the deeper search, because it saved more work, but also replace entries left from earlier moves of the game, using an age field. Many tables use buckets of two or more entries: one slot keeps the deepest result and another always takes the newest, so recent shallow positions still benefit without evicting expensive deep results.

  • Any score returned by alpha-beta can be stored as exact.
  • A table entry from any depth can safely cut off the current node.
  • Zobrist keys only need to cover piece placement.
  • With 64-bit keys, collisions are impossible in practice.
  • Blunders after adding a transposition table mean the table is too small.