From: protonspring Date: Wed, 10 Apr 2019 17:33:57 +0000 (-0600) Subject: Simplify castlingPath (#2088) X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;ds=sidebyside;h=ec49e676a70435472cb70a9cf0c0376dfab31af4;p=stockfish Simplify castlingPath (#2088) Instead of looping through kfrom,kto, rfrom, rto, we can use BetweenBB. This is less lines of code and it is more clear what castlingPath actually is. Personal benchmarks are all over the place. However, this code is only executed when loading a position, so performance doesn't seem that relevant. No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index 84892d09..ada03fbc 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -340,13 +340,8 @@ void Position::set_castling_right(Color c, Square rfrom) { Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1); Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1); - for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); ++s) - if (s != kfrom && s != rfrom) - castlingPath[cr] |= s; - - for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); ++s) - if (s != kfrom && s != rfrom) - castlingPath[cr] |= s; + castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto) + & ~(square_bb(kfrom) | rfrom); }