Generalize check for fairy riders
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 25 Jan 2020 11:05:49 +0000 (12:05 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 25 Jan 2020 11:05:49 +0000 (12:05 +0100)
No functional change.

src/position.cpp
src/types.h

index 9d4575d..cd392af 100644 (file)
@@ -775,7 +775,7 @@ Bitboard Position::attackers_to(Square s, Bitboard occupied, Color c) const {
       {
           PieceType move_pt = pt == KING ? king_type() : pt;
           // Consider asymmetrical move of horse
-          if (move_pt == HORSE || move_pt == BANNER)
+          if (AttackRiderTypes[move_pt] & ASYMMETRICAL_RIDERS)
           {
               Bitboard horses = PseudoAttacks[~c][move_pt][s] & pieces(c, pt);
               while (horses)
@@ -1060,7 +1060,7 @@ bool Position::gives_check(Move m) const {
   if (type_of(m) != PROMOTION && type_of(m) != PIECE_PROMOTION && type_of(m) != PIECE_DEMOTION)
   {
       PieceType pt = type_of(moved_piece(m));
-      if (pt == CANNON || pt == BANNER || pt == HORSE)
+      if (AttackRiderTypes[pt] & (HOPPING_RIDERS | ASYMMETRICAL_RIDERS))
       {
           if (attacks_bb(sideToMove, pt, to, (pieces() ^ from) | to) & square<KING>(~sideToMove))
               return true;
index 2ec3128..c678dd1 100644 (file)
@@ -382,6 +382,8 @@ enum RiderType {
   RIDER_CANNON_V = 1 << 4,
   RIDER_HORSE = 1 << 5,
   RIDER_ELEPHANT = 1 << 6,
+  HOPPING_RIDERS = RIDER_CANNON_H | RIDER_CANNON_V,
+  ASYMMETRICAL_RIDERS = RIDER_HORSE,
 };
 
 extern Value PieceValue[PHASE_NB][PIECE_NB];