]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Parse halfmove clock and fullmove number from FEN
[stockfish] / src / position.cpp
index f0301e4ec9308af1a78394c5728b0246b1af30a3..71556a566e49072d37023c5a07b74613e043303f 100644 (file)
@@ -152,9 +152,9 @@ Position::Position(const Position& pos, int th) {
   nodes = 0;
 }
 
-Position::Position(const string& fen, int th) {
+Position::Position(const string& fen, bool isChess960, int th) {
 
-  from_fen(fen);
+  from_fen(fen, isChess960);
   threadID = th;
 }
 
@@ -175,7 +175,7 @@ void Position::detach() {
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
-void Position::from_fen(const string& fen) {
+void Position::from_fen(const string& fen, bool c960) {
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
@@ -264,7 +264,15 @@ void Position::from_fen(const string& fen) {
           st->epSquare = fenEpSquare;
   }
 
-  // 5-6. Halfmove clock and fullmove number are not parsed
+  // 5. Halfmove clock
+  int hmc;
+  if (ss >> hmc)
+      st->rule50 = hmc;
+
+  // 6. Fullmove number
+  int fmn;
+  if (ss >> fmn)
+      startPosPlyCounter = (fmn - 1) * 2 + int(sideToMove == BLACK);
 
   // Various initialisations
   castleRightsMask[make_square(initialKFile,  RANK_1)] ^= WHITE_OO | WHITE_OOO;
@@ -274,10 +282,7 @@ void Position::from_fen(const string& fen) {
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
-  isChess960 =   initialKFile  != FILE_E
-              || initialQRFile != FILE_A
-              || initialKRFile != FILE_H;
-
+  isChess960 = c960;
   find_checkers();
 
   st->key = compute_key();
@@ -527,7 +532,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];
   }
 }
 
@@ -540,7 +545,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];
   }
 }