Skip to content

Commit

Permalink
evaluate leaf value before vcf
Browse files Browse the repository at this point in the history
test f15
  • Loading branch information
dhbloo committed Oct 13, 2024
1 parent ed79856 commit b06b9cf
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions Rapfi/search/ab/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,17 @@ Value search(Board &board, SearchStack *ss, Value alpha, Value beta, Depth depth

// Dive into vcf search when the depth reaches zero (~17 elo)
if (depth <= 0.0f) {
(ss + 1)->staticEval = ss->staticEval = Evaluation::evaluate<Rule>(board, alpha, beta);

// Update bound using standing pat
if (oppo5)
beta = std::min(beta, ss->staticEval);
else
alpha = std::max(alpha, ss->staticEval);
// Prune directly if the value is already outside the window
if (alpha >= beta)
return alpha;

return oppo5 ? vcfdefend<Rule, NT>(board, ss, alpha, beta)
: vcfsearch<Rule, NT>(board, ss, alpha, beta);
}
Expand Down Expand Up @@ -1505,7 +1516,7 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de

// Check if we reached the max ply
if (ss->ply >= MAX_PLY)
return Evaluation::evaluate<Rule>(board, alpha, beta);
return alpha;

// Check for immediate winning
if ((value = quickWinCheck<Rule>(board, ss->ply, beta)) != VALUE_ZERO) {
Expand Down Expand Up @@ -1546,20 +1557,26 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de
// Step 5. Static position evaluation
if (ttHit) {
// Never assume anything about values stored in TT
bestValue = ss->staticEval = ttEval;
if (bestValue == VALUE_NONE)
bestValue = ss->staticEval = Evaluation::evaluate<Rule>(board, alpha, beta);
if (ttEval != VALUE_NONE)
ss->staticEval = ttEval;
else if (depth < 0)
ss->staticEval = Evaluation::evaluate<Rule>(board, alpha, beta);
bestValue = ss->staticEval;

// Try to use ttValue as a better eval estimation
if (ttValue != VALUE_NONE
&& (ttBound & (ttValue > ss->staticEval ? BOUND_LOWER : BOUND_UPPER)))
bestValue = ttValue;
}
else {
// In case of null move search use previous static eval with a different sign
bestValue = ss->staticEval = (ss - 1)->currentMove == Pos::PASS
? -(ss - 1)->staticEval
: Evaluation::evaluate<Rule>(board, alpha, beta);
if (depth < 0) {
// In case of null move search use previous static eval with a different sign
ss->staticEval = (ss - 1)->currentMove == Pos::PASS
? -(ss - 1)->staticEval
: Evaluation::evaluate<Rule>(board, alpha, beta);
}

bestValue = ss->staticEval;
}

// Stand pat. Return immediately if static value is at least beta
Expand Down Expand Up @@ -1686,17 +1703,13 @@ Value vcfdefend(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de
thisThread->selDepth = ss->ply + 1;

// Step 2. Check for immediate evaluation, draw and winning
// Return evaluation immediately if there is no vcf threat
if (!oppo5)
return Evaluation::evaluate<Rule>(board, alpha, beta);

// Check if the board has been filled or we have reached the max game ply.
if (board.movesLeft() == 0 || board.nonPassMoveCount() >= thisThread->options().maxMoves)
return getDrawValue(board, thisThread->options(), ss->ply);

// Check if we reached the max ply
if (ss->ply >= MAX_PLY)
return Evaluation::evaluate<Rule>(board, alpha, beta);
// Check if we reached the max ply or if there is no vcf threat
if (ss->ply >= MAX_PLY || !oppo5)
return beta;

// Step 3. Search the only defence move
Pos move = board.stateInfo().lastPattern4(oppo, A_FIVE);
Expand Down

0 comments on commit b06b9cf

Please sign in to comment.