]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Position::move_is_capture() does not handle MOVE_NONE
[stockfish] / src / position.cpp
index abac6efc1ef56e4b57a22734558c5d1c3564348a..98e79df2a82d2d661c9af66aa8d8004466da1bab 100644 (file)
@@ -52,6 +52,7 @@ Key Position::zobSideToMove;
 Value Position::MgPieceSquareTable[16][64];
 Value Position::EgPieceSquareTable[16][64];
 
+static bool RequestPending = false;
 
 ////
 //// Functions
@@ -272,6 +273,13 @@ void Position::print(Move m) const {
 
   static const std::string pieceLetters = " PNBRQK  PNBRQK .";
 
+  // Check for reentrancy, as example when called from inside
+  // MovePicker that is used also here in move_to_san()
+  if (RequestPending)
+      return;
+
+  RequestPending = true;
+
   std::cout << std::endl;
   if (m != MOVE_NONE)
   {
@@ -296,6 +304,8 @@ void Position::print(Move m) const {
   std::cout << "+---+---+---+---+---+---+---+---+" << std::endl
             << "Fen is: " << to_fen() << std::endl
             << "Key is: " << key << std::endl;
+
+  RequestPending = false;
 }
 
 
@@ -665,10 +675,12 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
 
 
 /// Position::move_is_capture() tests whether a move from the current
-/// position is a capture.
+/// position is a capture. Move must not be MOVE_NONE.
 
 bool Position::move_is_capture(Move m) const {
 
+  assert(m != MOVE_NONE);
+
   return (   !square_is_empty(move_to(m))
           && (color_of_piece_on(move_to(m)) == opposite_color(side_to_move()))
          )