From cb4bda0f4974c75733c41b15bff7624a65e6cee1 Mon Sep 17 00:00:00 2001 From: protonspring Date: Sun, 6 May 2018 09:42:49 +0200 Subject: [PATCH] Simplify the backward pawns code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The two lines of code in the patch seem to be just as good as master. 1. We now only look at the current square to see if it is currently backward, whereas master looks there AND further ahead in the current file (master would declare a pawn "backward" even though it could still safely advance a little). This simplification allows us to avoid the use of the difficult logic with `backmost_sq(Us, neighbours | stoppers)`. 2. The condition `relative_rank(Us,s) < RANK_5` is simplified away. Passed STC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 68132 W: 14025 L: 13992 D: 40115 http://tests.stockfishchess.org/tests/view/5aedc97a0ebc5902a4099fd6 Passed LTC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 23789 W: 3643 L: 3527 D: 16619 http://tests.stockfishchess.org/tests/view/5aee4f970ebc5902a409a03a Ideas for further work: • The new code flags some pawns on the 5th rank as backward, which was not the case in the old master. So maybe we should test a version with that included? • Further tweaks of the backward condition with [0..5] bounds? Closes https://github.com/official-stockfish/Stockfish/pull/1583 Bench: 5122789 --- src/pawns.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/pawns.cpp b/src/pawns.cpp index 6623ab71..ca9c3023 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -116,22 +116,10 @@ namespace { phalanx = neighbours & rank_bb(s); supported = neighbours & rank_bb(s - Up); - // A pawn is backward when it is behind all pawns of the same color on the - // adjacent files and cannot be safely advanced. - if (!neighbours || lever || relative_rank(Us, s) >= RANK_5) - backward = false; - else - { - // Find the backmost rank with neighbours or stoppers - b = rank_bb(backmost_sq(Us, neighbours | stoppers)); - - // The pawn is backward when it cannot safely progress to that rank: - // either there is a stopper in the way on this rank, or there is a - // stopper on adjacent file which controls the way to that rank. - backward = (b | shift(b & adjacent_files_bb(f))) & stoppers; - - assert(!(backward && (forward_ranks_bb(Them, s + Up) & neighbours))); - } + // A pawn is backward when it is behind all pawns of the same color + // on the adjacent files and cannot be safely advanced. + backward = !lever && !(ourPawns & pawn_attack_span(Them, s + Up)) + && (stoppers & (leverPush | (s + Up))); // Passed pawns will be properly scored in evaluation because we need // full attack info to evaluate them. Include also not passed pawns -- 2.39.2