1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Split search() in independent sections

I don't know if enumerating sections is a good idea,
but for me code is more readable this way

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Joona Kiiski 2010-02-24 12:19:47 +02:00 committed by Marco Costalba
parent 8a78ac84f3
commit 77bb9a94ae

View file

@ -1267,29 +1267,30 @@ namespace {
if (depth < OnePly) if (depth < OnePly)
return qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID); return qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
// Initialize, and make an early exit in case of an aborted search, // Step 1. Initialize node and poll
// an instant draw, maximum ply reached, etc. // Polling can abort search.
init_node(ss, ply, threadID); init_node(ss, ply, threadID);
// After init_node() that calls poll() // Step 2. Check for aborted search and immediate draw
if (AbortSearch || TM.thread_should_stop(threadID)) if (AbortSearch || TM.thread_should_stop(threadID))
return Value(0); return Value(0);
if (pos.is_draw() || ply >= PLY_MAX - 1) if (pos.is_draw() || ply >= PLY_MAX - 1)
return VALUE_DRAW; return VALUE_DRAW;
// Mate distance pruning // Step 3. Mate distance pruning
if (value_mated_in(ply) >= beta) if (value_mated_in(ply) >= beta)
return beta; return beta;
if (value_mate_in(ply + 1) < beta) if (value_mate_in(ply + 1) < beta)
return beta - 1; return beta - 1;
// Step 4. Transposition table lookup
// We don't want the score of a partial search to overwrite a previous full search // We don't want the score of a partial search to overwrite a previous full search
// TT value, so we use a different position key in case of an excluded move exsists. // TT value, so we use a different position key in case of an excluded move exsists.
Key posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key(); Key posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key();
// Transposition table lookup
tte = TT.retrieve(posKey); tte = TT.retrieve(posKey);
ttMove = (tte ? tte->move() : MOVE_NONE); ttMove = (tte ? tte->move() : MOVE_NONE);
@ -1299,9 +1300,9 @@ namespace {
return value_from_tt(tte->value(), ply); return value_from_tt(tte->value(), ply);
} }
// Step 5. Evaluate the position statically
isCheck = pos.is_check(); isCheck = pos.is_check();
// Evaluate the position statically
if (!isCheck) if (!isCheck)
{ {
if (tte && (tte->type() & VALUE_TYPE_EVAL)) if (tte && (tte->type() & VALUE_TYPE_EVAL))