X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpawns.cpp;h=401977bdf52980975576ece727f5fe824140bc4d;hp=aa3139e27a7b65fe7af7b986437134d93e0ca5de;hb=15e21911110f9d459c4fef2bb17903d97345d0b9;hpb=3c1201c20c6adceceff764a56aa80e615ca80c64 diff --git a/src/pawns.cpp b/src/pawns.cpp index aa3139e2..401977bd 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -57,7 +57,7 @@ namespace { S( 0, 0), S( 6, 13), S(6,13), S(14,29), S(34,68), S(83,166), S(0, 0), S( 0, 0) }; - // Levers bonus by rank + // 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) }; @@ -74,7 +74,7 @@ namespace { // Danger of enemy pawns moving toward our king indexed by // [no friendly pawn | pawn unblocked | pawn blocked][rank of enemy pawn] - const Value StormDanger[3][RANK_NB] = { + const Value StormDanger[][RANK_NB] = { { V( 0), V(64), V(128), V(51), V(26) }, { V(26), V(32), V( 96), V(38), V(20) }, { V( 0), V( 0), V(160), V(25), V(13) } }; @@ -102,7 +102,7 @@ namespace { const Square* pl = pos.list(Us); const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)]; - Bitboard ourPawns = pos.pieces(Us, PAWN); + Bitboard ourPawns = pos.pieces(Us , PAWN); Bitboard theirPawns = pos.pieces(Them, PAWN); e->passedPawns[Us] = e->candidatePawns[Us] = 0; @@ -193,7 +193,7 @@ namespace { value += Connected[f][relative_rank(Us, s)]; if (lever) - value += Lever[relative_rank(Us, s)]; + value += Lever[relative_rank(Us, s)]; if (candidate) { @@ -204,13 +204,12 @@ namespace { } } + 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. - if (pos.count(Us) > 1) - { - b = e->semiopenFiles[Us] ^ 0xFF; - value += PawnsFileSpan * int(msb(b) - lsb(b)); - } + value += PawnsFileSpan * e->pawnSpan[Us]; return value; } @@ -223,20 +222,19 @@ namespace Pawns { void init() { - const int bonusesByFile[8] = { 1, 3, 3, 4, 4, 3, 3, 1 }; - int bonus; + const int bonusByFile[] = { 1, 3, 3, 4, 4, 3, 3, 1 }; for (Rank r = RANK_1; r < RANK_8; ++r) for (File f = FILE_A; f <= FILE_H; ++f) { - bonus = r * (r-1) * (r-2) + bonusesByFile[f] * (r/2 + 1); + int bonus = r * (r - 1) * (r - 2) + bonusByFile[f] * (r / 2 + 1); Connected[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 +/// 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. Entry* probe(const Position& pos, Table& entries) { @@ -260,30 +258,30 @@ template Value Entry::shelter_storm(const Position& pos, Square ksq) { const Color Them = (Us == WHITE ? BLACK : WHITE); - static const Bitboard MiddleEdges = (FileABB | FileHBB) & (Rank2BB | Rank3BB); + const Bitboard Edges = (FileABB | FileHBB) & (Rank2BB | Rank3BB); - Value safety = MaxSafetyBonus; Bitboard b = pos.pieces(PAWN) & (in_front_bb(Us, rank_of(ksq)) | rank_bb(ksq)); Bitboard ourPawns = b & pos.pieces(Us); Bitboard theirPawns = b & pos.pieces(Them); - Rank rkUs, rkThem; + Value safety = MaxSafetyBonus; File kf = std::max(FILE_B, std::min(FILE_G, file_of(ksq))); for (File f = kf - File(1); f <= kf + File(1); ++f) { b = ourPawns & file_bb(f); - rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1; + Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1; b = theirPawns & file_bb(f); - rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; + Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; - if ( (MiddleEdges & make_square(f, rkThem)) + if ( (Edges & make_square(f, rkThem)) && file_of(ksq) == f && relative_rank(Us, ksq) == rkThem - 1) safety += 200; else - safety -= ShelterWeakness[rkUs] - + StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem]; + safety -= ShelterWeakness[rkUs] + + StormDanger[rkUs == RANK_1 ? 0 : + rkThem != rkUs + 1 ? 1 : 2][rkThem]; } return safety;