Skip to content

Commit

Permalink
Qsearch TT
Browse files Browse the repository at this point in the history
Bench: 1997745
  • Loading branch information
SzilBalazs committed Aug 10, 2023
1 parent cc9902b commit ef5cf64
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/search/search_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,26 +434,37 @@ namespace search {

template<NodeType node_type>
Score qsearch(Score alpha, Score beta) {
constexpr bool non_pv_node = node_type == NON_PV_NODE;

if (!shared.is_searching) {
return UNKNOWN_SCORE;
}

std::optional<TTEntry> entry = shared.tt.probe(board.get_hash());
chess::Move hash_move = entry ? entry->hash_move : chess::NULL_MOVE;

if (entry && non_pv_node &&
(entry->flag == TT_EXACT || (entry->flag == TT_ALPHA && entry->eval <= alpha) || (entry->flag == TT_BETA && entry->eval >= beta))) {
return entry->eval;
}

Score static_eval = eval::evaluate(board, nnue);

if (static_eval >= beta)
return beta;
if (static_eval > alpha)
alpha = static_eval;

MoveList<true> move_list(board, chess::NULL_MOVE, chess::NULL_MOVE, history, 0);
MoveList<true> move_list(board, hash_move, chess::NULL_MOVE, history, 0);

while (!move_list.empty()) {
chess::Move move = move_list.next_move();

if (alpha > -WORST_MATE && !see(board, move, 0)) continue;

shared.tt.prefetch(board.hash_after_move(move));
shared.node_count[id]++;

board.make_move(move, &nnue);
Score score = -qsearch<node_type>(-beta, -alpha);
board.undo_move(move, &nnue);
Expand Down

0 comments on commit ef5cf64

Please sign in to comment.