X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=bce794ca1a30722e0942532f5bdb6e25408a51a3;hp=a97d3e025b070922448486522a7c1068d68d2d44;hb=0a687b2cf06fda0cc8e103c8cf9c3bbd564b02d6;hpb=d9a8dd0f7a498ec1cc191a78e7a6d44628a17133 diff --git a/src/search.cpp b/src/search.cpp index a97d3e02..bce794ca 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -235,7 +235,7 @@ namespace { const Value EasyMoveMargin = Value(0x200); // Last seconds noise filtering (LSN) - const bool UseLSNFiltering = true; + const bool UseLSNFiltering = false; const int LSNTime = 100; // In milliseconds const Value LSNValue = value_from_centipawns(200); bool loseOnTime = false; @@ -356,7 +356,7 @@ void init_search() { // Init futility margins array for (d = 0; d < 16; d++) for (mc = 0; mc < 64; mc++) - FutilityMarginsMatrix[d][mc] = 112 * int(log(double(d * d) / 2) / log(2.0) + 1) - 8 * mc + 45; + FutilityMarginsMatrix[d][mc] = 112 * int(log(double(d * d) / 2) / log(2.0) + 1.001) - 8 * mc + 45; // Init futility move count array for (d = 0; d < 32; d++) @@ -364,16 +364,17 @@ void init_search() { } -// SearchStack::init() initializes a search stack. Used at the beginning of a -// new search from the root. +// SearchStack::init() initializes a search stack entry. +// Called at the beginning of search() when starting to examine a new node. void SearchStack::init() { - pv[0] = pv[1] = MOVE_NONE; + pv[0] = pv[1] = bestMove = MOVE_NONE; currentMove = threatMove = MOVE_NONE; reduction = Depth(0); eval = VALUE_NONE; } +// SearchStack::initKillers() initializes killers for a search stack entry void SearchStack::initKillers() { mateKiller = MOVE_NONE; @@ -1246,7 +1247,7 @@ namespace { search(pos, ss, alpha, beta, d, ply); ss->skipNullMove = false; - ttMove = ss->pv[0]; + ttMove = ss->bestMove; tte = TT.retrieve(posKey); } @@ -1442,22 +1443,20 @@ namespace { if (AbortSearch || TM.thread_should_stop(threadID)) return bestValue; - if (bestValue <= oldAlpha) - TT.store(posKey, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE, ss->eval, ei.kingDanger[pos.side_to_move()]); + ValueType f = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT); + move = (bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove); + TT.store(posKey, value_to_tt(bestValue, ply), f, depth, move, ss->eval, ei.kingDanger[pos.side_to_move()]); - else if (bestValue >= beta) + // Update killers and history only for non capture moves that fails high + if (bestValue >= beta) { TM.incrementBetaCounter(pos.side_to_move(), depth, threadID); - move = ss->pv[0]; - TT.store(posKey, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, move, ss->eval, ei.kingDanger[pos.side_to_move()]); if (!pos.move_is_capture_or_promotion(move)) { update_history(pos, move, depth, movesSearched, moveCount); update_killers(move, ss); } } - else - TT.store(posKey, value_to_tt(bestValue, ply), VALUE_TYPE_EXACT, depth, ss->pv[0], ss->eval, ei.kingDanger[pos.side_to_move()]); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1488,7 +1487,7 @@ namespace { Value oldAlpha = alpha; TM.incrementNodeCounter(pos.thread()); - ss->pv[0] = ss->pv[1] = ss->currentMove = MOVE_NONE; + ss->pv[0] = ss->pv[1] = ss->bestMove = ss->currentMove = MOVE_NONE; ss->eval = VALUE_NONE; // Check for an instant draw or maximum ply reached @@ -1627,19 +1626,13 @@ namespace { // Update transposition table Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1)); - if (bestValue <= oldAlpha) - TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE, ss->eval, ei.kingDanger[pos.side_to_move()]); - else if (bestValue >= beta) - { - move = ss->pv[0]; - TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, move, ss->eval, ei.kingDanger[pos.side_to_move()]); + ValueType f = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT); + TT.store(pos.get_key(), value_to_tt(bestValue, ply), f, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]); - // Update killers only for good checking moves - if (!pos.move_is_capture_or_promotion(move)) - update_killers(move, ss); - } - else - TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EXACT, d, ss->pv[0], ss->eval, ei.kingDanger[pos.side_to_move()]); + // Update killers only for checking moves that fails high + if ( bestValue >= beta + && !pos.move_is_capture_or_promotion(ss->bestMove)) + update_killers(ss->bestMove, ss); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1823,7 +1816,7 @@ namespace { Move* src = (ss+1)->pv; Move* dst = ss->pv; - *dst = ss->currentMove; + *dst = ss->bestMove = ss->currentMove; do *++dst = *src; @@ -1841,7 +1834,7 @@ namespace { Move* dst = ss->pv; Move* pdst = pss->pv; - *dst = *pdst = ss->currentMove; + *dst = *pdst = pss->bestMove = ss->bestMove = ss->currentMove; do *++dst = *++pdst = *src; @@ -1948,7 +1941,7 @@ namespace { if (*dangerous) { - if (moveIsCheck && pos.see_sign(m)>= 0) + if (moveIsCheck && pos.see_sign(m) >= 0) result += CheckExtension[PvNode]; if (singleEvasion)