Skip to content

Commit

Permalink
Merge official-stockfish/master
Browse files Browse the repository at this point in the history
bench: 4756806
  • Loading branch information
ianfab committed Nov 17, 2019
2 parents 94bbcff + 3468138 commit 6775c7e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 52 deletions.
19 changes: 11 additions & 8 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace {
constexpr Score PassedRank[RANK_NB] = {
S(0, 0), S(10, 28), S(17, 33), S(15, 41), S(62, 72), S(168, 177), S(276, 260)
};

// OutpostRank[Rank] contains a bonus according to the rank of the outpost
constexpr Score OutpostRank[RANK_NB] = {
S(0, 0), S(0, 0), S(0, 0), S(28, 18), S(30, 24), S(32, 19)
Expand Down Expand Up @@ -464,7 +464,7 @@ namespace {
if (!pos.count<KING>(Us) || !pos.checking_permitted())
return SCORE_ZERO;

Bitboard weak, b1, b2, safe, unsafeChecks = 0;
Bitboard weak, b1, b2, b3, safe, unsafeChecks = 0;
Bitboard queenChecks, knightChecks, pawnChecks, otherChecks;
int kingDanger = 0;
const Square ksq = pos.square<KING>(Us);
Expand Down Expand Up @@ -542,12 +542,14 @@ namespace {
Square s = file_of(ksq) == FILE_A ? ksq + EAST : file_of(ksq) == pos.max_file() ? ksq + WEST : ksq;
Bitboard kingFlank = pos.max_file() == FILE_H ? KingFlank[file_of(ksq)] : file_bb(s) | adjacent_files_bb(s);

// Find the squares that opponent attacks in our king flank, and the squares
// which are attacked twice in that flank.
// Find the squares that opponent attacks in our king flank, the squares
// which they attack twice in that flank, and the squares that we defend.
b1 = attackedBy[Them][ALL_PIECES] & kingFlank & Camp;
b2 = b1 & attackedBy2[Them];
b3 = attackedBy[Us][ALL_PIECES] & kingFlank & Camp;

int kingFlankAttacks = popcount(b1) + popcount(b2);
int kingFlankAttack = popcount(b1) + popcount(b2);
int kingFlankDefense = popcount(b3);

kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
+ kingAttackersCountInHand[Them] * kingAttackersWeight[Them]
Expand All @@ -556,7 +558,8 @@ namespace {
+ 148 * popcount(unsafeChecks)
+ 98 * popcount(pos.blockers_for_king(Us))
+ 69 * kingAttacksCount[Them] * (2 + 8 * pos.check_counting() + pos.captures_to_hand()) / 2
+ 3 * kingFlankAttacks * kingFlankAttacks / 8
+ 4 * (kingFlankAttack - kingFlankDefense)
+ 3 * kingFlankAttack * kingFlankAttack / 8
+ mg_value(mobility[Them] - mobility[Us])
- 873 * !(pos.major_pieces(Them) || pos.captures_to_hand() || pos.xiangqi_general()) / (1 + pos.check_counting())
- 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
Expand All @@ -572,8 +575,8 @@ namespace {
if (!(pos.pieces(PAWN) & kingFlank))
score -= PawnlessFlank;

// King tropism bonus, to anticipate slow motion attacks on our king
score -= FlankAttacks * kingFlankAttacks * (1 + 5 * pos.captures_to_hand() + pos.check_counting());
// Penalty if king flank is under attack, potentially moving toward the king
score -= FlankAttacks * kingFlankAttack * (1 + 5 * pos.captures_to_hand() + pos.check_counting());

if (pos.check_counting())
score += make_score(0, mg_value(score) / 2);
Expand Down
91 changes: 47 additions & 44 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,51 @@ namespace {
movedPiece = pos.moved_piece(move);
givesCheck = pos.gives_check(move);

// Step 13. Extensions (~70 Elo)
// Calculate new depth for this move
newDepth = depth - 1;

// Step 13. Pruning at shallow depth (~170 Elo)
if ( !rootNode
&& (pos.non_pawn_material(us) || !(pos.pieces(us) ^ pos.pieces(us, PAWN)))
&& bestValue > VALUE_MATED_IN_MAX_PLY)
{
// Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
moveCountPruning = moveCount >= futility_move_count(improving, depth)
|| (pos.must_capture() && (moveCountPruning || (pos.capture(move) && pos.legal(move))));

if ( !captureOrPromotion
&& !givesCheck
&& (!pos.must_capture() || !pos.attackers_to(to_sq(move), ~us))
&& (!PvNode || !pos.advanced_pawn_push(move) || pos.non_pawn_material(~us) > BishopValueMg || pos.count<ALL_PIECES>(us) == pos.count<PAWN>(us)))
{
// Reduced depth of the next LMR search
int lmrDepth = std::max(newDepth - reduction(improving, depth, moveCount), 0);

// Countermoves based pruning (~20 Elo)
if ( lmrDepth < 4 + ((ss-1)->statScore > 0 || (ss-1)->moveCount == 1)
&& (*contHist[0])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold
&& (*contHist[1])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold)
continue;

// Futility pruning: parent node (~2 Elo)
if ( lmrDepth < 6
&& !inCheck
&& !( pos.extinction_value() == -VALUE_MATE
&& pos.extinction_piece_types().find(ALL_PIECES) == pos.extinction_piece_types().end())
&& ss->staticEval + 250 + 211 * lmrDepth <= alpha)
continue;

// Prune moves with negative SEE (~10 Elo)
if (!pos.must_capture() && !pos.see_ge(move, Value(-(31 - std::min(lmrDepth, 18)) * lmrDepth * lmrDepth)))
continue;
}
else if ( !(givesCheck && extension)
&& !pos.must_capture()
&& !pos.see_ge(move, Value(-199 - 120 * pos.captures_to_hand()) * depth)) // (~20 Elo)
continue;
}

// Step 14. Extensions (~70 Elo)

// Singular extension search (~60 Elo). If all moves but one fail low on a
// search of (alpha-s, beta-s), and just one fails high on (alpha, beta),
Expand Down Expand Up @@ -1051,49 +1095,8 @@ namespace {
&& MoveList<CAPTURES>(pos).size() == 1)
extension = 1;

// Calculate new depth for this move
newDepth = depth - 1 + extension;

// Step 14. Pruning at shallow depth (~170 Elo)
if ( !rootNode
&& (pos.non_pawn_material(us) || !(pos.pieces(us) ^ pos.pieces(us, PAWN)))
&& bestValue > VALUE_MATED_IN_MAX_PLY)
{
// Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
moveCountPruning = moveCount >= futility_move_count(improving, depth)
|| (pos.must_capture() && (moveCountPruning || (pos.capture(move) && pos.legal(move))));

if ( !captureOrPromotion
&& !givesCheck
&& (!pos.must_capture() || !pos.attackers_to(to_sq(move), ~us))
&& (!PvNode || !pos.advanced_pawn_push(move) || pos.non_pawn_material(~us) > BishopValueMg || pos.count<ALL_PIECES>(us) == pos.count<PAWN>(us)))
{
// Reduced depth of the next LMR search
int lmrDepth = std::max(newDepth - reduction(improving, depth, moveCount), 0);

// Countermoves based pruning (~20 Elo)
if ( lmrDepth < 4 + ((ss-1)->statScore > 0 || (ss-1)->moveCount == 1)
&& (*contHist[0])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold
&& (*contHist[1])[history_slot(movedPiece)][to_sq(move)] < CounterMovePruneThreshold)
continue;

// Futility pruning: parent node (~2 Elo)
if ( lmrDepth < 6
&& !inCheck
&& !( pos.extinction_value() == -VALUE_MATE
&& pos.extinction_piece_types().find(ALL_PIECES) == pos.extinction_piece_types().end())
&& ss->staticEval + 250 + 211 * lmrDepth <= alpha)
continue;

// Prune moves with negative SEE (~10 Elo)
if (!pos.must_capture() && !pos.see_ge(move, Value(-(31 - std::min(lmrDepth, 18)) * lmrDepth * lmrDepth)))
continue;
}
else if ( !(givesCheck && extension)
&& !pos.must_capture()
&& !pos.see_ge(move, Value(-199 - 120 * pos.captures_to_hand()) * depth)) // (~20 Elo)
continue;
}
// Add extension to new depth
newDepth += extension;

// Speculative prefetch as early as possible
prefetch(TT.first_entry(pos.key_after(move)));
Expand Down

0 comments on commit 6775c7e

Please sign in to comment.