X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fpawns.cpp;h=91da8a7b0858cf748e7ba57231aabfa93b6f238a;hb=eed508b4445057cd26bfb95ab5cd754ac96629fd;hp=d65b0418f0145f448c3d37dff8ecb7262c86fdaf;hpb=457ac26de5e2925c87bdc0169478d138074c50f8;p=stockfish diff --git a/src/pawns.cpp b/src/pawns.cpp index d65b0418..91da8a7b 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -51,11 +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] = { - S(11,-1), S(13,-1), S(13,-1), S(14,-1), - S(14,-1), S(13,-1), S(13,-1), S(11,-1) - }; + // 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] = { @@ -99,7 +96,7 @@ namespace { Bitboard ourPawns = pos.pieces(Us, PAWN); Bitboard theirPawns = pos.pieces(Them, PAWN); - e->passedPawns[Us] = 0; + e->passedPawns[Us] = e->candidatePawns[Us] = 0; e->kingSquares[Us] = SQ_NONE; e->semiopenFiles[Us] = 0xFF; e->pawnAttacks[Us] = shift_bb(ourPawns) | shift_bb(ourPawns); @@ -176,10 +173,15 @@ namespace { value -= Backward[opposed][f]; if (chain) - value += ChainMember[f]; + value += ChainMember[f][relative_rank(Us, s)]; if (candidate) + { value += CandidatePassed[relative_rank(Us, s)]; + + if (!doubled) + e->candidatePawns[Us] |= s; + } } return value; @@ -189,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. @@ -222,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]; }