]> git.sesse.net Git - stockfish/commitdiff
Simplify castlingPath (#2088)
authorprotonspring <mike@whiteley.org>
Wed, 10 Apr 2019 17:33:57 +0000 (11:33 -0600)
committerMarco Costalba <mcostalba@users.noreply.github.com>
Wed, 10 Apr 2019 17:33:57 +0000 (19:33 +0200)
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.

src/position.cpp

index 84892d094a60fd3d770b1af0ba2546724ef7b8a9..ada03fbcf4b1076b38d5aca3583d5bf5b60be2f7 100644 (file)
@@ -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);
 }