Move Ordering Techniques

GATE Relevance: Medium

Prerequisites

🎯 Learning Objectives

  • Understand why move ordering is critical for alpha-beta performance
  • Describe killer move heuristic and history heuristic
  • Explain transposition tables and their role in avoiding redundant computation
  • Combine iterative deepening with move ordering for practical game search

1. Why Move Ordering Matters

Alpha-beta pruning’s efficiency varies dramatically based on the order children are explored:

OrderingNodes EvaluatedEffective Branching
Worst orderO(bd)b (no pruning)
Random orderO(b3d/4)b3/4
Perfect orderO(bd/2)b1/2 (= √b)

For chess (b≈35), perfect ordering reduces the effective branching factor from 35 to ≈6. This is the difference between searching 6 moves deep and 12 moves deep in the same time.

The Goal

Examine the best move first at every node. If at a MAX node we look at the highest-value child first, and at a MIN node the lowest-value child first, alpha-beta achieves maximum pruning.

2. Killer Move Heuristic

Killer Move

A killer move is a move that caused a cutoff (pruning) at the same depth in a sibling subtree. The idea: if a move was strong enough to cause a cutoff at depth d in one branch, it is likely strong at depth d in other branches too.

Killer Move Heuristic
Maintain array: killers[depth] ← list of 2–3 moves

When a move m causes a β-cutoff at depth d:
    Store m in killers[d]

When generating moves at depth d:
    Try killers[d] moves FIRST (before other moves)
    Then try remaining moves in normal order

Typically, two killer moves are stored per depth level. This simple heuristic improves pruning significantly in practice, especially in chess engines.

3. History Heuristic

History Heuristic

Maintain a global table H[move] that tracks how often each move has been “good” (caused cutoffs) across the entire search. Moves with higher history scores are tried first.

History Heuristic
Initialize: H[m] ← 0 for all moves m

When move m causes a cutoff at depth d:
    H[m] ← H[m] + 2d   (deeper cutoffs weighted more)

When ordering moves at any node:
    Sort moves by H[m] in descending order

The weighting by 2d gives more credit to moves that cause cutoffs deeper in the tree, where they save more computation.

4. Transposition Tables

In many games, different move sequences can lead to the same board position (a transposition). Without detection, the same subtree is searched multiple times.

Transposition Table

A hash table that stores previously evaluated positions along with their minimax values, search depth, and best move. Before searching a node, check if the position has already been evaluated.

Transposition Table Lookup
function ALPHA-BETA-TT(state, α, β, depth):
    // Check transposition table
    entry ← TT.lookup(hash(state))
    if entry ≠ null AND entry.depth ≥ depth:
        if entry.flag = EXACT: return entry.value
        if entry.flag = LOWER: α ← max(α, entry.value)
        if entry.flag = UPPER: β ← min(β, entry.value)
        if α ≥ β: return entry.value
    
    // Normal alpha-beta search...
    // After computing value v, store in TT:
    TT.store(hash(state), v, depth, flag)

4.1 Zobrist Hashing

The standard method for hashing board positions. Assign a random 64-bit number to each (piece, square) combination. The hash of a position is the XOR of all active (piece, square) values.

  • Incremental update: When a piece moves from square A to B, hash ⊕= zobrist[piece][A] ⊕ zobrist[piece][B]
  • O(1) to update after each move
  • Uniform distribution minimizes collisions
Chess Example

After 1. e4 e5 2. Nf3 Nc6 and after 1. Nf3 Nc6 2. e4 e5, the board position is identical. The transposition table avoids re-searching this subtree. In typical chess middlegame positions, transposition tables reduce nodes by 20–40%.

5. Iterative Deepening with Move Ordering

Iterative deepening combined with alpha-beta is the gold standard for game-playing programs. The key insight: use the results from the shallower search to order moves for the deeper search.

Iterative Deepening Alpha-Beta (IDA-B)
function ID-ALPHA-BETA(state, max_time):
    best_move ← null
    for depth = 1, 2, 3, ...:
        if time_elapsed > max_time: break
        (value, move) ← ALPHA-BETA(state, depth)
        best_move ← move  // always have a move ready
    return best_move

Benefits of this approach:

  • Anytime algorithm: Can be interrupted and still return a useful move
  • Move ordering from previous iteration: The best move from depth d−1 is tried first at depth d
  • Minimal overhead: The cost of iterations 1 through d−1 is only about 1/b of iteration d
  • Transposition table synergy: Shallower searches populate the table
Practical Impact

Modern chess engines (Stockfish, Leela) use iterative deepening + alpha-beta + transposition tables + killer moves + history heuristic. This combination approaches the theoretical best-case O(bd/2) in practice.

Summary

  • Move ordering can improve alpha-beta from O(bd) to O(bd/2).
  • Killer moves: reuse moves that caused cutoffs at the same depth in sibling nodes.
  • History heuristic: global table tracking which moves tend to cause cutoffs.
  • Transposition tables: cache evaluated positions to avoid redundant work; use Zobrist hashing.
  • Iterative deepening provides move ordering from shallower searches and acts as an anytime algorithm.

References

  • Russell, S. & Norvig, P. AIMA, 4th Ed. — Chapter 5.3–5.4
  • Schaeffer, J. “The History Heuristic”, ICCA Journal, 1989
  • Zobrist, A. “A New Hashing Method with Application for Game Playing”, Tech Report, 1970