Skip to content

Commit

Permalink
sort evasion ahead of time
Browse files Browse the repository at this point in the history
  • Loading branch information
ces42 committed Nov 25, 2024
1 parent b7f1734 commit b3481ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
25 changes: 10 additions & 15 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,13 @@ void MovePicker::score() {

// Returns the next move satisfying a predicate function.
// This never returns the TT move, as it was emitted before.
template<MovePicker::PickType T, typename Pred>
template<typename Pred>
Move MovePicker::select(Pred filter) {

while (cur < endMoves)
{
if constexpr (T == Best)
std::swap(*cur, *std::max_element(cur, endMoves));

for (; cur < endMoves; ++cur)
if (*cur != ttMove && filter())
return *cur++;

cur++;
}
return Move::none();
}

Expand Down Expand Up @@ -245,7 +239,7 @@ Move MovePicker::next_move() {
goto top;

case GOOD_CAPTURE :
if (select<Next>([&]() {
if (select([&]() {
// Move losing capture to endBadCaptures to be tried later
return pos.see_ge(*cur, -cur->value / 18) ? true
: (*endBadCaptures++ = *cur, false);
Expand All @@ -269,7 +263,7 @@ Move MovePicker::next_move() {
[[fallthrough]];

case GOOD_QUIET :
if (!skipQuiets && select<Next>([]() { return true; }))
if (!skipQuiets && select([]() { return true; }))
{
if ((cur - 1)->value > -7998 || (cur - 1)->value <= quiet_threshold(depth))
return *(cur - 1);
Expand All @@ -286,7 +280,7 @@ Move MovePicker::next_move() {
[[fallthrough]];

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

// Prepare the pointers to loop over the bad quiets
Expand All @@ -298,7 +292,7 @@ Move MovePicker::next_move() {

case BAD_QUIET :
if (!skipQuiets)
return select<Next>([]() { return true; });
return select([]() { return true; });

return Move::none();

Expand All @@ -307,17 +301,18 @@ Move MovePicker::next_move() {
endMoves = generate<EVASIONS>(pos, cur);

score<EVASIONS>();
partial_insertion_sort(cur, endMoves, std::numeric_limits<int>::min());
++stage;
[[fallthrough]];

case EVASION :
return select<Best>([]() { return true; });
return select([]() { return true; });

case PROBCUT :
return select<Next>([&]() { return pos.see_ge(*cur, threshold); });
return select([&]() { return pos.see_ge(*cur, threshold); });

case QCAPTURE :
return select<Next>([]() { return true; });
return select([]() { return true; });
}

assert(false);
Expand Down
7 changes: 1 addition & 6 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class Position;
// a cut-off first.
class MovePicker {

enum PickType {
Next,
Best
};

public:
MovePicker(const MovePicker&) = delete;
MovePicker& operator=(const MovePicker&) = delete;
Expand All @@ -57,7 +52,7 @@ class MovePicker {
void skip_quiet_moves();

private:
template<PickType T, typename Pred>
template<typename Pred>
Move select(Pred);
template<GenType>
void score();
Expand Down

0 comments on commit b3481ab

Please sign in to comment.