X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpawns.cpp;h=91da8a7b0858cf748e7ba57231aabfa93b6f238a;hp=b74f0659b24a371a92a6184ce5c73a50ea57ae7c;hb=52ae0efccffcce7f095cc4bae7bf90fe7a3b467b;hpb=97015afce834a68be4a955768caab7152834d7d8 diff --git a/src/pawns.cpp b/src/pawns.cpp index b74f0659..91da8a7b 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -51,17 +51,8 @@ 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) }}; - // Pawn chain membership bonus by file - const Score ChainMember[FILE_NB][RANK_NB] = { - { S(0, 0), S(14, 0), S(16, 4), S(18, 9), S(56, 56), S(104, 208), S(236, 472) }, - { S(0, 0), S(16, 0), S(18, 5), S(20, 10), S(60, 60), S(108, 216), S(240, 480) }, - { S(0, 0), S(16, 0), S(18, 5), S(20, 10), S(60, 60), S(108, 216), S(240, 480) }, - { S(0, 0), S(17, 0), S(19, 6), S(22, 11), S(66, 66), S(118, 236), S(254, 508) }, - { S(0, 0), S(17, 0), S(19, 6), S(22, 11), S(66, 66), S(118, 236), S(254, 508) }, - { S(0, 0), S(16, 0), S(18, 5), S(20, 10), S(60, 60), S(108, 216), S(240, 480) }, - { S(0, 0), S(16, 0), S(18, 5), S(20, 10), S(60, 60), S(108, 216), S(240, 480) }, - { S(0, 0), S(14, 0), S(16, 4), S(18, 9), S(56, 56), S(104, 208), S(236, 472) } - }; + // Pawn chain membership bonus by file and rank (initialized by formula) + Score ChainMember[FILE_NB][RANK_NB]; // Candidate passed pawn bonus by rank const Score CandidatePassed[RANK_NB] = { @@ -98,7 +89,6 @@ namespace { Bitboard b; Square s; File f; - Rank r; bool passed, isolated, doubled, opposed, chain, backward, candidate; Score value = SCORE_ZERO; const Square* pl = pos.list(Us); @@ -119,7 +109,6 @@ namespace { assert(pos.piece_on(s) == make_piece(Us, PAWN)); f = file_of(s); - r = relative_rank(Us, s); // This file cannot be semi-open e->semiopenFiles[Us] &= ~(1 << f); @@ -184,11 +173,11 @@ namespace { value -= Backward[opposed][f]; if (chain) - value += opposed ? ChainMember[f][r] / 2 : ChainMember[f][r]; + value += ChainMember[f][relative_rank(Us, s)]; if (candidate) { - value += CandidatePassed[r]; + value += CandidatePassed[relative_rank(Us, s)]; if (!doubled) e->candidatePawns[Us] |= s; @@ -202,6 +191,22 @@ namespace { namespace Pawns { +/// init() initializes some tables by formula instead of hard-code their values + +void init() { + + const int chainByFile[8] = { 1, 3, 3, 4, 4, 3, 3, 1 }; + int bonus; + + for (Rank r = RANK_1; r < RANK_8; ++r) + for (File f = FILE_A; f <= FILE_H; ++f) + { + bonus = r * (r-1) * (r-2) + chainByFile[f] * (r/2 + 1); + ChainMember[f][r] = make_score(bonus, bonus); + } +} + + /// probe() takes a position object 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. @@ -235,13 +240,13 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) { Rank rkUs, rkThem; File kf = std::max(FILE_B, std::min(FILE_G, file_of(ksq))); - for (int f = kf - 1; f <= kf + 1; ++f) + for (File f = kf - File(1); f <= kf + File(1); ++f) { - b = ourPawns & FileBB[f]; + b = ourPawns & file_bb(f); rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1; safety -= ShelterWeakness[rkUs]; - b = theirPawns & FileBB[f]; + b = theirPawns & file_bb(f); rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; safety -= StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem]; }