]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Clean up position setup code
[stockfish] / src / position.cpp
index bc6efb7f646d05bb242b94b3f3d5eea48b426eb6..ae28805c4c6bfd4cf093d52c74bcf456ab23d22a 100644 (file)
@@ -205,6 +205,7 @@ void Position::from_fen(const string& fen, bool c960) {
 */
 
   char token;
+  int hmc, fmn;
   std::istringstream ss(fen);
   Rank rank = RANK_8;
   File file = FILE_A;
@@ -264,7 +265,13 @@ void Position::from_fen(const string& fen, bool c960) {
           st->epSquare = fenEpSquare;
   }
 
-  // 5-6. Halfmove clock and fullmove number are not parsed
+  // 5. Halfmove clock
+  if (ss >> hmc)
+      st->rule50 = hmc;
+
+  // 6. Fullmove number
+  if (ss >> fmn)
+      startPosPlyCounter = (fmn - 1) * 2 + int(sideToMove == BLACK);
 
   // Various initialisations
   castleRightsMask[make_square(initialKFile,  RANK_1)] ^= WHITE_OO | WHITE_OOO;
@@ -524,7 +531,7 @@ Bitboard Position::attacks_from(Piece p, Square s) const {
   case WB: case BB: return attacks_from<BISHOP>(s);
   case WR: case BR: return attacks_from<ROOK>(s);
   case WQ: case BQ: return attacks_from<QUEEN>(s);
-  default: return StepAttackBB[p][s];
+  default: return NonSlidingAttacksBB[p][s];
   }
 }
 
@@ -537,7 +544,7 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
   case WB: case BB: return bishop_attacks_bb(s, occ);
   case WR: case BR: return rook_attacks_bb(s, occ);
   case WQ: case BQ: return bishop_attacks_bb(s, occ) | rook_attacks_bb(s, occ);
-  default: return StepAttackBB[p][s];
+  default: return NonSlidingAttacksBB[p][s];
   }
 }
 
@@ -766,6 +773,23 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
 }
 
 
+/// Position::do_setup_move() makes a permanent move on the board.
+/// It should be used when setting up a position on board.
+/// You can't undo the move.
+
+void Position::do_setup_move(Move m, StateInfo& newSt) {
+
+  do_move(m, newSt);
+
+  // Reset "game ply" in case we made a non-reversible move.
+  // "game ply" is used for repetition detection.
+  if (st->rule50 == 0)
+      st->gamePly = 0;
+
+  // Update the number of plies played from the starting position
+  startPosPlyCounter++;
+}
+
 /// Position::do_move() makes a move, and saves all information necessary
 /// to a StateInfo object. The move is assumed to be legal.
 /// Pseudo-legal moves should be filtered out before this function is called.
@@ -1533,22 +1557,6 @@ void Position::clear() {
 }
 
 
-/// Position::reset_game_ply() simply sets gamePly to 0. It is used from the
-/// UCI interface code, whenever a non-reversible move is made in a
-/// 'position fen <fen> moves m1 m2 ...' command.  This makes it possible
-/// for the program to handle games of arbitrary length, as long as the GUI
-/// handles draws by the 50 move rule correctly.
-
-void Position::reset_game_ply() {
-
-  st->gamePly = 0;
-}
-
-void Position::inc_startpos_ply_counter() {
-
-  startPosPlyCounter++;
-}
-
 /// Position::put_piece() puts a piece on the given square of the board,
 /// updating the board array, pieces list, bitboards, and piece counts.