Skip to content

Enable null move pruning by default and fix parallel engine cleanup#51

Open
luccabb wants to merge 1 commit intomasterfrom
improve/default-params
Open

Enable null move pruning by default and fix parallel engine cleanup#51
luccabb wants to merge 1 commit intomasterfrom
improve/default-params

Conversation

@luccabb
Copy link
Owner

@luccabb luccabb commented Feb 16, 2026

Summary

  • Enable null move pruning by default in the CLI (--null-move default changed from False to True). The benchmark already uses null_move=True, but UCI/Lichess games were playing without it, making the engine significantly weaker in actual play.
  • Fix resource leaks in all parallel engines (LazySMP, Layer1Parallel, Layer2Parallel) by using context managers (with statements) for Pool and Manager.
  • Add self.nodes = 0 reset in all parallel engine search_move methods.
  • Fix L1P score handling: negate opponent scores and sort descending for clearer intent.

Local Stockfish Benchmark

Settings: 20 games, Stockfish skill 3, 10s/move, no opening book.

W L D Win Rate
Master (baseline) 19 1 0 95%
This PR 20 0 0 100%

Use /run-stockfish-benchmark for CI validation with opening book and longer time control.

Test plan

  • All alpha_beta unit tests pass (16/16)
  • /run-nps-benchmark
  • /run-stockfish-benchmark

- Change default null_move from False to True in CLI. The bench already
  uses null_move=True, but UCI/Lichess games were playing without it,
  making the engine significantly weaker in actual play.

- Fix resource leaks in all parallel engines (LazySMP, L1P, L2P) by
  using context managers (with statements) for Pool and Manager instead
  of bare constructors that never get cleaned up.

- Add self.nodes = 0 reset in all parallel engine search_move methods.

- Fix L1P score negation: negate opponent's scores and sort descending
  for clearer intent (functionally equivalent to the old ascending sort).
@github-actions
Copy link

Benchmarks

The following benchmarks are available for this PR:

Command Description
/run-nps-benchmark NPS speed benchmark (depth 5, 48 positions)
/run-stockfish-benchmark Stockfish strength benchmark (300 games)

Post a comment with the command to trigger a benchmark run.

@greptile-apps
Copy link

greptile-apps bot commented Feb 16, 2026

Greptile Summary

Enables null move pruning by default in CLI to match benchmark configuration, fixing a significant weakness in UCI/Lichess games. Adds proper resource management to all parallel engines using context managers for Pool and Manager to prevent resource leaks. Fixes Layer1ParallelAlphaBeta score handling by negating opponent scores to our perspective and sorting descending for correct move selection.

Key changes:

  • --null-move CLI default changed from False to True (aligns with bench.py:87 which uses null_move=True)
  • All parallel engines now use with statements for Pool and Manager cleanup
  • All parallel engines reset self.nodes = 0 at start of search_move
  • L1P correctly negates opponent scores and sorts descending for best move selection

Confidence Score: 5/5

  • Safe to merge - well-structured bug fixes and resource management improvements with no breaking changes
  • All changes are defensive improvements: context managers prevent resource leaks, node counter resets ensure accurate metrics, L1P score fix corrects move selection logic, and null move default aligns with tested benchmark configuration. The changes are minimal, focused, and follow Python best practices.
  • No files require special attention

Important Files Changed

Filename Overview
moonfish/main.py Changed --null-move CLI default from False to True, aligning UCI/Lichess play with benchmark configuration
moonfish/engines/lazy_smp.py Added context managers for Pool/Manager to prevent resource leaks and added self.nodes = 0 reset
moonfish/engines/l1p_alpha_beta.py Added context managers, self.nodes = 0 reset, fixed score negation and sort order for correct move selection
moonfish/engines/l2p_alpha_beta.py Added context managers for Pool/Manager to prevent resource leaks and added self.nodes = 0 reset

Flowchart

flowchart TD
    A[search_move called] --> B[Reset self.nodes = 0]
    B --> C[Create Pool and Manager<br/>with context managers]
    C --> D{Engine Type?}
    
    D -->|LazySMP| E[Run negamax N times<br/>in parallel on same board]
    E --> F[All processes share<br/>transposition table cache]
    F --> G[Return best move<br/>from shared cache]
    
    D -->|Layer1Parallel| H[Generate all<br/>legal moves layer 1]
    H --> I[Evaluate each move<br/>in parallel via negamax]
    I --> J[Negate opponent scores<br/>to our perspective]
    J --> K[Sort descending by score]
    K --> L[Return highest<br/>scoring move]
    
    D -->|Layer2Parallel| M[Generate boards<br/>2 moves ahead]
    M --> N[Evaluate all boards<br/>in parallel via negamax]
    N --> O[Apply layer/checkmate<br/>corrections]
    O --> P[Group by root move<br/>and select best]
    P --> Q[Return move leading<br/>to best board]
    
    G --> R[Context managers<br/>auto-cleanup resources]
    L --> R
    Q --> R
Loading

Last reviewed commit: 9eca103

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant