Speed-up pseudo-legal move validation of drops
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 31 Jan 2019 20:14:47 +0000 (21:14 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 1 Feb 2019 20:57:03 +0000 (21:57 +0100)
Improves performance by ~10% for drop variants.

src/position.cpp

index ee5b2f1..f7860fe 100644 (file)
@@ -831,6 +831,14 @@ bool Position::pseudo_legal(const Move m) const {
   Square to = to_sq(m);
   Piece pc = moved_piece(m);
 
+  // Use a fast check for piece drops
+  if (type_of(m) == DROP)
+      return   piece_drops()
+            && count_in_hand(us, type_of(pc))
+            && (drop_region(us, type_of(pc)) & ~pieces() & to)
+            && (   type_of(pc) == in_hand_piece_type(m)
+                || (drop_promoted() && promoted_piece_type(type_of(pc)) == in_hand_piece_type(m)));
+
   // Use a slower but simpler function for uncommon cases
   if (type_of(m) != NORMAL)
       return MoveList<LEGAL>(*this).contains(m);