+CheckInfo::CheckInfo(const Position& pos) {
+
+ Color them = ~pos.side_to_move();
+ ksq = pos.king_square(them);
+
+ pinned = pos.pinned_pieces();
+ dcCandidates = pos.discovered_check_candidates();
+
+ checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
+ checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
+ checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
+ checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
+ checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
+ checkSq[KING] = 0;
+}
+
+
+/// Position::operator=() creates a copy of 'pos'. We want the new born Position
+/// object do not depend on any external data so we detach state pointer from
+/// the source one.
+
+Position& Position::operator=(const Position& pos) {
+
+ memcpy(this, &pos, sizeof(Position));
+ startState = *st;
+ st = &startState;
+ nodes = 0;
+
+ assert(pos_is_ok());
+
+ return *this;
+}
+
+
+/// Position::set() initializes the position object with the given FEN 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::set(const string& fenStr, bool isChess960, Thread* th) {
+/*
+ A FEN string defines a particular position using only the ASCII character set.
+
+ A FEN string contains six fields separated by a space. The fields are:
+
+ 1) Piece placement (from white's perspective). Each rank is described, starting
+ with rank 8 and ending with rank 1; within each rank, the contents of each
+ square are described from file A through file H. Following the Standard
+ Algebraic Notation (SAN), each piece is identified by a single letter taken
+ from the standard English names. White pieces are designated using upper-case
+ letters ("PNBRQK") while Black take lowercase ("pnbrqk"). Blank squares are
+ noted using digits 1 through 8 (the number of blank squares), and "/"
+ separates ranks.
+
+ 2) Active color. "w" means white moves next, "b" means black.
+
+ 3) Castling availability. If neither side can castle, this is "-". Otherwise,
+ this has one or more letters: "K" (White can castle kingside), "Q" (White
+ can castle queenside), "k" (Black can castle kingside), and/or "q" (Black
+ can castle queenside).
+
+ 4) En passant target square (in algebraic notation). If there's no en passant
+ target square, this is "-". If a pawn has just made a 2-square move, this
+ is the position "behind" the pawn. This is recorded regardless of whether
+ there is a pawn in position to make an en passant capture.
+
+ 5) Halfmove clock. This is the number of halfmoves since the last pawn advance
+ or capture. This is used to determine if a draw can be claimed under the
+ fifty-move rule.
+
+ 6) Fullmove number. The number of the full move. It starts at 1, and is
+ incremented after Black's move.
+*/
+
+ char col, row, token;
+ size_t p;
+ Square sq = SQ_A8;
+ std::istringstream ss(fenStr);