]> git.sesse.net Git - stockfish/commitdiff
Wrap all access to LineBB and add assert
authorprotonspring <mike@whiteley.org>
Sun, 7 Jun 2020 03:25:32 +0000 (21:25 -0600)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Tue, 9 Jun 2020 16:13:24 +0000 (18:13 +0200)
This is a non-functional code style change which provides a safe access handler for LineBB.
Also includes an assert in debug mode to verify square correctness.

closes https://github.com/official-stockfish/Stockfish/pull/2719

No functional change

src/bitboard.h
src/evaluate.cpp
src/movegen.cpp

index 93f838f8a6adce42ead12022368fce28959f34c9..704f4bb4e8a463d3d349bfee9fefcbbf9df63bc6 100644 (file)
@@ -200,12 +200,24 @@ inline Bitboard adjacent_files_bb(Square s) {
   return shift<EAST>(file_bb(s)) | shift<WEST>(file_bb(s));
 }
 
+/// line_bb(Square, Square) returns a Bitboard representing an entire line
+/// (from board edge to board edge) that intersects the given squares.
+/// If the given squares are not on a same file/rank/diagonal, return 0.
+/// Ex. line_bb(SQ_C4, SQ_F7) returns a bitboard with the A2-G8 diagonal.
+
+inline Bitboard line_bb(Square s1, Square s2) {
+
+  assert(is_ok(s1) && is_ok(s2));
+  return LineBB[s1][s2];
+}
 
-/// between_bb() returns squares that are linearly between the given squares
+/// between_bb() returns a Bitboard representing squares that are linearly
+/// between the given squares (excluding the given squares).
 /// If the given squares are not on a same file/rank/diagonal, return 0.
+/// Ex. between_bb(SQ_C4, SQ_F7) returns a bitboard with squares D5 and E6.
 
 inline Bitboard between_bb(Square s1, Square s2) {
-  Bitboard b = LineBB[s1][s2] & ((AllSquares << s1) ^ (AllSquares << s2));
+  Bitboard b = line_bb(s1, s2) & ((AllSquares << s1) ^ (AllSquares << s2));
   return b & (b - 1); //exclude lsb
 }
 
@@ -249,7 +261,7 @@ inline Bitboard passed_pawn_span(Color c, Square s) {
 /// straight or on a diagonal line.
 
 inline bool aligned(Square s1, Square s2, Square s3) {
-  return LineBB[s1][s2] & s3;
+  return line_bb(s1, s2) & s3;
 }
 
 
index 12a4c7bff10d15e0b73ed837e93a9d154fafda00..c042c016ed35c511b304938332b918da188e96d7 100644 (file)
@@ -276,7 +276,7 @@ namespace {
                          : attacks_bb<Pt>(s, pos.pieces());
 
         if (pos.blockers_for_king(Us) & s)
-            b &= LineBB[pos.square<KING>(Us)][s];
+            b &= line_bb(pos.square<KING>(Us), s);
 
         attackedBy2[Us] |= attackedBy[Us][ALL_PIECES] & b;
         attackedBy[Us][Pt] |= b;
index b57f41a9829ed3264293418feff27736dbe68eec..17203a959383b06537ca721e64c27ff8a4519d27 100644 (file)
@@ -332,7 +332,7 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
   // the king evasions in order to skip known illegal moves, which avoids any
   // useless legality checks later on.
   while (sliders)
-      sliderAttacks |= LineBB[ksq][pop_lsb(&sliders)] & ~pos.checkers();
+      sliderAttacks |= line_bb(ksq, pop_lsb(&sliders)) & ~pos.checkers();
 
   // Generate evasions for king, capture and non capture moves
   Bitboard b = attacks_bb<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;