Add Late Move Reductions and Principal Variation Search#56
Add Late Move Reductions and Principal Variation Search#56
Conversation
- LMR: Late quiet moves (index >= 3, depth >= 3) are searched with reduced depth using a precomputed log-based reduction table. If the reduced search fails high, re-search at full depth. - PVS: First move searched with full alpha-beta window (PV move). All subsequent moves use null window (-alpha-1, -alpha). If the null window search fails high, re-search with full window. - Together these dramatically reduce the search tree by skipping full-depth searches on moves unlikely to improve the position. Benchmark (depth 4, 48 positions): - Nodes: 4,760,507 → 1,936,234 (−59.3%) - Time: 210.32s → 84.57s (−59.8%)
|
/run-nps-benchmark |
BenchmarksThe following benchmarks are available for this PR:
Post a comment with the command to trigger a benchmark run. |
Greptile SummaryThis PR adds two standard search optimizations to the alpha-beta engine:
Both techniques are well-established in chess engine development and are implemented correctly following standard patterns. The
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| moonfish/engines/alpha_beta.py | Adds LMR (precomputed log-based reduction table, quiet-move filtering) and PVS (null-window + re-search pattern) to negamax. Implementation follows standard chess programming patterns. No logical bugs found; caches in_check to avoid redundant call. |
Flowchart
flowchart TD
A[Start Move Loop] --> B{move_index == 0?}
B -->|Yes| C[Full Window Search\n-beta, -alpha]
B -->|No| D{Is Quiet & Not In Check\n& depth >= 3 & index >= 3?}
D -->|Yes| E[Compute LMR Reduction\nfrom precomputed table]
D -->|No| F[reduction = 0]
E --> G[PVS Null Window Search\ndepth - 1 - reduction\n-alpha-1, -alpha]
F --> G
G --> H{reduction > 0\n& score > alpha?}
H -->|Yes| I[LMR Re-search\nFull Depth, Null Window\n-alpha-1, -alpha]
H -->|No| J{score > alpha\n& score < beta?}
I --> J
J -->|Yes| K[PVS Re-search\nFull Depth, Full Window\n-beta, -alpha]
J -->|No| L[Use Current Score]
K --> L
C --> L
L --> M[Update Alpha/Beta\nCheck Cutoffs]
Last reviewed commit: 2b69491
⚡ NPS Benchmark Results
Per-position breakdown |
Summary
Two complementary search optimizations that together reduce nodes searched by ~60%:
reduction = floor(log(depth) * log(move_index) / 2). If the reduced search finds a score above alpha, re-search at full depth to verify.(-alpha-1, -alpha). If a null-window search finds a score that improves alpha, re-search with the full window.Tactical moves (captures, promotions, checks) and moves made while in check are never reduced by LMR.
Benchmark (depth 4, 48 positions)
Local Stockfish Benchmark
Settings: 20 games, Stockfish skill 3, 10s/move, no opening book.
Use
/run-stockfish-benchmarkfor CI validation with opening book and longer time control.Test plan
/run-nps-benchmarkfor CI validation/run-stockfish-benchmarkfor strength validation