Skip to content

Commit

Permalink
refine vcfsearch
Browse files Browse the repository at this point in the history
test f15
  • Loading branch information
dhbloo committed Oct 14, 2024
1 parent 530ba3c commit e8b02e7
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Rapfi/search/ab/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,6 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de

// Step 1. Initialize node
SearchThread *thisThread = board.thisThread();
ABSearchData *searchData = thisThread->searchDataAs<ABSearchData>();
thisThread->numNodes.fetch_add(1, std::memory_order_relaxed);

Color self = board.sideToMove(), oppo = ~self;
Expand All @@ -1505,10 +1504,6 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de
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 for immediate winning
if ((value = quickWinCheck<Rule>(board, ss->ply, beta)) != VALUE_ZERO) {
// Do not return mate that longer than maxMoves option
Expand All @@ -1518,6 +1513,10 @@ Value vcfsearch(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de
return value;
}

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

// Step 3. Mate distance pruning
alpha = std::max(mated_in(ss->ply), alpha);
beta = std::min(mate_in(ss->ply + 1), beta);
Expand Down Expand Up @@ -1681,31 +1680,27 @@ Value vcfdefend(Board &board, SearchStack *ss, Value alpha, Value beta, Depth de

Color self = board.sideToMove(), oppo = ~self;
uint16_t oppo5 = board.p4Count(oppo, A_FIVE); // opponent five
Value value;

// Update selDepth (selDepth counts from 1, ply from 0)
if (PvNode && thisThread->selDepth <= ss->ply)
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)
// Check if we reached the max ply or if there is no vcf threat
if (ss->ply >= MAX_PLY || !oppo5)
return Evaluation::evaluate<Rule>(board, alpha, beta);

// Step 3. Search the only defence move
Pos move = board.stateInfo().lastPattern4(oppo, A_FIVE);
assert(board.cell(move).pattern4[oppo] == A_FIVE);

// For renju, if black's defence move is a forbidden point, black loses in two steps.
Value value;
if (Rule == Rule::RENJU && self == BLACK && board.checkForbiddenPoint(move)) {
// For renju, if black's defence move is a forbidden point, black loses in two steps.
value = mated_in(ss->ply + 2);
}
else {
Expand Down

0 comments on commit e8b02e7

Please sign in to comment.