]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Merge remote-tracking branch 'upstream/master' into HEAD
[stockfish] / src / position.cpp
index 35e307efcbce58e2581cc0ccb37baea5e0e47d1a..a2ee64f81cc603e6e4a03dbbfbbc00afeb863aa6 100644 (file)
@@ -34,6 +34,8 @@
 
 using std::string;
 
+namespace Stockfish {
+
 namespace Zobrist {
 
   Key psq[PIECE_NB][SQUARE_NB];
@@ -268,8 +270,8 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
       enpassant = pawn_attacks_bb(~sideToMove, st->epSquare) & pieces(sideToMove, PAWN)
                && (pieces(~sideToMove, PAWN) & (st->epSquare + pawn_push(~sideToMove)))
                && !(pieces() & (st->epSquare | (st->epSquare + pawn_push(sideToMove))))
-               && (file_of(square<KING>(sideToMove)) == file_of(st->epSquare)
-               || !(blockers_for_king(sideToMove) & (st->epSquare + pawn_push(~sideToMove))));
+               && (   file_of(square<KING>(sideToMove)) == file_of(st->epSquare)
+                   || !(blockers_for_king(sideToMove) & (st->epSquare + pawn_push(~sideToMove))));
   }
 
   // It's necessary for st->previous to be intialized in this way because legality check relies on its existence
@@ -296,8 +298,6 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
   st->accumulator.state[WHITE] = Eval::NNUE::INIT;
   st->accumulator.state[BLACK] = Eval::NNUE::INIT;
 
-  assert(pos_is_ok());
-
   return *this;
 }
 
@@ -408,7 +408,7 @@ Position& Position::set(const string& code, Color c, StateInfo* si) {
 /// Position::fen() returns a FEN representation of the position. In case of
 /// Chess960 the Shredder-FEN notation is used. This is mainly a debugging function.
 
-const string Position::fen() const {
+string Position::fen() const {
 
   int emptyCnt;
   std::ostringstream ss;
@@ -518,8 +518,8 @@ bool Position::legal(Move m) const {
   // st->previous->blockersForKing consider capsq as empty.
   // If pinned, it has to move along the king ray.
   if (type_of(m) == EN_PASSANT)
-      return !(st->previous->blockersForKing[sideToMove] & from) ||
-               aligned(from, to, square<KING>(us));
+      return   !(st->previous->blockersForKing[sideToMove] & from)
+            || aligned(from, to, square<KING>(us));
 
   // Castling moves generation does not check if the castling path is clear of
   // enemy attacks, it is delayed at a later time: now!
@@ -546,8 +546,8 @@ bool Position::legal(Move m) const {
 
   // A non-king move is legal if and only if it is not pinned or it
   // is moving along the ray towards or away from the king.
-  return   !(blockers_for_king(us) & from)
-        ||  aligned(from, to, square<KING>(us));
+  return !(blockers_for_king(us) & from)
+      || aligned(from, to, square<KING>(us));
 }
 
 
@@ -657,8 +657,9 @@ bool Position::gives_check(Move m) const {
   // So the King must be in the same rank as fromsq to consider this possibility.
   // st->previous->blockersForKing consider capsq as empty.
   case EN_PASSANT:
-      return st->previous->checkersBB || (rank_of(square<KING>(~sideToMove)) == rank_of(from)
-          && st->previous->blockersForKing[~sideToMove] & from);
+      return st->previous->checkersBB
+          || (   rank_of(square<KING>(~sideToMove)) == rank_of(from)
+              && st->previous->blockersForKing[~sideToMove] & from);
 
   default: //CASTLING
   {
@@ -1337,3 +1338,5 @@ bool Position::pos_is_ok() const {
 
   return true;
 }
+
+} // namespace Stockfish