X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpawns.cpp;h=3634f95746796afef7ab904856629b59d2c970fa;hp=4693e1584f5b2161573fd42ff19643791feeef20;hb=d3091971b789b4be4c56fdf608eae33c5c54bbd4;hpb=069073ea6882ccb27fe4b571ed08ebe6a4ad8c65 diff --git a/src/pawns.cpp b/src/pawns.cpp index 4693e158..3634f957 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -49,17 +49,14 @@ namespace { { S(20, 28), S(29, 31), S(33, 31), S(33, 31), S(33, 31), S(33, 31), S(29, 31), S(20, 28) } }; - // Connected bonus by rank - const int Connected[RANK_NB] = {0, 6, 15, 10, 57, 75, 135, 258}; + // Connected pawn bonus by opposed, phalanx flags and rank + Score Connected[2][2][RANK_NB]; // Levers bonus by rank const Score Lever[RANK_NB] = { S( 0, 0), S( 0, 0), S(0, 0), S(0, 0), S(20,20), S(40,40), S(0, 0), S(0, 0) }; - // Bonus for file distance of the two outermost pawns - const Score PawnsFileSpan = S(0, 15); - // Unsupported pawn penalty const Score UnsupportedPawnPenalty = S(20, 10); @@ -89,9 +86,9 @@ namespace { const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW); const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE); - Bitboard b, p, doubled; + Bitboard b, p, doubled, connected; Square s; - bool passed, isolated, opposed, connected, backward, unsupported, lever; + bool passed, isolated, opposed, phalanx, backward, unsupported, lever; Score value = SCORE_ZERO; const Square* pl = pos.list(Us); const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)]; @@ -111,7 +108,6 @@ namespace { { assert(pos.piece_on(s) == make_piece(Us, PAWN)); - Rank r = rank_of(s), rr = relative_rank(Us, s); File f = file_of(s); // This file cannot be semi-open @@ -120,12 +116,10 @@ namespace { // Previous rank p = rank_bb(s - pawn_push(Us)); - // Our rank plus previous one - b = rank_bb(s) | p; - // Flag the pawn as passed, isolated, doubled, // unsupported or connected (but not the backward one). - connected = ourPawns & adjacent_files_bb(f) & b; + connected = ourPawns & adjacent_files_bb(f) & (rank_bb(s) | p); + phalanx = connected & rank_bb(s); unsupported = !(ourPawns & adjacent_files_bb(f) & p); isolated = !(ourPawns & adjacent_files_bb(f)); doubled = ourPawns & forward_bb(Us, s); @@ -176,24 +170,16 @@ namespace { if (backward) value -= Backward[opposed][f]; - if (connected) { - int bonus = Connected[rr]; - if (ourPawns & adjacent_files_bb(f) & rank_bb(r)) - bonus += (Connected[rr+1] - Connected[rr]) / 2; - value += make_score(bonus / 2, bonus >> opposed); - } + if (connected) + value += Connected[opposed][phalanx][relative_rank(Us, s)]; if (lever) - value += Lever[rr]; + value += Lever[relative_rank(Us, s)]; } b = e->semiopenFiles[Us] ^ 0xFF; e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0; - // In endgame it's better to have pawns on both wings. So give a bonus according - // to file distance between left and right outermost pawns. - value += PawnsFileSpan * e->pawnSpan[Us]; - return value; } @@ -201,6 +187,24 @@ namespace { namespace Pawns { +/// init() initializes some tables used by evaluation. Instead of 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 const int Seed[RANK_NB] = { 0, 6, 15, 10, 57, 75, 135, 258 }; + + for (int opposed = 0; opposed <= 1; ++opposed) + for (int phalanx = 0; phalanx <= 1; ++phalanx) + for (Rank r = RANK_2; r < RANK_8; ++r) + { + int bonus = Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0); + Connected[opposed][phalanx][r] = make_score(bonus / 2, bonus >> opposed); + } +} + + /// probe() takes a position as input, computes a Entry object, and returns a /// pointer to it. The result is also stored in a hash table, so we don't have /// to recompute everything when the same pawn structure occurs again.