From: protonspring Date: Wed, 18 Apr 2018 18:03:37 +0000 (+0200) Subject: Simplify BlockedByKing in pawn storms X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=f7cc0026e3291cd281d2e3975a5f01f63be162aa Simplify BlockedByKing in pawn storms This patch is non-functional. Current master does four operations to determine whether an enemy pawn on this file is blocked by the king or not ``` f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ) ``` By adding a direction (based on the template color), this is reduced to two operations. This works because b is limited to enemy pawns that are ahead of the king and on the current file. ``` shift(b) & ksq ``` I've added a line of code, but the number of executing instructions is reduced (I think). I'm not sure if this counts as a simplification, but it should theoretically be a little faster (barely). The code line length is also reduced making it a little easier to read. Closes https://github.com/official-stockfish/Stockfish/pull/1552 No functional change. --- diff --git a/src/pawns.cpp b/src/pawns.cpp index 7b3dd818..d2ef33e6 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -236,7 +236,8 @@ Entry* probe(const Position& pos) { template Value Entry::shelter_storm(const Position& pos, Square ksq) { - constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH); enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked }; @@ -257,9 +258,9 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) { int d = std::min(f, ~f); safety -= ShelterWeakness[f == file_of(ksq)][d][rkUs] + StormDanger - [f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing : - rkUs == RANK_1 ? Unopposed : - rkThem == rkUs + 1 ? BlockedByPawn : Unblocked] + [(shift(b) & ksq) ? BlockedByKing : + rkUs == RANK_1 ? Unopposed : + rkThem == (rkUs + 1) ? BlockedByPawn : Unblocked] [d][rkThem]; }