X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpawns.cpp;h=4c2ff3913d50faecad5cbc081e5e6b27428cb45a;hp=c581c8e72e90fa7ef4ac64408b1fa56405b1d21b;hb=76777b663a5f5a2dcfaafa19c15d02d11c401bdf;hpb=eb6d7f537d214c4dc8bde7d4fdc2aaead47dd3c3 diff --git a/src/pawns.cpp b/src/pawns.cpp index c581c8e7..4c2ff391 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -18,7 +18,6 @@ along with this program. If not, see . */ -#include #include #include "bitboard.h" @@ -36,8 +35,8 @@ namespace { constexpr Score Doubled = S(11, 56); constexpr Score Isolated = S( 5, 15); - // Connected pawn bonus by opposed, phalanx, #support and rank - Score Connected[2][2][3][RANK_NB]; + // Connected pawn bonus + 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. @@ -78,7 +77,6 @@ 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); @@ -90,13 +88,13 @@ 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 opposed = theirPawns & forward_file_bb(Us, s); - stoppers = theirPawns & passed_pawn_mask(Us, s); + stoppers = theirPawns & passed_pawn_span(Us, s); lever = theirPawns & PawnAttacks[Us][s]; leverPush = theirPawns & PawnAttacks[Us][s + Up]; doubled = ourPawns & (s - Up); @@ -114,12 +112,11 @@ namespace { // which could become passed after one or two pawn pushes when are // not attacked more times than defended. if ( !(stoppers ^ lever ^ leverPush) - && popcount(support) >= popcount(lever) - 1 + && (support || !more_than_one(lever)) && popcount(phalanx) >= popcount(leverPush)) e->passedPawns[Us] |= s; - else if ( stoppers == SquareBB[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 +126,11 @@ namespace { // Score this pawn if (support | phalanx) - score += Connected[opposed][bool(phalanx)][popcount(support)][relative_rank(Us, s)]; - + { + int v = (phalanx ? 3 : 2) * Connected[r]; + v = 17 * popcount(support) + (v >> (opposed + 1)); + score += make_score(v, v * (r - 2) / 4); + } else if (!neighbours) score -= Isolated, e->weakUnopposed[Us] += !opposed; @@ -148,27 +148,6 @@ namespace { namespace Pawns { -/// Pawns::init() initializes some tables needed by evaluation. Instead of using -/// hard-coded tables, when makes sense, we prefer to calculate them with a formula -/// to reduce independent parameters and to allow easier tuning and better insight. - -void init() { - - static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 }; - - for (int opposed = 0; opposed <= 1; ++opposed) - for (int phalanx = 0; phalanx <= 1; ++phalanx) - for (int support = 0; support <= 2; ++support) - for (Rank r = RANK_2; r < RANK_8; ++r) - { - int v = 17 * support; - v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed; - - Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4); - } -} - - /// Pawns::probe() looks up the current position's pawns configuration in /// the pawns hash table. It returns a pointer to the Entry if the position /// is found. Otherwise a new Entry is computed and stored there, so we don't @@ -185,8 +164,6 @@ Entry* probe(const Position& pos) { e->key = key; e->scores[WHITE] = evaluate(pos, e); e->scores[BLACK] = evaluate(pos, e); - e->asymmetry = popcount( (e->passedPawns[WHITE] | e->passedPawns[BLACK]) - | (e->semiopenFiles[WHITE] ^ e->semiopenFiles[BLACK])); return e; } @@ -209,7 +186,7 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) { Value safety = (shift(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ? Value(374) : Value(5); - File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq))); + File center = clamp(file_of(ksq), FILE_B, FILE_G); for (File f = File(center - 1); f <= File(center + 1); ++f) { b = ourPawns & file_bb(f);