Skip to content

Commit 33c3a04

Browse files
Rocky640snicolet
authored andcommitted
Pawn clean up
Non functional simplification when we find the passed pawns in pawn.cpp and some code clean up. It also better follows the pattern "flag the pawn" and "score the pawn". ------------------------- The idea behind the third condition for candidate passed pawn is a little bit difficult to visualize. Just for the record, the idea is the following: Consider White e5 d4 against black e6. d4 can (in some endgames) push to d5 and lever e6. Thanks to this sacrifice, or after d5xe6, we consider e5 as "passed". However: - if White e5/d4 against black e6/c6: d4 cannot safely push to d5 since d5 is double attacked; - if White e5/d4 against black e6/d5: d4 cannot safely push to d5 since it is occupied. This is exactly what the following expression does: ``` && (shift<Up>(support) & ~(theirPawns | dblAttackThem))) ``` -------------------------- http://tests.stockfishchess.org/tests/view/5d3325bb0ebc5925cf0e6e91 LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 124666 W: 27586 L: 27669 D: 69411 Closes #2255 No functional change
1 parent dc243a3 commit 33c3a04

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/pawns.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace {
3535
constexpr Score Backward = S( 9, 24);
3636
constexpr Score Doubled = S(11, 56);
3737
constexpr Score Isolated = S( 5, 15);
38+
constexpr Score WeakLever = S( 0, 56);
3839
constexpr Score WeakUnopposed = S(13, 27);
39-
constexpr Score Attacked2Unsupported = S(0, 56);
4040

4141
// Connected pawn bonus
4242
constexpr int Connected[RANK_NB] = { 0, 7, 8, 12, 29, 48, 86 };
@@ -73,13 +73,15 @@ namespace {
7373
Bitboard b, neighbours, stoppers, doubled, support, phalanx;
7474
Bitboard lever, leverPush;
7575
Square s;
76-
bool opposed, backward;
76+
bool opposed, backward, passed;
7777
Score score = SCORE_ZERO;
7878
const Square* pl = pos.squares<PAWN>(Us);
7979

8080
Bitboard ourPawns = pos.pieces( Us, PAWN);
8181
Bitboard theirPawns = pos.pieces(Them, PAWN);
8282

83+
Bitboard doubleAttackThem = pawn_double_attacks_bb<Them>(theirPawns);
84+
8385
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0;
8486
e->kingSquares[Us] = SQ_NONE;
8587
e->pawnAttacks[Us] = pawn_attacks_bb<Us>(ourPawns);
@@ -109,22 +111,21 @@ namespace {
109111
backward = !(neighbours & forward_ranks_bb(Them, s))
110112
&& (stoppers & (leverPush | (s + Up)));
111113

112-
// Passed pawns will be properly scored in evaluation because we need
113-
// full attack info to evaluate them. Include also not passed pawns
114-
// which could become passed after one or two pawn pushes when they
115-
// are not attacked more times than defended.
116-
if ( !(stoppers ^ lever) ||
117-
(!(stoppers ^ leverPush) && popcount(phalanx) >= popcount(leverPush)))
114+
// A pawn is passed if one of the three following conditions is true:
115+
// (a) there is no stoppers except some levers
116+
// (b) the only stoppers are the leverPush, but we outnumber them
117+
// (c) there is only one front stopper which can be levered.
118+
passed = !(stoppers ^ lever)
119+
|| ( !(stoppers ^ leverPush)
120+
&& popcount(phalanx) >= popcount(leverPush))
121+
|| ( stoppers == square_bb(s + Up) && r >= RANK_5
122+
&& (shift<Up>(support) & ~(theirPawns | doubleAttackThem)));
123+
124+
// Passed pawns will be properly scored later in evaluation when we have
125+
// full attack info.
126+
if (passed)
118127
e->passedPawns[Us] |= s;
119128

120-
else if (stoppers == square_bb(s + Up) && r >= RANK_5)
121-
{
122-
b = shift<Up>(support) & ~theirPawns;
123-
while (b)
124-
if (!more_than_one(theirPawns & PawnAttacks[Us][pop_lsb(&b)]))
125-
e->passedPawns[Us] |= s;
126-
}
127-
128129
// Score this pawn
129130
if (support | phalanx)
130131
{
@@ -144,11 +145,11 @@ namespace {
144145
score -= Doubled;
145146
}
146147

147-
// Unsupported friendly pawns attacked twice by the enemy
148-
score -= Attacked2Unsupported * popcount( ourPawns
149-
& pawn_double_attacks_bb<Them>(theirPawns)
150-
& ~pawn_attacks_bb<Us>(ourPawns)
151-
& ~e->passedPawns[Us]);
148+
// Penalize the unsupported and non passed pawns attacked twice by the enemy
149+
b = ourPawns
150+
& doubleAttackThem
151+
& ~(e->pawnAttacks[Us] | e->passedPawns[Us]);
152+
score -= WeakLever * popcount(b);
152153

153154
return score;
154155
}

src/search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ namespace {
11521152
: -stat_bonus(newDepth);
11531153

11541154
if (move == ss->killers[0])
1155-
bonus += bonus / 4;
1155+
bonus += bonus / 4;
11561156

11571157
update_continuation_histories(ss, movedPiece, to_sq(move), bonus);
11581158
}

0 commit comments

Comments
 (0)