From: Steinar H. Gunderson Date: Thu, 18 Apr 2019 20:10:06 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=298cf150958212e3270182644fd87f5489823b27;hp=784e7d91455246361871f2f950dfb05e428c2c58 Merge remote-tracking branch 'upstream/master' --- diff --git a/src/bitboard.h b/src/bitboard.h index b1d961f4..6f99ef19 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -237,15 +237,13 @@ inline bool aligned(Square s1, Square s2, Square s3) { /// distance() functions return the distance between x and y, defined as the -/// number of steps for a king in x to reach y. Works with squares, ranks, files. +/// number of steps for a king in x to reach y. -template inline int distance(T x, T y) { return std::abs(x - y); } +template inline int distance(Square x, Square y); +template<> inline int distance(Square x, Square y) { return std::abs(file_of(x) - file_of(y)); } +template<> inline int distance(Square x, Square y) { return std::abs(rank_of(x) - rank_of(y)); } template<> inline int distance(Square x, Square y) { return SquareDistance[x][y]; } -template inline int distance(T2 x, T2 y); -template<> inline int distance(Square x, Square y) { return distance(file_of(x), file_of(y)); } -template<> inline int distance(Square x, Square y) { return distance(rank_of(x), rank_of(y)); } - template constexpr const T& clamp(const T& v, const T& lo, const T& hi) { return v < lo ? lo : v > hi ? hi : v; } diff --git a/src/endgame.cpp b/src/endgame.cpp index efc41a98..5958e633 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -635,8 +635,6 @@ ScaleFactor Endgame::operator()(const Position& pos) const { Square ksq = pos.square(weakSide); Square psq1 = pos.squares(strongSide)[0]; Square psq2 = pos.squares(strongSide)[1]; - Rank r1 = rank_of(psq1); - Rank r2 = rank_of(psq2); Square blockSq1, blockSq2; if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2)) @@ -670,7 +668,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && opposite_colors(ksq, wbsq) && ( bbsq == blockSq2 || (pos.attacks_from(blockSq2) & pos.pieces(weakSide, BISHOP)) - || distance(r1, r2) >= 2)) + || distance(psq1, psq2) >= 2)) return SCALE_FACTOR_DRAW; else if ( ksq == blockSq2 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7408a77c..566eba6d 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -328,7 +328,7 @@ namespace { // bishop, bigger when the center files are blocked with pawns. Bitboard blocked = pos.pieces(Us, PAWN) & shift(pos.pieces()); - score -= BishopPawns * pe->pawns_on_same_color_squares(Us, s) + score -= BishopPawns * pos.pawns_on_same_color_squares(Us, s) * (1 + popcount(blocked & CenterFiles)); // Bonus for bishop on a long diagonal which can "see" both center squares @@ -358,8 +358,8 @@ namespace { score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]); // Bonus for rook on an open or semi-open file - if (pe->semiopen_file(Us, file_of(s))) - score += RookOnFile[bool(pe->semiopen_file(Them, file_of(s)))]; + if (pos.semiopen_file(Us, file_of(s))) + score += RookOnFile[bool(pos.semiopen_file(Them, file_of(s)))]; // Penalty when trapped by the king, even more if the king cannot castle else if (mob <= 3) @@ -720,7 +720,7 @@ namespace { int bonus = popcount(safe) + popcount(behind & safe); int weight = pos.count(Us) - - 2 * popcount(pe->semiopenFiles[WHITE] & pe->semiopenFiles[BLACK]); + - (16 - pos.count()) / 4; Score score = make_score(bonus * weight * weight / 16, 0); diff --git a/src/movepick.cpp b/src/movepick.cpp index 86eb98aa..a70785e7 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -139,12 +139,12 @@ Move MovePicker::select(Pred filter) { if (T == Best) std::swap(*cur, *std::max_element(cur, endMoves)); - move = *cur++; + if (*cur != ttMove && filter()) + return *cur++; - if (move != ttMove && filter()) - return move; + cur++; } - return move = MOVE_NONE; + return MOVE_NONE; } /// MovePicker::next_move() is the most important method of the MovePicker class. It @@ -174,10 +174,10 @@ top: case GOOD_CAPTURE: if (select([&](){ - return pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)) ? + return pos.see_ge(*cur, Value(-55 * cur->value / 1024)) ? // Move losing capture to endBadCaptures to be tried later - true : (*endBadCaptures++ = move, false); })) - return move; + true : (*endBadCaptures++ = *cur, false); })) + return *(cur - 1); // Prepare the pointers to loop over the refutations array cur = std::begin(refutations); @@ -192,10 +192,10 @@ top: /* fallthrough */ case REFUTATION: - if (select([&](){ return move != MOVE_NONE - && !pos.capture(move) - && pos.pseudo_legal(move); })) - return move; + if (select([&](){ return *cur != MOVE_NONE + && !pos.capture(*cur) + && pos.pseudo_legal(*cur); })) + return *(cur - 1); ++stage; /* fallthrough */ @@ -210,10 +210,10 @@ top: case QUIET: if ( !skipQuiets - && select([&](){return move != refutations[0] - && move != refutations[1] - && move != refutations[2];})) - return move; + && select([&](){return *cur != refutations[0].move + && *cur != refutations[1].move + && *cur != refutations[2].move;})) + return *(cur - 1); // Prepare the pointers to loop over the bad captures cur = moves; @@ -237,12 +237,12 @@ top: return select([](){ return true; }); case PROBCUT: - return select([&](){ return pos.see_ge(move, threshold); }); + return select([&](){ return pos.see_ge(*cur, threshold); }); case QCAPTURE: if (select([&](){ return depth > DEPTH_QS_RECAPTURES - || to_sq(move) == recaptureSquare; })) - return move; + || to_sq(*cur) == recaptureSquare; })) + return *(cur - 1); // If we did not find any move and we do not try checks, we have finished if (depth != DEPTH_QS_CHECKS) diff --git a/src/movepick.h b/src/movepick.h index d9ecba99..e916514d 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -142,7 +142,6 @@ private: Move ttMove; ExtMove refutations[3], *cur, *endMoves, *endBadCaptures; int stage; - Move move; Square recaptureSquare; Value threshold; Depth depth; diff --git a/src/pawns.cpp b/src/pawns.cpp index 7edaa6e1..e2b26344 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -36,7 +36,7 @@ namespace { constexpr Score Isolated = S( 5, 15); // Connected pawn bonus - constexpr int Connected[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 }; + constexpr int Connected[RANK_NB] = { 0, 13, 17, 24, 59, 96, 171 }; // Strength of pawn shelter for our king by [distance from edge][rank]. // RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king. @@ -77,11 +77,8 @@ namespace { Bitboard theirPawns = pos.pieces(Them, PAWN); e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0; - e->semiopenFiles[Us] = 0xFF; e->kingSquares[Us] = SQ_NONE; e->pawnAttacks[Us] = pawn_attacks_bb(ourPawns); - e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares); - e->pawnsOnSquares[Us][WHITE] = pos.count(Us) - e->pawnsOnSquares[Us][BLACK]; // Loop through all pawns of the current color and score each pawn while ((s = *pl++) != SQ_NONE) @@ -89,8 +86,8 @@ namespace { assert(pos.piece_on(s) == make_piece(Us, PAWN)); File f = file_of(s); + Rank r = relative_rank(Us, s); - e->semiopenFiles[Us] &= ~(1 << f); e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s); // Flag the pawn @@ -117,8 +114,7 @@ namespace { && popcount(phalanx) >= popcount(leverPush)) e->passedPawns[Us] |= s; - else if ( stoppers == square_bb(s + Up) - && relative_rank(Us, s) >= RANK_5) + else if (stoppers == square_bb(s + Up) && r >= RANK_5) { b = shift(support) & ~theirPawns; while (b) @@ -129,8 +125,7 @@ namespace { // Score this pawn if (support | phalanx) { - int r = relative_rank(Us, s); - int v = phalanx ? Connected[r] + Connected[r + 1] : 2 * Connected[r]; + int v = (phalanx ? 3 : 2) * Connected[r]; v = 17 * popcount(support) + (v >> (opposed + 1)); score += make_score(v, v * (r - 2) / 4); } @@ -167,7 +162,6 @@ Entry* probe(const Position& pos) { e->key = key; e->scores[WHITE] = evaluate(pos, e); e->scores[BLACK] = evaluate(pos, e); - e->passedCount= popcount(e->passedPawns[WHITE] | e->passedPawns[BLACK]); return e; } diff --git a/src/pawns.h b/src/pawns.h index 71d18ee8..88b55545 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -38,15 +38,7 @@ struct Entry { Bitboard passed_pawns(Color c) const { return passedPawns[c]; } Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; } int weak_unopposed(Color c) const { return weakUnopposed[c]; } - int passed_count() const { return passedCount; } - - int semiopen_file(Color c, File f) const { - return semiopenFiles[c] & (1 << f); - } - - int pawns_on_same_color_squares(Color c, Square s) const { - return pawnsOnSquares[c][bool(DarkSquares & s)]; - } + int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }; template Score king_safety(const Position& pos) { @@ -69,9 +61,7 @@ struct Entry { Score kingSafety[COLOR_NB]; int weakUnopposed[COLOR_NB]; int castlingRights[COLOR_NB]; - int semiopenFiles[COLOR_NB]; int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares] - int passedCount; }; typedef HashTable Table; diff --git a/src/position.h b/src/position.h index 03c00148..1078e03e 100644 --- a/src/position.h +++ b/src/position.h @@ -95,6 +95,7 @@ public: template int count() const; template const Square* squares(Color c) const; template Square square(Color c) const; + int semiopen_file(Color c, File f) const; // Castling int castling_rights(Color c) const; @@ -128,6 +129,7 @@ public: // Piece specific bool pawn_passed(Color c, Square s) const; bool opposite_bishops() const; + int pawns_on_same_color_squares(Color c, Square s) const; // Doing and undoing moves void do_move(Move m, StateInfo& newSt); @@ -260,6 +262,10 @@ inline Square Position::ep_square() const { return st->epSquare; } +inline int Position::semiopen_file(Color c, File f) const { + return !(pieces(c, PAWN) & file_bb(f)); +} + inline bool Position::can_castle(CastlingRight cr) const { return st->castlingRights & cr; } @@ -318,6 +324,10 @@ inline bool Position::advanced_pawn_push(Move m) const { && relative_rank(sideToMove, from_sq(m)) > RANK_4; } +inline int Position::pawns_on_same_color_squares(Color c, Square s) const { + return popcount(pieces(c, PAWN) & ((DarkSquares & s) ? DarkSquares : ~DarkSquares)); +} + inline Key Position::key() const { return st->key; } diff --git a/src/search.cpp b/src/search.cpp index 645b1f9c..15e88ca4 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -623,9 +623,8 @@ namespace { if (!pos.capture_or_promotion(ttMove)) update_quiet_stats(pos, ss, ttMove, nullptr, 0, stat_bonus(depth)); - // Extra penalty for a quiet TT or main killer move in previous ply when it gets refuted - if ( ((ss-1)->moveCount == 1 || (ss-1)->currentMove == (ss-1)->killers[0]) - && !pos.captured_piece()) + // Extra penalty for early quiet moves of the previous ply + if ((ss-1)->moveCount <= 2 && !pos.captured_piece()) update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY)); } // Penalty for a quiet ttMove that fails low @@ -1227,8 +1226,7 @@ moves_loop: // When in check, search starts from here Thread* thisThread = pos.this_thread(); (ss+1)->ply = ss->ply + 1; - ss->currentMove = bestMove = MOVE_NONE; - ss->continuationHistory = &thisThread->continuationHistory[NO_PIECE][0]; + bestMove = MOVE_NONE; inCheck = pos.checkers(); moveCount = 0;