Skip to content

Commit

Permalink
feat: Add Reverse Futility Pruning
Browse files Browse the repository at this point in the history
BENCH: 11896507
  • Loading branch information
IbaiBuR committed Jul 8, 2024
1 parent 562cf09 commit e4b06d4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/search/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace search {

constexpr int rfp_depth_limit = 6;
constexpr int rfp_margin = 70;

void searcher::reset_info() {
m_info.stopped = false;
m_info.searched_nodes = 0ULL;
Expand Down Expand Up @@ -179,9 +182,6 @@ score searcher::negamax(const board::position& pos,
if (!root_node && pos.has_repeated())
return 0;

if (ply >= constants::max_ply)
return eval::evaluate(pos);

tt::tt_entry entry;

const bool tt_hit = tt::global_tt.probe(pos.key(), entry);
Expand All @@ -193,6 +193,18 @@ score searcher::negamax(const board::position& pos,
&& entry.can_use_score(alpha, beta))
return tt_score;

const score static_eval = eval::evaluate(pos);
const bool in_check = pos.checkers().bit_count() > 0;

if (!in_check && !pv_node) {
// Reverse Futility Pruning
if (depth <= rfp_depth_limit && static_eval - rfp_margin * depth >= beta)
return static_eval;
}

if (ply >= constants::max_ply)
return static_eval;

u16 legal_moves{};
pv_line child_pv{};

Expand Down Expand Up @@ -250,7 +262,7 @@ score searcher::negamax(const board::position& pos,

// Checkmate / stalemate detection
if (!legal_moves) {
return pos.checkers().bit_count() > 0 ? -constants::score_mate + ply : 0;
return in_check ? -constants::score_mate + ply : 0;
}

const auto tt_flag = best_score <= original_alpha ? tt::tt_entry::tt_flag::upper_bound
Expand Down

0 comments on commit e4b06d4

Please sign in to comment.