Skip to content

Commit

Permalink
Introduce BAD_QUIET movepicker stage
Browse files Browse the repository at this point in the history
Split quiets into good and bad as we do with captures. When we find
the first quiet move below a certain threshold that has been sorted we
consider all subsequent quiets bad.  Inspired by @locutus2 idea to skip
bad captures.
  • Loading branch information
mstembera authored and PikaCat-OuO committed Jan 11, 2024
1 parent deb7afe commit d462775
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
45 changes: 39 additions & 6 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ enum Stages {
GOOD_CAPTURE,
REFUTATION,
QUIET_INIT,
QUIET,
GOOD_QUIET,
BAD_CAPTURE,
BAD_QUIET,

// generate evasion moves
EVASION_TT,
Expand Down Expand Up @@ -247,6 +248,8 @@ Move MovePicker::select(Pred filter) {
// moves left, picking the move with the highest score from a list of generated moves.
Move MovePicker::next_move(bool skipQuiets) {

auto quiet_threshold = [](Depth d) { return -3330 * d; };

top:
switch (stage)
{
Expand Down Expand Up @@ -299,20 +302,34 @@ Move MovePicker::next_move(bool skipQuiets) {
if (!skipQuiets)
{
cur = endBadCaptures;
endMoves = generate<QUIETS>(pos, cur);
endMoves = beginBadQuiets = endBadQuiets = generate<QUIETS>(pos, cur);

score<QUIETS>();
partial_insertion_sort(cur, endMoves, -3330 * depth);
partial_insertion_sort(cur, endMoves, quiet_threshold(depth));
}

++stage;
[[fallthrough]];

case QUIET :
case GOOD_QUIET :
if (!skipQuiets && select<Next>([&]() {
return *cur != refutations[0] && *cur != refutations[1] && *cur != refutations[2];
}))
return *(cur - 1);
{
Move tmp = *(cur - 1);
if ((cur - 1)->value < -7500 && (cur - 1)->value > quiet_threshold(depth))
{
// Remaining quiets are bad
beginBadQuiets = cur;

// Prepare the pointers to loop over the bad captures
cur = moves;
endMoves = endBadCaptures;

++stage;
}
return tmp;
}

// Prepare the pointers to loop over the bad captures
cur = moves;
Expand All @@ -322,7 +339,23 @@ Move MovePicker::next_move(bool skipQuiets) {
[[fallthrough]];

case BAD_CAPTURE :
return select<Next>([]() { return true; });
if (select<Next>([]() { return true; }))
return *(cur - 1);

// Prepare the pointers to loop over the bad quiets
cur = beginBadQuiets;
endMoves = endBadQuiets;

++stage;
[[fallthrough]];

case BAD_QUIET :
if (!skipQuiets)
return select<Next>([&]() {
return *cur != refutations[0] && *cur != refutations[1] && *cur != refutations[2];
});

return Move::none();

case EVASION_INIT :
cur = moves;
Expand Down
10 changes: 5 additions & 5 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ class MovePicker {
const PieceToHistory** continuationHistory;
const PawnHistory* pawnHistory;
Move ttMove;
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
int stage;
int threshold;
Depth depth;
ExtMove moves[MAX_MOVES];
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures, *beginBadQuiets, *endBadQuiets;
int stage;
int threshold;
Depth depth;
ExtMove moves[MAX_MOVES];
};

} // namespace Stockfish
Expand Down

0 comments on commit d462775

Please sign in to comment.