Improve multi-threaded go-mate searches

Ever since #5094 master only lets the main thread terminate `go mate`
searches, reverting the earlier improvement #1215.

This PR restores the old logic. So any thread that found a "mate in x"
can now stop the search.

To make this work robustly, we need to guard against inexact mate scores
in the best thread selection. In addition, in contrast to time limits,
the main thread may now not complete a d1 search for a mated-in
position.
In master an aborted d1 search may have a PV beginning with
`Move::none()`, in which case no thread selection is performed. See
#623. We fix this bug here by checking if `lastBestPV` is empty or not.
For interrupted d1 searches we now label mated-in scores as inexact.

While at it, we also simplify the logic for detecting if we can
terminate a go mate x search, using the fact that threads.stop can only
be false if we have a completed iteration with a valid score.

The PR has no effect on game play, but should slightly improve general
mate finding and speed up multi-threaded `go mate` searches.

We also add a corresponding matecheck run to the CI. This only involves
61 mates up to mate-in-2. Test runs with the first 50 or 100 mates from
`mates2000.epd` did at times not finish within 30 minutes on my fork or
in local tests, possibly due to search explosions for some mate-in-3
positions.

closes https://github.com/official-stockfish/Stockfish/pull/6668

No functional change
This commit is contained in:
Robert Nurnberg @ elitebook
2026-03-18 20:49:06 +01:00
committed by Disservin
parent e093339c2f
commit 67a2c247d4
3 changed files with 60 additions and 27 deletions
+21 -6
View File
@@ -50,20 +50,35 @@ jobs:
- name: Run matetrack th1
working-directory: matetrack
run: |
python matecheck.py --syzygyPath 3-4-5-wdl/:3-4-5-dtz/ --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --nodes 100000 | tee matecheckout1.out
! grep "issues were detected" matecheckout1.out > /dev/null
python matecheck.py --syzygyPath 3-4-5-wdl/:3-4-5-dtz/ --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --nodes 100000 | tee matecheck1.out
! grep "issues were detected" matecheck1.out > /dev/null
- name: Run matetrack th4
working-directory: matetrack
run: |
python matecheck.py --syzygyPath 3-4-5-wdl/:3-4-5-dtz/ --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --nodes 100000 --threads 4 | tee matecheckout4.out
! grep "issues were detected" matecheckout4.out > /dev/null
python matecheck.py --syzygyPath 3-4-5-wdl/:3-4-5-dtz/ --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --nodes 100000 --threads 4 | tee matecheck4.out
! grep "issues were detected" matecheck4.out > /dev/null
- name: Run matetrack th4 gameplay
working-directory: matetrack
run: |
python matecheck.py --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --time 3 --timeinc 0.01 --threads 4 | tee matecheckout4g.out
! grep "issues were detected" matecheckout4g.out > /dev/null
python matecheck.py --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile mates2000.epd --time 3 --timeinc 0.01 --threads 4 | tee matecheck4g.out
! grep "issues were detected" matecheck4g.out > /dev/null
- name: Run matetrack th4 go-mate
working-directory: matetrack
run: |
head -n 21 matetrack.epd > gomates.epd
head -n 44 matedtrack.epd >> gomates.epd
head -n 18 mates2000.epd >> gomates.epd
python matecheck.py --engine /home/runner/work/Stockfish/Stockfish/Stockfish/src/stockfish --epdFile gomates.epd --mate 0 --threads 4 | tee matecheck4gm.out
! grep "issues were detected" matecheck4gm.out > /dev/null
total=$(grep "Total FENs:" matecheck4gm.out | awk '{print $3}')
bmates=$(grep "Best mates:" matecheck4gm.out | awk '{print $3}')
if [ $bmates -ne $total ]; then
echo "At least one go-mate search did not yield expected mate, see matecheck4gm.out" >&2
exit 1
fi
- name: Run matetrack th1 with --syzygy50MoveRule false
working-directory: matetrack