X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsearch.cpp;h=e621d702dc42edd456cf80513ad879f3209efc55;hb=683e6dc6566719f8737fad9bc30580bb0b4d8d20;hp=f7f62b2344e7c5d2837fd21698d3b222a274771a;hpb=cc3c1dc25a60335bceb9f07ef93aad81b366a717;p=stockfish diff --git a/src/search.cpp b/src/search.cpp index f7f62b23..e621d702 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -267,7 +267,7 @@ namespace { bool connected_moves(const Position &pos, Move m1, Move m2); bool value_is_mate(Value value); bool move_is_killer(Move m, const SearchStack& ss); - Depth extension(const Position &pos, Move m, bool pvNode, bool check, bool singleReply, bool mateThreat, bool* dangerous); + Depth extension(const Position &pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous); bool ok_to_do_nullmove(const Position &pos); bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d); bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply); @@ -805,11 +805,11 @@ namespace { // Decide search depth for this move bool dangerous; - ext = extension(pos, move, true, pos.move_is_check(move), false, false, &dangerous); + ext = extension(pos, move, true, pos.move_is_capture(move), pos.move_is_check(move), false, false, &dangerous); newDepth = (Iteration - 2) * OnePly + ext + InitialDepth; // Make the move, and search it - pos.do_move(move, u, dcCandidates); + pos.do_move(move, u); if (i < MultiPV) { @@ -983,9 +983,10 @@ namespace { Move move, movesSearched[256]; int moveCount = 0; Value value, bestValue = -VALUE_INFINITE; - Bitboard dcCandidates = mp.discovered_check_candidates(); + Color us = pos.side_to_move(); + Bitboard dcCandidates = pos.discovered_check_candidates(us); bool isCheck = pos.is_check(); - bool mateThreat = pos.has_mate_threat(opposite_color(pos.side_to_move())); + bool mateThreat = pos.has_mate_threat(opposite_color(us)); // Loop through all legal moves until no moves remain or a beta cutoff // occurs. @@ -996,7 +997,7 @@ namespace { assert(move_is_ok(move)); bool singleReply = (isCheck && mp.number_of_moves() == 1); - bool moveIsCheck = pos.move_is_check(move, dcCandidates); + bool moveIsCheck = pos.move_is_check(move); bool moveIsCapture = pos.move_is_capture(move); movesSearched[moveCount++] = ss[ply].currentMove = move; @@ -1009,12 +1010,12 @@ namespace { // Decide the new search depth bool dangerous; - Depth ext = extension(pos, move, true, moveIsCheck, singleReply, mateThreat, &dangerous); + Depth ext = extension(pos, move, true, moveIsCapture, moveIsCheck, singleReply, mateThreat, &dangerous); Depth newDepth = depth - OnePly + ext; // Make and search the move UndoInfo u; - pos.do_move(move, u, dcCandidates); + pos.do_move(move, u); if (moveCount == 1) // The first move in list is the PV value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID); @@ -1247,8 +1248,8 @@ namespace { { Value v = qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID); if ( (v < beta - RazorMargin - RazorMargin / 4) - || (depth <= 2*OnePly && v < beta - RazorMargin) - || (depth <= OnePly && v < beta - RazorMargin / 2)) + || (depth < 3*OnePly && v < beta - RazorMargin) + || (depth < 2*OnePly && v < beta - RazorMargin / 2)) return v; } @@ -1283,7 +1284,7 @@ namespace { Move move, movesSearched[256]; int moveCount = 0; Value value, bestValue = -VALUE_INFINITE; - Bitboard dcCandidates = mp.discovered_check_candidates(); + Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move()); Value futilityValue = VALUE_NONE; bool useFutilityPruning = UseFutilityPruning && depth < SelectiveDepth @@ -1298,14 +1299,14 @@ namespace { assert(move_is_ok(move)); bool singleReply = (isCheck && mp.number_of_moves() == 1); - bool moveIsCheck = pos.move_is_check(move, dcCandidates); + bool moveIsCheck = pos.move_is_check(move); bool moveIsCapture = pos.move_is_capture(move); movesSearched[moveCount++] = ss[ply].currentMove = move; // Decide the new search depth bool dangerous; - Depth ext = extension(pos, move, false, moveIsCheck, singleReply, mateThreat, &dangerous); + Depth ext = extension(pos, move, false, moveIsCapture, moveIsCheck, singleReply, mateThreat, &dangerous); Depth newDepth = depth - OnePly + ext; // Futility pruning @@ -1338,7 +1339,7 @@ namespace { // Make and search the move UndoInfo u; - pos.do_move(move, u, dcCandidates); + pos.do_move(move, u); // Try to reduce non-pv search depth by one ply if move seems not problematic, // if the move fails high will be re-searched at full depth. @@ -1470,8 +1471,9 @@ namespace { MovePicker mp = MovePicker(pos, pvNode, MOVE_NONE, EmptySearchStack, depth, isCheck ? NULL : &ei); Move move; int moveCount = 0; - Bitboard dcCandidates = mp.discovered_check_candidates(); - bool enoughMaterial = pos.non_pawn_material(pos.side_to_move()) > RookValueMidgame; + Color us = pos.side_to_move(); + Bitboard dcCandidates = pos.discovered_check_candidates(us); + bool enoughMaterial = pos.non_pawn_material(us) > RookValueMidgame; // Loop through the moves until no moves remain or a beta cutoff // occurs. @@ -1489,7 +1491,7 @@ namespace { && !isCheck && !pvNode && !move_promotion(move) - && !pos.move_is_check(move, dcCandidates) + && !pos.move_is_check(move) && !pos.move_is_passed_pawn_push(move)) { Value futilityValue = staticValue @@ -1517,7 +1519,7 @@ namespace { // Make and search the move. UndoInfo u; - pos.do_move(move, u, dcCandidates); + pos.do_move(move, u); Value value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID); pos.undo_move(move, u); @@ -1583,8 +1585,9 @@ namespace { && (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE) { assert(move_is_ok(move)); + assert(pos.discovered_check_candidates(pos.side_to_move()) == sp->dcCandidates); - bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates); + bool moveIsCheck = pos.move_is_check(move); bool moveIsCapture = pos.move_is_capture(move); lock_grab(&(sp->lock)); @@ -1595,7 +1598,7 @@ namespace { // Decide the new search depth. bool dangerous; - Depth ext = extension(pos, move, false, moveIsCheck, false, false, &dangerous); + Depth ext = extension(pos, move, false, moveIsCapture, moveIsCheck, false, false, &dangerous); Depth newDepth = sp->depth - OnePly + ext; // Prune? @@ -1609,7 +1612,7 @@ namespace { // Make and search the move. UndoInfo u; - pos.do_move(move, u, sp->dcCandidates); + pos.do_move(move, u); // Try to reduce non-pv search depth by one ply if move seems not problematic, // if the move fails high will be re-searched at full depth. @@ -1694,7 +1697,9 @@ namespace { && !thread_should_stop(threadID) && (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE) { - bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates); + assert(pos.discovered_check_candidates(pos.side_to_move()) == sp->dcCandidates); + + bool moveIsCheck = pos.move_is_check(move); bool moveIsCapture = pos.move_is_capture(move); assert(move_is_ok(move)); @@ -1713,12 +1718,12 @@ namespace { // Decide the new search depth. bool dangerous; - Depth ext = extension(pos, move, true, moveIsCheck, false, false, &dangerous); + Depth ext = extension(pos, move, true, moveIsCapture, moveIsCheck, false, false, &dangerous); Depth newDepth = sp->depth - OnePly + ext; // Make and search the move. UndoInfo u; - pos.do_move(move, u, sp->dcCandidates); + pos.do_move(move, u); // Try to reduce non-pv search depth by one ply if move seems not problematic, // if the move fails high will be re-searched at full depth. @@ -2113,7 +2118,7 @@ namespace { // Case 4: The destination square for m2 is attacked by the moving piece // in m1: - if(pos.piece_attacks_square(t1, t2)) + if(pos.piece_attacks_square(pos.piece_on(t1), t1, t2)) return true; // Case 5: Discovered check, checking piece is the piece moved in m1: @@ -2178,7 +2183,7 @@ namespace { // extended, as example because the corresponding UCI option is set to zero, // the move is marked as 'dangerous' so, at least, we avoid to prune it. - Depth extension(const Position &pos, Move m, bool pvNode, bool check, + Depth extension(const Position& pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous) { assert(m != MOVE_NONE); @@ -2209,7 +2214,7 @@ namespace { } } - if ( pos.move_is_capture(m) + if ( capture && pos.type_of_piece_on(move_to(m)) != PAWN && ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) - pos.midgame_value_of_piece_on(move_to(m)) == Value(0)) @@ -2221,7 +2226,7 @@ namespace { } if ( pvNode - && pos.move_is_capture(m) + && capture && pos.type_of_piece_on(move_to(m)) != PAWN && pos.see(m) >= 0) {