Evaluation Functions

GATE Relevance: Medium

Prerequisites

🎯 Learning Objectives

  • Understand why evaluation functions are needed (cannot search to terminal states)
  • Design evaluation functions using material and positional features
  • Implement cutoff search: minimax with a depth limit and evaluation
  • Recognize the horizon effect and solve it with quiescence search

1. Why Evaluation Functions?

For complex games like chess (b≈35, m≈80), searching all the way to terminal states is impossible. Even with alpha-beta pruning, the tree is too large. The solution: cut off the search at some depth d and use an evaluation function to estimate the utility of non-terminal states.

Evaluation Function

An evaluation function EVAL(s) is a heuristic that estimates the expected utility of game state s. It replaces the true UTILITY function at non-terminal states when the search is cut off.

  • EVAL(s) > 0 ⇒ position favors MAX
  • EVAL(s) < 0 ⇒ position favors MIN
  • EVAL(s) = 0 ⇒ roughly equal position
  • At terminal states, EVAL must agree with UTILITY

2. Designing Evaluation Functions

2.1 Weighted Linear Evaluation

The most common form is a weighted linear combination of features:

EVAL(s) = w1f1(s) + w2f2(s) + … + wnfn(s)

where fi(s) are features of the state and wi are learned or hand-tuned weights.

2.2 Material Balance (Chess)

Standard Chess Piece Values
PieceValueFeature
Pawn (♙)1f1 = #white pawns − #black pawns
Knight (♘)3f2 = #white knights − #black knights
Bishop (♗)3f3 = #white bishops − #black bishops
Rook (♖)5f4 = #white rooks − #black rooks
Queen (♕)9f5 = #white queens − #black queens

Material evaluation: EVAL = 1·f1 + 3·f2 + 3·f3 + 5·f4 + 9·f5

2.3 Positional Features

Beyond material, strong evaluation functions consider:

  • Piece mobility: Number of legal moves available
  • King safety: Pawn shelter, castling status
  • Pawn structure: Doubled, isolated, or passed pawns
  • Center control: Pieces controlling central squares
  • Development: How many pieces are active vs. on starting squares
Modern Approach: Neural Networks

Modern engines like AlphaZero and Leela use neural networks as evaluation functions, trained via self-play. The network learns features automatically. Stockfish NNUE combines a hand-crafted search with a neural network evaluator.

4. The Horizon Effect

Horizon Effect

An artifact of fixed-depth search where the engine makes poor decisions because a critical event (threat, capture) occurs just beyond the search depth. The engine “pushes” the problem past its horizon by making delaying moves.

Horizon Effect Example

Suppose at depth 6, a queen capture occurs at depth 7. The engine doesn’t see it and evaluates the position as good. It might even sacrifice a piece to push the queen loss to depth 8 — still beyond its horizon — making the situation worse.

5. Quiescence Search

Quiescence Search

Instead of cutting off at a fixed depth, continue searching in non-quiet (volatile) positions. Only apply EVAL(s) at quiet positions — states where no captures, checks, or other forcing moves are available.

Algorithm: QUIESCENCE-SEARCH
function QUIESCENCE(state, α, β):
    stand_pat ← EVAL(state)
    if stand_pat ≥ β: return β
    if stand_pat > α: α ← stand_pat
    
    for each capture_move in CAPTURE-MOVES(state):
        score ← −QUIESCENCE(RESULT(state, capture_move),
                                   −β, −α)
        if score ≥ β: return β
        if score > α: α ← score
    return α

Quiescence search typically adds 4–8 plies of additional search at capture-heavy positions, providing much more accurate evaluations.

6. Evaluation in Other Games

GameKey FeaturesTypical EVAL
Tic-Tac-ToeLines with potential, blocking+1/0/−1 (can solve fully, eval rarely needed)
ChessMaterial, position, pawn structureCentipawns (100 = 1 pawn advantage)
Othello (Reversi)Corners, edges, mobility, disc countWeighted square table + mobility
CheckersKings, back-row protection, piece countLinear combination of ~20 features

Summary

  • Evaluation functions estimate utility for non-terminal states when search is cut off at depth d.
  • Weighted linear combinations of game features are the classic approach.
  • Material balance is the dominant feature in chess; positional features add refinement.
  • The horizon effect causes errors when critical events lie just beyond the search depth.
  • Quiescence search addresses the horizon effect by extending search in volatile positions.
  • Modern engines use neural network evaluators trained by self-play.

References

  • Russell, S. & Norvig, P. AIMA, 4th Ed. — Chapter 5.4
  • Shannon, C. “Programming a Computer for Playing Chess”, 1950
  • Silver, D. et al. “Mastering Chess and Shogi by Self-Play”, Science, 2018