Simplify handling special riders
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 14 Aug 2020 13:45:40 +0000 (15:45 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 14 Aug 2020 13:45:40 +0000 (15:45 +0200)
No functional change.

src/movegen.cpp
src/position.cpp
src/position.h

index 31d7118..bcad30c 100644 (file)
@@ -333,7 +333,7 @@ namespace {
             break;
         case EVASIONS:
         {
-            if (pos.checkers() & (pos.pieces(CANNON, BANNER) | pos.pieces(HORSE, ELEPHANT) | pos.pieces(JANGGI_CANNON, JANGGI_ELEPHANT)))
+            if (pos.checkers() & pos.non_sliding_riders())
             {
                 target = ~pos.pieces(Us);
                 break;
@@ -490,7 +490,7 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
       *moveList++ = make<SPECIAL>(ksq, ksq);
 
   // Consider all evasion moves for special pieces
-  if (sliders & (pos.pieces(CANNON, BANNER) | pos.pieces(HORSE, ELEPHANT) | pos.pieces(JANGGI_CANNON, JANGGI_ELEPHANT)))
+  if (sliders & pos.non_sliding_riders())
   {
       Bitboard target = pos.board_bb() & ~pos.pieces(us);
       Bitboard b = (  (pos.attacks_from(us, KING, ksq) & pos.pieces())
index 8b3360f..84cd5f4 100644 (file)
@@ -1052,7 +1052,7 @@ bool Position::pseudo_legal(const Move m) const {
   // Evasions generator already takes care to avoid some kind of illegal moves
   // and legal() relies on this. We therefore have to take care that the same
   // kind of moves are filtered out here.
-  if (checkers() && !(checkers() & (pieces(CANNON, BANNER) | pieces(HORSE, ELEPHANT) | pieces(JANGGI_CANNON, JANGGI_ELEPHANT))))
+  if (checkers() && !(checkers() & non_sliding_riders()))
   {
       if (type_of(pc) != KING)
       {
index 285773b..eae5c66 100644 (file)
@@ -181,6 +181,7 @@ public:
   Bitboard pieces(Color c, PieceType pt) const;
   Bitboard pieces(Color c, PieceType pt1, PieceType pt2) const;
   Bitboard major_pieces(Color c) const;
+  Bitboard non_sliding_riders() const;
   Piece piece_on(Square s) const;
   Piece unpromoted_piece_on(Square s) const;
   Square ep_square() const;
@@ -833,6 +834,10 @@ inline Bitboard Position::major_pieces(Color c) const {
   return pieces(c) & (pieces(QUEEN) | pieces(AIWOK) | pieces(ARCHBISHOP) | pieces(CHANCELLOR) | pieces(AMAZON));
 }
 
+inline Bitboard Position::non_sliding_riders() const {
+  return pieces(CANNON, BANNER) | pieces(HORSE, ELEPHANT) | pieces(JANGGI_CANNON, JANGGI_ELEPHANT);
+}
+
 inline int Position::count(Color c, PieceType pt) const {
   return pieceCount[make_piece(c, pt)];
 }