X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=944d9c6926a6b8a4e71eb0617f03743e5f380e0a;hp=15757c3a9ae7c025cc02f5c616380cc00976fc29;hb=b088f0aefd658261e9231b556382acf532920513;hpb=2fff532f4e80c8e2e61d8b3955447f13124d40f0 diff --git a/src/search.cpp b/src/search.cpp index 15757c3a..944d9c69 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -190,9 +190,6 @@ namespace { // Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) }; - // The main transposition table - TranspositionTable TT; - /// Variables initialized by UCI options @@ -894,7 +891,7 @@ namespace { // Decide search depth for this move bool moveIsCapture = pos.move_is_capture(move); bool dangerous; - ext = extension(pos, move, true, pos.move_is_capture(move), pos.move_is_check(move), false, false, &dangerous); + ext = extension(pos, move, true, moveIsCapture, pos.move_is_check(move), false, false, &dangerous); newDepth = (Iteration - 2) * OnePly + ext + InitialDepth; // Make the move, and search it @@ -918,8 +915,8 @@ namespace { } else { - if (newDepth >= 3*OnePly - && i + MultiPV >= LMRPVMoves + if ( newDepth >= 3*OnePly + && i >= MultiPV + LMRPVMoves - 2 // Remove -2 and decrease LMRPVMoves instead ? && !dangerous && !moveIsCapture && !move_is_promotion(move) @@ -927,10 +924,10 @@ namespace { { ss[0].reduction = OnePly; value = -search(pos, ss, -alpha, newDepth-OnePly, 1, true, 0); - } - else + } else value = alpha + 1; // Just to trigger next condition - if(value > alpha) + + if (value > alpha) { value = -search(pos, ss, -alpha, newDepth, 1, true, 0); if (value > alpha) @@ -989,6 +986,8 @@ namespace { // Print search information to the standard output std::cout << "info depth " << Iteration << " score " << value_to_string(value) + << ((value >= beta)? + " lowerbound" : ((value <= alpha)? " upperbound" : "")) << " time " << current_search_time() << " nodes " << nodes_searched() << " nps " << nps() @@ -1282,57 +1281,21 @@ namespace { bool mateThreat = false; bool isCheck = pos.is_check(); - // Null move search - if ( allowNullmove - && depth > OnePly - && !isCheck - && !value_is_mate(beta) - && ok_to_do_nullmove(pos) - && approximateEval >= beta - NullMoveMargin) - { - ss[ply].currentMove = MOVE_NULL; - - StateInfo st; - pos.do_null_move(st); - int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction - - Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID); - - pos.undo_null_move(); + bool useNullMove = ( allowNullmove + //&& depth > OnePly + && !isCheck + && !value_is_mate(beta) + && ok_to_do_nullmove(pos) + && approximateEval >= beta - NullMoveMargin); - if (nullValue >= beta) - { - if (depth < 6 * OnePly) - return beta; - - // Do zugzwang verification search - Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID); - if (v >= beta) - return beta; - } else { - // The null move failed low, which means that we may be faced with - // some kind of threat. If the previous move was reduced, check if - // the move that refuted the null move was somehow connected to the - // move which was reduced. If a connection is found, return a fail - // low score (which will cause the reduced move to fail high in the - // parent node, which will trigger a re-search with full depth). - if (nullValue == value_mated_in(ply + 2)) - mateThreat = true; - - ss[ply].threatMove = ss[ply + 1].currentMove; - if ( depth < ThreatDepth - && ss[ply - 1].reduction - && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove)) - return beta - 1; - } - } // Null move search not allowed, try razoring - else if ( !value_is_mate(beta) - && depth < RazorDepth - && approximateEval < beta - RazorApprMargins[int(depth) - 2] - && ss[ply - 1].currentMove != MOVE_NULL - && ttMove == MOVE_NONE - && !pos.has_pawn_on_7th(pos.side_to_move())) + if ( !useNullMove + && !value_is_mate(beta) + && depth < RazorDepth + && approximateEval < beta - RazorApprMargins[int(depth) - 2] + && ss[ply - 1].currentMove != MOVE_NULL + && ttMove == MOVE_NONE + && !pos.has_pawn_on_7th(pos.side_to_move())) { Value v = qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID); if (v < beta - RazorMargins[int(depth) - 2]) @@ -1349,7 +1312,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search all moves. - MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]); + MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply], useNullMove); Move move, movesSearched[256]; int moveCount = 0; @@ -1365,6 +1328,48 @@ namespace { && (move = mp.get_next_move()) != MOVE_NONE && !thread_should_stop(threadID)) { + + // Null move search + if (move == MOVE_NULL) + { + ss[ply].currentMove = MOVE_NULL; + + StateInfo st; + pos.do_null_move(st); + int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction + + Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID); + + pos.undo_null_move(); + + if (nullValue >= beta) + { + if (depth < 6 * OnePly) + return beta; + + // Do zugzwang verification search + Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID); + if (v >= beta) + return beta; + } else { + // The null move failed low, which means that we may be faced with + // some kind of threat. If the previous move was reduced, check if + // the move that refuted the null move was somehow connected to the + // move which was reduced. If a connection is found, return a fail + // low score (which will cause the reduced move to fail high in the + // parent node, which will trigger a re-search with full depth). + if (nullValue == value_mated_in(ply + 2)) + mateThreat = true; + + ss[ply].threatMove = ss[ply + 1].currentMove; + if ( depth < ThreatDepth + && ss[ply - 1].reduction + && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove)) + return beta - 1; + } + continue; + } + assert(move_is_ok(move)); bool singleReply = (isCheck && mp.number_of_moves() == 1); @@ -2268,12 +2273,13 @@ namespace { if (pos.type_of_piece_on(move_from(m)) == PAWN) { - if (pos.move_is_pawn_push_to_7th(m)) + Color c = pos.side_to_move(); + if (relative_rank(c, move_to(m)) == RANK_7) { result += PawnPushTo7thExtension[pvNode]; *dangerous = true; } - if (pos.move_is_passed_pawn_push(m)) + if (pos.pawn_is_passed(c, move_to(m))) { result += PassedPawnExtension[pvNode]; *dangerous = true;