Rev 96 | Rev 169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 96 | Rev 154 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | namespace { |
37 | namespace { |
38 | 38 | ||
39 | // FEN string of the initial position, normal chess |
39 | // FEN string of the initial position, normal chess |
40 | const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; |
40 | const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; |
41 | 41 | ||
42 | // |
42 | // A list to keep track of the position states along the setup moves (from the |
43 | // start position to the position just before the search starts). Needed by |
43 | // start position to the position just before the search starts). Needed by |
44 | // 'draw by repetition' detection. |
44 | // 'draw by repetition' detection. |
45 |
|
45 | StateListPtr States(new std::deque<StateInfo>(1)); |
46 | 46 | ||
47 | 47 | ||
48 | // position() is called when engine receives the "position" UCI command. |
48 | // position() is called when engine receives the "position" UCI command. |
49 | // The function sets up the position described in the given FEN string ("fen") |
49 | // The function sets up the position described in the given FEN string ("fen") |
50 | // or the starting position ("startpos") and then makes the moves given in the |
50 | // or the starting position ("startpos") and then makes the moves given in the |
Line 66... | Line 66... | ||
66 | while (is >> token && token != "moves") |
66 | while (is >> token && token != "moves") |
67 | fen += token + " "; |
67 | fen += token + " "; |
68 | else |
68 | else |
69 | return; |
69 | return; |
70 | 70 | ||
71 |
|
71 | States = StateListPtr(new std::deque<StateInfo>(1)); |
72 |
|
72 | pos.set(fen, Options["UCI_Chess960"], &States->back(), Threads.main()); |
73 | 73 | ||
74 | // Parse move list (if any) |
74 | // Parse move list (if any) |
75 | while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE) |
75 | while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE) |
76 | { |
76 | { |
77 |
|
77 | States->push_back(StateInfo()); |
78 | pos.do_move(m, |
78 | pos.do_move(m, States->back(), pos.gives_check(m)); |
79 | } |
79 | } |
80 | } |
80 | } |
81 | 81 | ||
82 | 82 | ||
83 | // setoption() is called when engine receives the "setoption" UCI command. The |
83 | // setoption() is called when engine receives the "setoption" UCI command. The |
Line 106... | Line 106... | ||
106 | 106 | ||
107 | // go() is called when engine receives the "go" UCI command. The function sets |
107 | // go() is called when engine receives the "go" UCI command. The function sets |
108 | // the thinking time and other parameters from the input string, then starts |
108 | // the thinking time and other parameters from the input string, then starts |
109 | // the search. |
109 | // the search. |
110 | 110 | ||
111 | void go( |
111 | void go(Position& pos, istringstream& is) { |
112 | 112 | ||
113 | Search::LimitsType limits; |
113 | Search::LimitsType limits; |
114 | string token; |
114 | string token; |
115 | 115 | ||
116 | limits.startTime = now(); // As early as possible! |
116 | limits.startTime = now(); // As early as possible! |
Line 130... | Line 130... | ||
130 | else if (token == "movetime") is >> limits.movetime; |
130 | else if (token == "movetime") is >> limits.movetime; |
131 | else if (token == "mate") is >> limits.mate; |
131 | else if (token == "mate") is >> limits.mate; |
132 | else if (token == "infinite") limits.infinite = 1; |
132 | else if (token == "infinite") limits.infinite = 1; |
133 | else if (token == "ponder") limits.ponder = 1; |
133 | else if (token == "ponder") limits.ponder = 1; |
134 | 134 | ||
135 | Threads.start_thinking(pos, |
135 | Threads.start_thinking(pos, States, limits); |
136 | } |
136 | } |
137 | 137 | ||
138 | } // namespace |
138 | } // namespace |
139 | 139 | ||
140 | 140 | ||
Line 144... | Line 144... | ||
144 | /// run 'bench', once the command is executed the function returns immediately. |
144 | /// run 'bench', once the command is executed the function returns immediately. |
145 | /// In addition to the UCI ones, also some additional debug commands are supported. |
145 | /// In addition to the UCI ones, also some additional debug commands are supported. |
146 | 146 | ||
147 | void UCI::loop(int argc, char* argv[]) { |
147 | void UCI::loop(int argc, char* argv[]) { |
148 | 148 | ||
149 | Position pos |
149 | Position pos; |
150 | string token, cmd; |
150 | string token, cmd; |
- | 151 | ||
- | 152 | pos.set(StartFEN, false, &States->back(), Threads.main()); |
|
151 | 153 | ||
152 | for (int i = 1; i < argc; ++i) |
154 | for (int i = 1; i < argc; ++i) |
153 | cmd += std::string(argv[i]) + " "; |
155 | cmd += std::string(argv[i]) + " "; |
154 | 156 | ||
155 | do { |
157 | do { |