From 52f92d05a9eae0cc68a3cd157f8df35802a98297 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ste=CC=81phane=20Nicolet?= Date: Wed, 21 Feb 2018 22:31:38 +0100 Subject: [PATCH] Move pawn_attacks_bb() helper to bitboard.h No functional change. --- src/bitboard.h | 8 ++++++++ src/evaluate.cpp | 4 ++-- src/pawns.cpp | 6 +++--- src/position.h | 7 ------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/bitboard.h b/src/bitboard.h index c9f72427..5cafcfcc 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -160,6 +160,14 @@ constexpr Bitboard shift(Bitboard b) { : 0; } +/// pawn_attacks_bb() returns the pawn attacks for the given color from the +/// squares in the given bitboard. + +template +constexpr Bitboard pawn_attacks_bb(Bitboard b) { + return c == WHITE ? shift(b) | shift(b) + : shift(b) | shift(b); +} /// adjacent_files_bb() returns a bitboard representing all the squares on the /// adjacent files of the given one. diff --git a/src/evaluate.cpp b/src/evaluate.cpp index b531cc27..0022ae4c 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -527,7 +527,7 @@ namespace { b = pos.pieces(Us, PAWN) & (~attackedBy[Them][ALL_PIECES] | attackedBy[Us][ALL_PIECES]); - safeThreats = pos.pawn_attacks(b) & weak; + safeThreats = pawn_attacks_bb(b) & weak; score += ThreatBySafePawn * popcount(safeThreats); } @@ -583,7 +583,7 @@ namespace { & (attackedBy[Us][ALL_PIECES] | ~attackedBy[Them][ALL_PIECES]); // Bonus for safe pawn threats on the next move - b = pos.pawn_attacks(b) + b = pawn_attacks_bb(b) & pos.pieces(Them) & ~attackedBy[Us][PAWN]; diff --git a/src/pawns.cpp b/src/pawns.cpp index 721df372..01e9632c 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -88,8 +88,8 @@ namespace { template Score evaluate(const Position& pos, Pawns::Entry* e) { - const Color Them = (Us == WHITE ? BLACK : WHITE); - const Direction Up = (Us == WHITE ? NORTH : SOUTH); + const Color Them = (Us == WHITE ? BLACK : WHITE); + const Direction Up = (Us == WHITE ? NORTH : SOUTH); Bitboard b, neighbours, stoppers, doubled, supported, phalanx; Bitboard lever, leverPush; @@ -104,7 +104,7 @@ namespace { e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0; e->semiopenFiles[Us] = 0xFF; e->kingSquares[Us] = SQ_NONE; - e->pawnAttacks[Us] = pos.pawn_attacks(ourPawns); + e->pawnAttacks[Us] = pawn_attacks_bb(ourPawns); e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares); e->pawnsOnSquares[Us][WHITE] = pos.count(Us) - e->pawnsOnSquares[Us][BLACK]; diff --git a/src/position.h b/src/position.h index 403ce398..34e2f7ee 100644 --- a/src/position.h +++ b/src/position.h @@ -115,7 +115,6 @@ public: Bitboard attacks_from(PieceType pt, Square s) const; template Bitboard attacks_from(Square s) const; template Bitboard attacks_from(Square s, Color c) const; - template Bitboard pawn_attacks(Bitboard b) const; Bitboard slider_blockers(Bitboard sliders, Square s, Bitboard& pinners) const; // Properties of moves @@ -289,12 +288,6 @@ inline Bitboard Position::attacks_from(PieceType pt, Square s) const { return attacks_bb(pt, s, byTypeBB[ALL_PIECES]); } -template -inline Bitboard Position::pawn_attacks(Bitboard b) const { - return c == WHITE ? shift(b) | shift(b) - : shift(b) | shift(b); -} - inline Bitboard Position::attackers_to(Square s) const { return attackers_to(s, byTypeBB[ALL_PIECES]); } -- 2.39.2