Evaluation Functions
Prerequisites
- Minimax Algorithm — Full-depth minimax search
- Alpha-Beta Pruning — Pruning techniques
- Heuristic Functions — Concept of heuristic evaluation
🎯 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.
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)
| Piece | Value | Feature |
|---|---|---|
| Pawn (♙) | 1 | f1 = #white pawns − #black pawns |
| Knight (♘) | 3 | f2 = #white knights − #black knights |
| Bishop (♗) | 3 | f3 = #white bishops − #black bishops |
| Rook (♖) | 5 | f4 = #white rooks − #black rooks |
| Queen (♕) | 9 | f5 = #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 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.
3. Cutoff Search
function H-MINIMAX(state, depth):
if IS-TERMINAL(state): return UTILITY(state)
if depth = 0: return EVAL(state) // cutoff
if PLAYER(state) = MAX:
v ← −∞
for each a in ACTIONS(state):
v ← max(v, H-MINIMAX(RESULT(state,a), depth−1))
return v
else:
v ← +∞
for each a in ACTIONS(state):
v ← min(v, H-MINIMAX(RESULT(state,a), depth−1))
return v
The depth parameter d is chosen based on available time. Deeper search generally means better play, but diminishing returns apply. The combination of cutoff search with alpha-beta pruning and iterative deepening is the standard approach.
- Must be fast to compute — called millions of times per move
- Must correlate with true utility — better positions should score higher
- Must be consistent with terminal values at game-over states
- Should not have systematic biases that cause pathological behavior
4. The 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.
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
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.
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
| Game | Key Features | Typical EVAL |
|---|---|---|
| Tic-Tac-Toe | Lines with potential, blocking | +1/0/−1 (can solve fully, eval rarely needed) |
| Chess | Material, position, pawn structure | Centipawns (100 = 1 pawn advantage) |
| Othello (Reversi) | Corners, edges, mobility, disc count | Weighted square table + mobility |
| Checkers | Kings, back-row protection, piece count | Linear 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