- // Local functions
- void set_option(UCIParser& up);
- void set_position(Position& pos, UCIParser& up);
- bool go(Position& pos, UCIParser& up);
- void perft(Position& pos, UCIParser& up);
-}
+
+ // position() is called when engine receives the "position" UCI command.
+ // The function sets up the position described in the given FEN string ("fen")
+ // or the starting position ("startpos") and then makes the moves given in the
+ // following move list ("moves").
+
+ void position(Position& pos, istringstream& is) {
+
+ Move m;
+ string token, fen;
+
+ is >> token;
+
+ if (token == "startpos")
+ {
+ fen = StartFEN;
+ is >> token; // Consume "moves" token if any
+ }
+ else if (token == "fen")
+ while (is >> token && token != "moves")
+ fen += token + " ";
+ else
+ return;
+
+ States = StateListPtr(new std::deque<StateInfo>(1));
+ pos.set(fen, Options["UCI_Chess960"], &States->back(), Threads.main());
+
+ // Parse move list (if any)
+ while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
+ {
+ States->push_back(StateInfo());
+ pos.do_move(m, States->back());
+ }
+ }