mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Simplify search functions according DRY principle
Passed STC non-regression bounds https://tests.stockfishchess.org/tests/view/6870db4bfa93cf16d3bb286a LLR: 3.00 (-2.94,2.94) <-1.75,0.25> Total: 182016 W: 46735 L: 46673 D: 88608 Ptnml(0-2): 368, 19895, 50465, 19867, 413 closes https://github.com/official-stockfish/Stockfish/pull/6161 no functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
90c83c381f
commit
b6082ba750
+14
-29
@@ -516,14 +516,21 @@ void Search::Worker::iterative_deepening() {
|
||||
}
|
||||
|
||||
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st) {
|
||||
do_move(pos, move, st, pos.gives_check(move));
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, Stack* const ss) {
|
||||
do_move(pos, move, st, pos.gives_check(move), ss);
|
||||
}
|
||||
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck) {
|
||||
void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck, Stack* const ss) {
|
||||
bool capture = pos.capture_stage(move);
|
||||
DirtyPiece dp = pos.do_move(move, st, givesCheck, &tt);
|
||||
nodes.fetch_add(1, std::memory_order_relaxed);
|
||||
accumulatorStack.push(dp);
|
||||
if (ss != nullptr)
|
||||
{
|
||||
ss->currentMove = move;
|
||||
ss->continuationHistory = &continuationHistory[ss->inCheck][capture][dp.pc][move.to_sq()];
|
||||
ss->continuationCorrectionHistory = &continuationCorrectionHistory[dp.pc][move.to_sq()];
|
||||
}
|
||||
}
|
||||
|
||||
void Search::Worker::do_null_move(Position& pos, StateInfo& st) { pos.do_null_move(st, tt); }
|
||||
@@ -695,7 +702,7 @@ Value Search::Worker::search(
|
||||
if (depth >= 8 && ttData.move && pos.pseudo_legal(ttData.move) && pos.legal(ttData.move)
|
||||
&& !is_decisive(ttData.value))
|
||||
{
|
||||
do_move(pos, ttData.move, st);
|
||||
do_move(pos, ttData.move, st, nullptr);
|
||||
Key nextPosKey = pos.key();
|
||||
auto [ttHitNext, ttDataNext, ttWriterNext] = tt.probe(nextPosKey);
|
||||
undo_move(pos, ttData.move);
|
||||
@@ -920,13 +927,7 @@ Value Search::Worker::search(
|
||||
|
||||
movedPiece = pos.moved_piece(move);
|
||||
|
||||
do_move(pos, move, st);
|
||||
|
||||
ss->currentMove = move;
|
||||
ss->continuationHistory =
|
||||
&continuationHistory[ss->inCheck][true][movedPiece][move.to_sq()];
|
||||
ss->continuationCorrectionHistory =
|
||||
&continuationCorrectionHistory[movedPiece][move.to_sq()];
|
||||
do_move(pos, move, st, ss);
|
||||
|
||||
// Perform a preliminary qsearch to verify that the move holds
|
||||
value = -qsearch<NonPV>(pos, ss + 1, -probCutBeta, -probCutBeta + 1);
|
||||
@@ -1161,17 +1162,10 @@ moves_loop: // When in check, search starts here
|
||||
}
|
||||
|
||||
// Step 16. Make the move
|
||||
do_move(pos, move, st, givesCheck);
|
||||
do_move(pos, move, st, givesCheck, ss);
|
||||
|
||||
// Add extension to new depth
|
||||
newDepth += extension;
|
||||
|
||||
// Update the current move (this must be done after singular extension search)
|
||||
ss->currentMove = move;
|
||||
ss->continuationHistory =
|
||||
&continuationHistory[ss->inCheck][capture][movedPiece][move.to_sq()];
|
||||
ss->continuationCorrectionHistory =
|
||||
&continuationCorrectionHistory[movedPiece][move.to_sq()];
|
||||
uint64_t nodeCount = rootNode ? uint64_t(nodes) : 0;
|
||||
|
||||
// Decrease reduction for PvNodes (*Scaler)
|
||||
@@ -1658,16 +1652,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
|
||||
}
|
||||
|
||||
// Step 7. Make and search the move
|
||||
Piece movedPiece = pos.moved_piece(move);
|
||||
|
||||
do_move(pos, move, st, givesCheck);
|
||||
|
||||
// Update the current move
|
||||
ss->currentMove = move;
|
||||
ss->continuationHistory =
|
||||
&continuationHistory[ss->inCheck][capture][movedPiece][move.to_sq()];
|
||||
ss->continuationCorrectionHistory =
|
||||
&continuationCorrectionHistory[movedPiece][move.to_sq()];
|
||||
do_move(pos, move, st, givesCheck, ss);
|
||||
|
||||
value = -qsearch<nodeType>(pos, ss + 1, -beta, -alpha);
|
||||
undo_move(pos, move);
|
||||
|
||||
+2
-2
@@ -297,8 +297,8 @@ class Worker {
|
||||
private:
|
||||
void iterative_deepening();
|
||||
|
||||
void do_move(Position& pos, const Move move, StateInfo& st);
|
||||
void do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck);
|
||||
void do_move(Position& pos, const Move move, StateInfo& st, Stack* const ss);
|
||||
void do_move(Position& pos, const Move move, StateInfo& st, const bool givesCheck, Stack* const ss);
|
||||
void do_null_move(Position& pos, StateInfo& st);
|
||||
void undo_move(Position& pos, const Move move);
|
||||
void undo_null_move(Position& pos);
|
||||
|
||||
Reference in New Issue
Block a user