Preserve all moves in movepicker

Simplifies method otherPieceTypesMobile quite a bit and makes it more
precise. More precise because capturesSearched list not always contains
all processed captures:
although extremely rare, it can happen that a 'good' capture get pruned
at step 14 and doesn't make it to capturesSearched. (functional change
at higher depths)

passed STC-simplification bounds
https://tests.stockfishchess.org/tests/view/68025974cd501869c6698153
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 273664 W: 15658 L: 15681 D: 242325
Ptnml(0-2): 166, 10368, 115802, 10315, 181

passed LTC-simplification bounds
https://tests.stockfishchess.org/tests/view/6804b86acd501869c6698673
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 96780 W: 24547 L: 24419 D: 47814
Ptnml(0-2): 30, 8466, 31286, 8562, 46

Applied changes requested by disservin & retested to be on the safe side

STC:
https://tests.stockfishchess.org/tests/view/6806110698cd372e3aea5919
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 107392 W: 27739 L: 27606 D: 52047
Ptnml(0-2): 266, 10867, 31306, 10982, 275

LTC:
https://tests.stockfishchess.org/tests/view/6806346198cd372e3aea5965
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 233484 W: 59106 L: 59103 D: 115275
Ptnml(0-2): 116, 22787, 70939, 22778, 122

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

Bench: 1857323
This commit is contained in:
pb00067
2025-05-13 20:23:43 +02:00
committed by Disservin
parent 94e6c0498f
commit 0f905b4e88
3 changed files with 26 additions and 33 deletions
+19 -23
View File
@@ -19,8 +19,8 @@
#include "movepick.h"
#include <cassert>
#include <cstddef>
#include <limits>
#include <utility>
#include "bitboard.h"
#include "misc.h"
@@ -223,6 +223,7 @@ top:
case QSEARCH_TT :
case PROBCUT_TT :
++stage;
cur = moves + 1;
return ttMove;
case CAPTURE_INIT :
@@ -238,9 +239,12 @@ top:
case GOOD_CAPTURE :
if (select([&]() {
// Move losing capture to endBadCaptures to be tried later
return pos.see_ge(*cur, -cur->value / 18) ? true
: (*endBadCaptures++ = *cur, false);
if (!pos.see_ge(*cur, -cur->value / 18))
{
std::swap(*endBadCaptures++, *cur);
return false;
}
return true;
}))
return *(cur - 1);
@@ -250,7 +254,6 @@ top:
case QUIET_INIT :
if (!skipQuiets)
{
cur = endBadCaptures;
endMoves = beginBadQuiets = endBadQuiets = generate<QUIETS>(pos, cur);
score<QUIETS>();
@@ -317,30 +320,23 @@ top:
void MovePicker::skip_quiet_moves() { skipQuiets = true; }
bool MovePicker::otherPieceTypesMobile(PieceType pt, ValueList<Move, 32>& capturesSearched) {
if (stage != GOOD_QUIET && stage != BAD_QUIET)
return true;
bool MovePicker::other_piece_types_mobile(PieceType pt) {
assert(stage == GOOD_QUIET || stage == BAD_QUIET || stage == EVASION);
// verify good captures
for (std::size_t i = 0; i < capturesSearched.size(); i++)
if (type_of(pos.moved_piece(capturesSearched[i])) != pt)
// verify all generated captures and quiets
for (ExtMove* m = moves; m < endMoves; ++m)
{
if (*m && type_of(pos.moved_piece(*m)) != pt)
{
if (type_of(pos.moved_piece(capturesSearched[i])) != KING)
if (type_of(pos.moved_piece(*m)) != KING)
return true;
if (pos.legal(capturesSearched[i]))
return true;
}
// now verify bad captures and quiets
for (ExtMove* c = moves; c < endBadQuiets; ++c)
if (type_of(pos.moved_piece(*c)) != pt)
{
if (type_of(pos.moved_piece(*c)) != KING)
return true;
if (pos.legal(*c))
if (pos.legal(*m))
return true;
}
}
return false;
}
void MovePicker::mark_current_illegal() { *(cur - 1) = Move::none(); }
} // namespace Stockfish
+2 -6
View File
@@ -19,8 +19,6 @@
#ifndef MOVEPICK_H_INCLUDED
#define MOVEPICK_H_INCLUDED
#include <cstddef>
#include "history.h"
#include "movegen.h"
#include "types.h"
@@ -29,9 +27,6 @@ namespace Stockfish {
class Position;
template<typename T, std::size_t MaxSize>
class ValueList;
// The MovePicker class is used to pick one pseudo-legal move at a time from the
// current position. The most important method is next_move(), which emits one
// new pseudo-legal move on every call, until there are no moves left, when
@@ -55,7 +50,8 @@ class MovePicker {
MovePicker(const Position&, Move, int, const CapturePieceToHistory*);
Move next_move();
void skip_quiet_moves();
bool otherPieceTypesMobile(PieceType pt, ValueList<Move, 32>& capturesSearched);
bool other_piece_types_mobile(PieceType pt);
void mark_current_illegal();
private:
template<typename Pred>
+5 -4
View File
@@ -1011,8 +1011,10 @@ moves_loop: // When in check, search starts here
// Check for legality
if (!pos.legal(move))
{
mp.mark_current_illegal();
continue;
}
// At root obey the "searchmoves" option and skip moves not listed in Root
// Move List. In MultiPV mode we also skip PV moves that have been already
// searched and those of lower "TB rank" if we are in a TB root position.
@@ -1084,9 +1086,8 @@ moves_loop: // When in check, search starts here
&& pos.non_pawn_material(us) == PieceValue[movedPiece]
&& PieceValue[movedPiece] >= RookValue
&& !(PseudoAttacks[KING][pos.square<KING>(us)] & move.from_sq()))
skip = mp.otherPieceTypesMobile(
type_of(movedPiece),
capturesSearched); // if the opponent captures last mobile piece it might be stalemate
// if the opponent captures last mobile piece it might be stalemate
skip = mp.other_piece_types_mobile(type_of(movedPiece));
if (skip)
continue;