Skip to content

Commit 29b5842

Browse files
Rocky640zamar
authored andcommitted
Backward simplication
On top of the usual conditions a) some opponent in front (but no lever) b) some neighbours (in front) (but no neighbour behind or same rank) c) < rank_5 to find out if a pawn is backward we look at the squares in front of this pawn to reach the same rank as the next neighbour. In current master, a pawn is backward if any of those squares is controlled by an enemy pawn on an adjacent file In this version, a pawn is ALSO backward if any of those squares is occupied by an enemy pawn. STC: http://tests.stockfishchess.org/tests/view/56fe7efd0ebc59301a3541f1 LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 19051 W: 3557 L: 3433 D: 12061 LTC: http://tests.stockfishchess.org/tests/view/56febc2d0ebc59301a354209 LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 40810 W: 5619 L: 5526 D: 29665 Bench: 7525245 Resolves #614
1 parent 8fb45ca commit 29b5842

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/pawns.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ namespace {
9999
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
100100
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
101101

102-
Bitboard b, neighbours, doubled, supported, phalanx;
102+
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
103103
Square s;
104-
bool passed, isolated, opposed, backward, lever, connected;
104+
bool opposed, lever, connected, backward;
105105
Score score = SCORE_ZERO;
106106
const Square* pl = pos.squares<PAWN>(Us);
107107
const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
@@ -127,55 +127,47 @@ namespace {
127127
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
128128

129129
// Flag the pawn
130-
neighbours = ourPawns & adjacent_files_bb(f);
131-
doubled = ourPawns & forward_bb(Us, s);
132-
opposed = theirPawns & forward_bb(Us, s);
133-
passed = !(theirPawns & passed_pawn_mask(Us, s));
134-
lever = theirPawns & pawnAttacksBB[s];
135-
phalanx = neighbours & rank_bb(s);
136-
supported = neighbours & rank_bb(s - Up);
137-
connected = supported | phalanx;
138-
isolated = !neighbours;
139-
140-
// Test for backward pawn.
141-
// If the pawn is passed, isolated, lever or connected it cannot be
142-
// backward. If there are friendly pawns behind on adjacent files
143-
// or if it is sufficiently advanced, it cannot be backward either.
144-
if ( (passed | isolated | lever | connected)
145-
|| (ourPawns & pawn_attack_span(Them, s))
146-
|| (relative_rank(Us, s) >= RANK_5))
130+
opposed = theirPawns & forward_bb(Us, s);
131+
stoppers = theirPawns & passed_pawn_mask(Us, s);
132+
lever = theirPawns & pawnAttacksBB[s];
133+
doubled = ourPawns & forward_bb(Us, s);
134+
neighbours = ourPawns & adjacent_files_bb(f);
135+
phalanx = neighbours & rank_bb(s);
136+
supported = neighbours & rank_bb(s - Up);
137+
connected = supported | phalanx;
138+
139+
// A pawn is backward when it is behind all pawns of the same color on the
140+
// adjacent files and cannot be safely advanced.
141+
if (!neighbours || lever || relative_rank(Us, s) >= RANK_5)
147142
backward = false;
148143
else
149144
{
150-
// We now know there are no friendly pawns beside or behind this
151-
// pawn on adjacent files. We now check whether the pawn is
152-
// backward by looking in the forward direction on the adjacent
153-
// files, and picking the closest pawn there.
154-
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
155-
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));
156-
157-
// If we have an enemy pawn in the same or next rank, the pawn is
158-
// backward because it cannot advance without being captured.
159-
backward = (b | shift_bb<Up>(b)) & theirPawns;
145+
// Find the backmost rank with neighbours or stoppers
146+
b = rank_bb(backmost_sq(Us, neighbours | stoppers));
147+
148+
// The pawn is backward when it cannot safely progress to that rank:
149+
// either there is a stopper in the way on this rank, or there is a
150+
// stopper on adjacent file which controls the way to that rank.
151+
backward = (b | shift_bb<Up>(b & adjacent_files_bb(f))) & stoppers;
152+
153+
assert(!backward || !(pawn_attack_span(Them, s + Up) & neighbours));
160154
}
161155

162-
assert(opposed | passed | (pawn_attack_span(Us, s) & theirPawns));
163-
164156
// Passed pawns will be properly scored in evaluation because we need
165157
// full attack info to evaluate them. Only the frontmost passed
166158
// pawn on each file is considered a true passed pawn.
167-
if (passed && !doubled)
159+
if (!(stoppers | doubled))
168160
e->passedPawns[Us] |= s;
169161

170162
// Score this pawn
171-
if (isolated)
163+
if (!neighbours)
172164
score -= Isolated[opposed][f];
173165

174166
else if (backward)
175167
score -= Backward[opposed];
176168

177169
else if (!supported)
178-
score -= Unsupported[more_than_one(neighbours & rank_bb(s + Up))];
170+
score -= Unsupported[more_than_one(neighbours & pawnAttacksBB[s])];
179171

180172
if (connected)
181173
score += Connected[opposed][!!phalanx][more_than_one(supported)][relative_rank(Us, s)];

0 commit comments

Comments
 (0)