X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=7c9c1b6936bfc9220f0b7be372e969a529ee2fd8;hp=2072c4bc241d7590d8dca47ba04e3e2c6985146b;hb=3d6995eae8039b2bf4141cbc02d87d5a6c2a1905;hpb=8d1625d6df6d9918ca85cd3e169a06e3749c2f67 diff --git a/src/search.cpp b/src/search.cpp index 2072c4bc..7c9c1b69 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -547,6 +547,7 @@ namespace { // Step 1. Initialize node Thread* thisThread = pos.this_thread(); inCheck = pos.checkers(); + Color us = pos.side_to_move(); moveCount = captureCount = quietCount = ss->moveCount = 0; bestValue = -VALUE_INFINITE; maxValue = VALUE_INFINITE; @@ -577,6 +578,17 @@ namespace { beta = std::min(mate_in(ss->ply+1), beta); if (alpha >= beta) return alpha; + + // Check if there exists a move which draws by repetition, or an alternative + // earlier move to this position. + if ( pos.rule50_count() >= 3 + && alpha < VALUE_DRAW + && pos.has_game_cycle(ss->ply)) + { + alpha = VALUE_DRAW; + if (alpha >= beta) + return alpha; + } } assert(0 <= ss->ply && ss->ply < MAX_PLY); @@ -628,7 +640,7 @@ namespace { else if (!pos.capture_or_promotion(ttMove)) { int penalty = -stat_bonus(depth); - thisThread->mainHistory[pos.side_to_move()][from_to(ttMove)] << penalty; + thisThread->mainHistory[us][from_to(ttMove)] << penalty; update_continuation_histories(ss, pos.moved_piece(ttMove), to_sq(ttMove), penalty); } } @@ -682,12 +694,12 @@ namespace { } } - // Step 6. Evaluate the position statically + // Step 6. Static evaluation of the position if (inCheck) { ss->staticEval = eval = VALUE_NONE; improving = false; - goto moves_loop; + goto moves_loop; // Skip early pruning when in check } else if (ttHit) { @@ -710,13 +722,7 @@ namespace { ss->staticEval, TT.generation()); } - improving = ss->staticEval >= (ss-2)->staticEval - ||(ss-2)->staticEval == VALUE_NONE; - - if (ss->excludedMove || !pos.non_pawn_material(pos.side_to_move())) - goto moves_loop; - - // Step 7. Razoring (skipped when in check, ~2 Elo) + // Step 7. Razoring (~2 Elo) if ( !PvNode && depth < 3 * ONE_PLY && eval <= alpha - RazorMargin[depth / ONE_PLY]) @@ -727,7 +733,10 @@ namespace { return v; } - // Step 8. Futility pruning: child node (skipped when in check, ~30 Elo) + improving = ss->staticEval >= (ss-2)->staticEval + || (ss-2)->staticEval == VALUE_NONE; + + // Step 8. Futility pruning: child node (~30 Elo) if ( !rootNode && depth < 7 * ONE_PLY && eval - futility_margin(depth, improving) >= beta @@ -737,9 +746,12 @@ namespace { // Step 9. Null move search with verification search (~40 Elo) if ( !PvNode && (ss-1)->currentMove != MOVE_NULL + && (ss-1)->statScore < 22500 && eval >= beta && ss->staticEval >= beta - 36 * depth / ONE_PLY + 225 - && (ss->ply >= thisThread->nmp_ply || ss->ply % 2 != thisThread->nmp_odd)) + && !excludedMove + && pos.non_pawn_material(us) + && (ss->ply > thisThread->nmp_min_ply || us != thisThread->nmp_color)) { assert(eval - beta >= 0); @@ -761,24 +773,26 @@ namespace { if (nullValue >= VALUE_MATE_IN_MAX_PLY) nullValue = beta; - if (abs(beta) < VALUE_KNOWN_WIN && (depth < 12 * ONE_PLY || thisThread->nmp_ply)) + if (thisThread->nmp_min_ply || (abs(beta) < VALUE_KNOWN_WIN && depth < 12 * ONE_PLY)) return nullValue; - // Do verification search at high depths. Disable null move pruning - // for side to move for the first part of the remaining search tree. - thisThread->nmp_ply = ss->ply + 3 * (depth-R) / 4; - thisThread->nmp_odd = ss->ply % 2; + assert(!thisThread->nmp_min_ply); // Recursive verification is not allowed + + // Do verification search at high depths, with null move pruning disabled + // for us, until ply exceeds nmp_min_ply. + thisThread->nmp_min_ply = ss->ply + 3 * (depth-R) / 4 - 1; + thisThread->nmp_color = us; Value v = search(pos, ss, beta-1, beta, depth-R, false); - thisThread->nmp_odd = thisThread->nmp_ply = 0; + thisThread->nmp_min_ply = 0; if (v >= beta) return nullValue; } } - // Step 10. ProbCut (skipped when in check, ~10 Elo) + // Step 10. ProbCut (~10 Elo) // If we have a good enough capture and a reduced search returns a value // much above beta, we can (almost) safely prune the previous move. if ( !PvNode @@ -816,7 +830,7 @@ namespace { } } - // Step 11. Internal iterative deepening (skipped when in check, ~2 Elo) + // Step 11. Internal iterative deepening (~2 Elo) if ( depth >= 8 * ONE_PLY && !ttMove) { @@ -912,7 +926,7 @@ moves_loop: // When in check, search starts from here // Step 14. Pruning at shallow depth (~170 Elo) if ( !rootNode - && pos.non_pawn_material(pos.side_to_move()) + && pos.non_pawn_material(us) && bestValue > VALUE_MATED_IN_MAX_PLY) { if ( !captureOrPromotion @@ -981,7 +995,14 @@ moves_loop: // When in check, search starts from here Depth r = reduction(improving, depth, moveCount); if (captureOrPromotion) // (~5 Elo) + { + //Increase reduction by comparing opponent's stat score + if ( (ss-1)->statScore >= 0 + && thisThread->captureHistory[movedPiece][to_sq(move)][type_of(pos.captured_piece())] < 0) + r += ONE_PLY; + r -= r ? ONE_PLY : DEPTH_ZERO; + } else { // Decrease reduction if opponent's move count is high (~5 Elo) @@ -1007,7 +1028,7 @@ moves_loop: // When in check, search starts from here && !pos.see_ge(make_move(to_sq(move), from_sq(move)))) r -= 2 * ONE_PLY; - ss->statScore = thisThread->mainHistory[~pos.side_to_move()][from_to(move)] + ss->statScore = thisThread->mainHistory[us][from_to(move)] + (*contHist[0])[movedPiece][to_sq(move)] + (*contHist[1])[movedPiece][to_sq(move)] + (*contHist[3])[movedPiece][to_sq(move)] @@ -1106,7 +1127,7 @@ moves_loop: // When in check, search starts from here else { assert(value >= beta); // Fail high - ss->statScore = std::max(ss->statScore, 0); + ss->statScore = 0; break; } } @@ -1153,7 +1174,7 @@ moves_loop: // When in check, search starts from here update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY)); } // Bonus for prior countermove that caused the fail low - else if ( depth >= 3 * ONE_PLY + else if ( (depth >= 3 * ONE_PLY || PvNode) && !pos.captured_piece() && is_ok((ss-1)->currentMove)) update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth));