X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=b56a83dcbeab820f136a08be65cfc1529f41ab1b;hp=ecfaaa569dfac037a0060187be323d355c37b751;hb=500b9b0eb3b20ef58ff1280a089ab2ef1e3c6436;hpb=e4d34e18153c953e63c49dc1c9dfd8ccdaa259f0 diff --git a/src/search.cpp b/src/search.cpp index ecfaaa56..b56a83dc 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -82,6 +82,7 @@ namespace { double BestMoveChanges; Value DrawValue[COLOR_NB]; HistoryStats History; + GainsStats Gains; CountermovesStats Countermoves; template @@ -262,7 +263,7 @@ finalize: sync_cout << "info nodes " << RootPos.nodes_searched() << " time " << Time::now() - SearchTime + 1 << sync_endl; - // When we reach max depth we arrive here even without Signals.stop is raised, + // When we reach max depth we arrive here even without Signals.stop being raised, // but if we are pondering or in infinite search, according to UCI protocol, // we shouldn't print the best move before the GUI sends a "stop" or "ponderhit" // command. We simply wait here until GUI sends one of those commands (that @@ -293,6 +294,7 @@ namespace { Value bestValue, alpha, beta, delta; std::memset(ss-2, 0, 5 * sizeof(Stack)); + (ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains depth = 0; BestMoveChanges = 0; @@ -301,6 +303,7 @@ namespace { TT.new_search(); History.clear(); + Gains.clear(); Countermoves.clear(); PVSize = Options["MultiPV"]; @@ -320,7 +323,7 @@ namespace { BestMoveChanges *= 0.8; // Save last iteration's scores before first PV line is searched and all - // the move scores but the (new) PV are set to -VALUE_INFINITE. + // the move scores except the (new) PV are set to -VALUE_INFINITE. for (size_t i = 0; i < RootMoves.size(); ++i) RootMoves[i].prevScore = RootMoves[i].score; @@ -393,7 +396,7 @@ namespace { sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl; } - // Do we need to pick now the sub-optimal best move ? + // Do we now need to pick now the sub-optimal best move ? if (skill.enabled() && skill.time_to_pick(depth)) skill.pick_move(); @@ -408,7 +411,7 @@ namespace { << std::endl; } - // Do we have found a "mate in x"? + // Have we found a "mate in x"? if ( Limits.mate && bestValue >= VALUE_MATE_IN_MAX_PLY && VALUE_MATE - bestValue <= 2 * Limits.mate) @@ -419,11 +422,11 @@ namespace { { bool stop = false; // Local variable, not the volatile Signals.stop - // Take in account some extra time if the best move has changed + // Take some extra time if the best move has changed if (depth > 4 && depth < 50 && PVSize == 1) TimeMgr.pv_instability(BestMoveChanges); - // Stop search if most of available time is already consumed. We + // Stop search if most of the available time is already consumed. We // probably don't have enough time to search the first move at the // next iteration anyway. if (Time::now() - SearchTime > (TimeMgr.available_time() * 62) / 100) @@ -487,9 +490,8 @@ namespace { SplitPoint* splitPoint; Key posKey; Move ttMove, move, excludedMove, bestMove, threatMove; - Depth ext, newDepth; - Value bestValue, value, ttValue; - Value eval, nullValue; + Depth ext, newDepth, predictedDepth; + Value bestValue, value, ttValue, eval, nullValue, futilityValue; bool inCheck, givesCheck, pvMove, singularExtensionNode, improving; bool captureOrPromotion, dangerous, doFullDepthSearch; int moveCount, quietCount; @@ -601,6 +603,16 @@ namespace { TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval); } + if ( !pos.captured_piece_type() + && ss->staticEval != VALUE_NONE + && (ss-1)->staticEval != VALUE_NONE + && (move = (ss-1)->currentMove) != MOVE_NULL + && type_of(move) == NORMAL) + { + Square to = to_sq(move); + Gains.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval); + } + // Step 6. Razoring (skipped when in check) if ( !PvNode && depth < 4 * ONE_PLY @@ -613,7 +625,7 @@ namespace { Value v = qsearch(pos, ss, rbeta-1, rbeta, DEPTH_ZERO); if (v < rbeta) // Logically we should return (v + razor_margin(depth)), but - // surprisingly this did slightly weaker in tests. + // surprisingly this performed slightly weaker in tests. return v; } @@ -795,7 +807,7 @@ moves_loop: // When in check and at SpNode search starts from here givesCheck = pos.gives_check(move, ci); dangerous = givesCheck || pos.passed_pawn_push(move) - || type_of(move) == CASTLE; + || type_of(move) == CASTLING; // Step 12. Extend checks if (givesCheck && pos.see_sign(move) >= 0) @@ -847,12 +859,13 @@ moves_loop: // When in check and at SpNode search starts from here continue; } - Depth predictedDepth = newDepth - reduction(improving, depth, moveCount); + predictedDepth = newDepth - reduction(improving, depth, moveCount); // Futility pruning: parent node if (predictedDepth < 7 * ONE_PLY) { - Value futilityValue = ss->staticEval + futility_margin(predictedDepth) + Value(128); + futilityValue = ss->staticEval + futility_margin(predictedDepth) + + Value(128) + Gains[pos.moved_piece(move)][to_sq(move)]; if (futilityValue <= alpha) { @@ -869,21 +882,19 @@ moves_loop: // When in check and at SpNode search starts from here } // Prune moves with negative SEE at low depths - if ( predictedDepth < 4 * ONE_PLY - && pos.see_sign(move) < 0) + if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < 0) { if (SpNode) splitPoint->mutex.lock(); continue; } - } // Check for legality only before to do the move if (!RootNode && !SpNode && !pos.legal(move, ci.pinned)) { - --moveCount; + moveCount--; continue; } @@ -941,7 +952,7 @@ moves_loop: // When in check and at SpNode search starts from here // Only for PV nodes do a full PV search on the first move or after a fail // high, in the latter case search only if value < beta, otherwise let the - // parent node to fail low with value <= alpha and to try another move. + // parent node fail low with value <= alpha and to try another move. if (PvNode && (pvMove || (value > alpha && (RootNode || value < beta)))) value = newDepth < ONE_PLY ? givesCheck ? -qsearch(pos, ss+1, -beta, -alpha, DEPTH_ZERO) @@ -1320,7 +1331,7 @@ moves_loop: // When in check and at SpNode search starts from here assert(is_ok(first)); assert(is_ok(second)); assert(color_of(pos.piece_on(from_sq(second))) == ~pos.side_to_move()); - assert(type_of(first) == CASTLE || color_of(pos.piece_on(to_sq(first))) == ~pos.side_to_move()); + assert(type_of(first) == CASTLING || color_of(pos.piece_on(to_sq(first))) == ~pos.side_to_move()); Square m1from = from_sq(first); Square m2from = from_sq(second); @@ -1331,7 +1342,7 @@ moves_loop: // When in check and at SpNode search starts from here // We exclude the trivial case where a sliding piece does in two moves what // it could do in one move: eg. Ra1a2, Ra2a3. if ( m2to == m1from - || (m1to == m2from && !squares_aligned(m1from, m2from, m2to))) + || (m1to == m2from && !aligned(m1from, m2from, m2to))) return true; // Second one moves through the square vacated by first one @@ -1339,7 +1350,7 @@ moves_loop: // When in check and at SpNode search starts from here return true; // Second's destination is defended by the first move's piece - Bitboard m1att = pos.attacks_from(pos.piece_on(m1to), m1to, pos.pieces() ^ m2from); + Bitboard m1att = attacks_bb(pos.piece_on(m1to), m1to, pos.pieces() ^ m2from); if (m1att & m2to) return true; @@ -1383,7 +1394,7 @@ moves_loop: // When in check and at SpNode search starts from here Piece pc = pos.piece_on(m1from); // The moved piece attacks the square 'tto' ? - if (pos.attacks_from(pc, m1to, occ) & m2to) + if (attacks_bb(pc, m1to, occ) & m2to) return true; // Scan for possible X-ray attackers behind the moved piece