X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=f6c2233b1519b8887f19919c789059e603e019d7;hp=79046ad2007aedbc13ab8315b1805adc65a67ef9;hb=23bdd064426c6fb5b6fd860d156c9f50bb58d0db;hpb=a5ea3a202eacff75f97e866f51da3f703359eb89 diff --git a/src/search.cpp b/src/search.cpp index 79046ad2..f6c2233b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -585,10 +585,6 @@ namespace { || ((tte->type() & BOUND_UPPER) && ttValue < eval)) eval = ttValue; } - - if (!tte) - TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, - ss->staticEval, ss->evalMargin); } // Update gain for the parent non-capture move given the static position @@ -1041,8 +1037,7 @@ split_point_start: // At split points actual search starts from here if (bestValue >= beta) // Failed high { - TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth, - bestMove, ss->staticEval, ss->evalMargin); + TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth, bestMove); if (!pos.is_capture_or_promotion(bestMove) && !inCheck) { @@ -1067,7 +1062,7 @@ split_point_start: // At split points actual search starts from here else // Failed low or PV search TT.store(posKey, value_to_tt(bestValue, ss->ply), PvNode && bestMove != MOVE_NONE ? BOUND_EXACT : BOUND_UPPER, - depth, bestMove, ss->staticEval, ss->evalMargin); + depth, bestMove); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1095,7 +1090,7 @@ split_point_start: // At split points actual search starts from here Key posKey; Move ttMove, move, bestMove; Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha; - bool givesCheck, enoughMaterial, evasionPrunable; + bool givesCheck, enoughMaterial, evasionPrunable, fromNull; Depth ttDepth; // To flag BOUND_EXACT a node with eval above alpha and no available moves @@ -1104,6 +1099,7 @@ split_point_start: // At split points actual search starts from here ss->currentMove = bestMove = MOVE_NONE; ss->ply = (ss-1)->ply + 1; + fromNull = (ss-1)->currentMove == MOVE_NULL; // Check for an instant draw or maximum ply reached if (pos.is_draw() || ss->ply > MAX_PLY) @@ -1141,14 +1137,20 @@ split_point_start: // At split points actual search starts from here } else { - ss->staticEval = bestValue = evaluate(pos, ss->evalMargin); + if (fromNull) + { + // Approximated score. Real one is slightly higher due to tempo + ss->staticEval = bestValue = -(ss-1)->staticEval; + ss->evalMargin = VALUE_ZERO; + } + else + ss->staticEval = bestValue = evaluate(pos, ss->evalMargin); // Stand pat. Return immediately if static value is at least beta if (bestValue >= beta) { if (!tte) - TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER, - DEPTH_NONE, MOVE_NONE, ss->staticEval, ss->evalMargin); + TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER, DEPTH_NONE, MOVE_NONE); return bestValue; } @@ -1177,6 +1179,7 @@ split_point_start: // At split points actual search starts from here // Futility pruning if ( !PvNode && !InCheck + && !fromNull && !givesCheck && move != ttMove && enoughMaterial @@ -1256,9 +1259,7 @@ split_point_start: // At split points actual search starts from here } else // Fail high { - TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER, - ttDepth, move, ss->staticEval, ss->evalMargin); - + TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER, ttDepth, move); return value; } } @@ -1272,7 +1273,7 @@ split_point_start: // At split points actual search starts from here TT.store(posKey, value_to_tt(bestValue, ss->ply), PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER, - ttDepth, bestMove, ss->staticEval, ss->evalMargin); + ttDepth, bestMove); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1563,20 +1564,12 @@ void RootMove::insert_pv_in_tt(Position& pos) { StateInfo state[MAX_PLY_PLUS_2], *st = state; TTEntry* tte; int ply = 0; - Value v, m; do { tte = TT.probe(pos.key()); if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries - { - if (pos.in_check()) - v = m = VALUE_NONE; - else - v = evaluate(pos, m); - - TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], v, m); - } + TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply]); assert(pos.move_is_legal(pv[ply])); pos.do_move(pv[ply++], *st++);