]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Add checkers info to Position::pretty()
[stockfish] / src / position.cpp
index 0c19d820b5e8c80656e8340a2e312c7645caecae..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.
@@ -542,14 +535,13 @@ bool Position::move_is_legal(const Move m) const {
 bool Position::is_pseudo_legal(const Move m) const {
 
   Color us = sideToMove;
-  Color them = ~sideToMove;
   Square from = from_sq(m);
   Square to = to_sq(m);
   Piece pc = piece_moved(m);
 
   // 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)
@@ -587,7 +579,7 @@ bool Position::is_pseudo_legal(const Move m) const {
       case DELTA_SE:
       // Capture. The destination square must be occupied by an enemy
       // piece (en passant captures was handled earlier).
-      if (piece_on(to) == NO_PIECE || color_of(piece_on(to)) != them)
+      if (piece_on(to) == NO_PIECE || color_of(piece_on(to)) != ~us)
           return false;
 
       // From and to files must be one file apart, avoids a7h5
@@ -632,18 +624,16 @@ 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)
       {
-          Bitboard b = checkers();
-          Square checksq = pop_lsb(&b);
-
-          if (b) // double check ? In this case a king move is required
+          // Double check? In this case a king move is required
+          if (more_than_one(checkers()))
               return false;
 
           // Our move must be a blocking evasion or a capture of the checking piece
-          if (!((between_bb(checksq, king_square(us)) | checkers()) & to))
+          if (!((between_bb(lsb(checkers()), king_square(us)) | checkers()) & to))
               return false;
       }
       // In case of king moves under check we have to remove king so to catch
@@ -918,7 +908,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   }
 
   // Prefetch pawn and material hash tables
-  prefetch((char*)thisThread->pawnTable.entries[st->pawnKey]);
+  prefetch((char*)thisThread->pawnsTable[st->pawnKey]);
   prefetch((char*)thisThread->materialTable[st->materialKey]);
 
   // Update incremental scores
@@ -1161,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
@@ -1445,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)