]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Add checkers info to Position::pretty()
[stockfish] / src / position.cpp
index 045b10cab7c276b8fc3806a09c4751c33fdf2523..de5d04c13ac8982368fcd10edf0eab96168058ec 100644 (file)
@@ -400,14 +400,21 @@ const string Position::pretty(Move move) const {
   std::ostringstream ss;
 
   if (move)
-      ss << "\nMove is: " << (sideToMove == BLACK ? ".." : "")
+      ss << "\nMove: " << (sideToMove == BLACK ? ".." : "")
          << move_to_san(*const_cast<Position*>(this), move);
 
   for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
       if (piece_on(sq) != NO_PIECE)
           brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
 
-  ss << brd << "\nFen is: " << fen() << "\nKey is: " << st->key;
+  ss << brd << "\nFen: " << fen() << "\nKey: " << st->key;
+
+  if (checkers())
+  {
+      ss << "\nCheckers: ";
+      for (Bitboard b = checkers(); b; )
+          ss << square_to_string(pop_lsb(&b)) << " ";
+  }
   return ss.str();
 }
 
@@ -521,20 +528,6 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
 }
 
 
-/// Position::move_is_legal() takes a random move and tests whether the move
-/// is legal. This version is not very fast and should be used only in non
-/// time-critical paths.
-
-bool Position::move_is_legal(const Move m) const {
-
-  for (MoveList<LEGAL> ml(*this); !ml.end(); ++ml)
-      if (ml.move() == m)
-          return true;
-
-  return false;
-}
-
-
 /// Position::is_pseudo_legal() takes a random move and tests whether the move
 /// is pseudo legal. It is used to validate moves from TT that can be corrupted
 /// due to SMP concurrent access or hash position key aliasing.
@@ -548,7 +541,7 @@ bool Position::is_pseudo_legal(const Move m) const {
 
   // Use a slower but simpler function for uncommon cases
   if (type_of(m) != NORMAL)
-      return move_is_legal(m);
+      return MoveList<LEGAL>(*this).contains(m);
 
   // Is not a promotion, so promotion piece must be empty
   if (promotion_type(m) - 2 != NO_PIECE_TYPE)
@@ -631,7 +624,7 @@ bool Position::is_pseudo_legal(const Move m) const {
   // Evasions generator already takes care to avoid some kind of illegal moves
   // and pl_move_is_legal() relies on this. So we have to take care that the
   // same kind of moves are filtered out here.
-  if (in_check())
+  if (checkers())
   {
       if (type_of(pc) != KING)
       {
@@ -1158,7 +1151,7 @@ void Position::do_castle_move(Move m) {
 template<bool Do>
 void Position::do_null_move(StateInfo& backupSt) {
 
-  assert(!in_check());
+  assert(!checkers());
 
   // Back up the information necessary to undo the null move to the supplied
   // StateInfo object. Note that differently from normal case here backupSt
@@ -1442,7 +1435,7 @@ bool Position::is_draw() const {
       && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
       return true;
 
-  if (st->rule50 > 99 && (!in_check() || MoveList<LEGAL>(*this).size()))
+  if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
       return true;
 
   if (CheckRepetition)