Skip to content

Commit ada55c5

Browse files
committed
Reshuffle in uci.cpp
Move function definitions before call site. No functional change.
1 parent 17cb7e7 commit ada55c5

File tree

1 file changed

+77
-83
lines changed

1 file changed

+77
-83
lines changed

src/uci.cpp

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -44,89 +44,6 @@ namespace {
4444
// draw detection code.
4545
Search::StateStackPtr SetupStates;
4646

47-
void setoption(istringstream& up);
48-
void position(Position& pos, istringstream& up);
49-
void go(const Position& pos, istringstream& up);
50-
}
51-
52-
53-
/// Wait for a command from the user, parse this text string as an UCI command,
54-
/// and call the appropriate functions. Also intercepts EOF from stdin to ensure
55-
/// that we exit gracefully if the GUI dies unexpectedly. In addition to the UCI
56-
/// commands, the function also supports a few debug commands.
57-
58-
void UCI::loop(const string& args) {
59-
60-
Position pos(StartFEN, false, Threads.main()); // The root position
61-
string token, cmd = args;
62-
63-
do {
64-
if (args.empty() && !getline(cin, cmd)) // Block here waiting for input
65-
cmd = "quit";
66-
67-
istringstream is(cmd);
68-
69-
is >> skipws >> token;
70-
71-
if (token == "quit" || token == "stop" || token == "ponderhit")
72-
{
73-
// The GUI sends 'ponderhit' to tell us to ponder on the same move the
74-
// opponent has played. In case Signals.stopOnPonderhit is set we are
75-
// waiting for 'ponderhit' to stop the search (for instance because we
76-
// already ran out of time), otherwise we should continue searching but
77-
// switch from pondering to normal search.
78-
if (token != "ponderhit" || Search::Signals.stopOnPonderhit)
79-
{
80-
Search::Signals.stop = true;
81-
Threads.main()->notify_one(); // Could be sleeping
82-
}
83-
else
84-
Search::Limits.ponder = false;
85-
}
86-
else if (token == "perft" && (is >> token)) // Read perft depth
87-
{
88-
stringstream ss;
89-
90-
ss << Options["Hash"] << " "
91-
<< Options["Threads"] << " " << token << " current perft";
92-
93-
benchmark(pos, ss);
94-
}
95-
else if (token == "key")
96-
sync_cout << hex << uppercase << setfill('0')
97-
<< "position key: " << setw(16) << pos.key()
98-
<< "\nmaterial key: " << setw(16) << pos.material_key()
99-
<< "\npawn key: " << setw(16) << pos.pawn_key()
100-
<< dec << sync_endl;
101-
102-
else if (token == "uci")
103-
sync_cout << "id name " << engine_info(true)
104-
<< "\n" << Options
105-
<< "\nuciok" << sync_endl;
106-
107-
else if (token == "eval")
108-
{
109-
Search::RootColor = pos.side_to_move(); // Ensure it is set
110-
sync_cout << Eval::trace(pos) << sync_endl;
111-
}
112-
else if (token == "ucinewgame") TT.clear();
113-
else if (token == "go") go(pos, is);
114-
else if (token == "position") position(pos, is);
115-
else if (token == "setoption") setoption(is);
116-
else if (token == "flip") pos.flip();
117-
else if (token == "bench") benchmark(pos, is);
118-
else if (token == "d") sync_cout << pos.pretty() << sync_endl;
119-
else if (token == "isready") sync_cout << "readyok" << sync_endl;
120-
else
121-
sync_cout << "Unknown command: " << cmd << sync_endl;
122-
123-
} while (token != "quit" && args.empty()); // Args have one-shot behaviour
124-
125-
Threads.wait_for_think_finished(); // Cannot quit whilst the search is running
126-
}
127-
128-
129-
namespace {
13047

13148
// position() is called when engine receives the "position" UCI command.
13249
// The function sets up the position described in the given FEN string ("fen")
@@ -217,4 +134,81 @@ namespace {
217134

218135
Threads.start_thinking(pos, limits, SetupStates);
219136
}
137+
138+
} // namespace
139+
140+
141+
/// Wait for a command from the user, parse this text string as an UCI command,
142+
/// and call the appropriate functions. Also intercepts EOF from stdin to ensure
143+
/// that we exit gracefully if the GUI dies unexpectedly. In addition to the UCI
144+
/// commands, the function also supports a few debug commands.
145+
146+
void UCI::loop(const string& args) {
147+
148+
Position pos(StartFEN, false, Threads.main()); // The root position
149+
string token, cmd = args;
150+
151+
do {
152+
if (args.empty() && !getline(cin, cmd)) // Block here waiting for input
153+
cmd = "quit";
154+
155+
istringstream is(cmd);
156+
157+
is >> skipws >> token;
158+
159+
if (token == "quit" || token == "stop" || token == "ponderhit")
160+
{
161+
// The GUI sends 'ponderhit' to tell us to ponder on the same move the
162+
// opponent has played. In case Signals.stopOnPonderhit is set we are
163+
// waiting for 'ponderhit' to stop the search (for instance because we
164+
// already ran out of time), otherwise we should continue searching but
165+
// switch from pondering to normal search.
166+
if (token != "ponderhit" || Search::Signals.stopOnPonderhit)
167+
{
168+
Search::Signals.stop = true;
169+
Threads.main()->notify_one(); // Could be sleeping
170+
}
171+
else
172+
Search::Limits.ponder = false;
173+
}
174+
else if (token == "perft" && (is >> token)) // Read perft depth
175+
{
176+
stringstream ss;
177+
178+
ss << Options["Hash"] << " "
179+
<< Options["Threads"] << " " << token << " current perft";
180+
181+
benchmark(pos, ss);
182+
}
183+
else if (token == "key")
184+
sync_cout << hex << uppercase << setfill('0')
185+
<< "position key: " << setw(16) << pos.key()
186+
<< "\nmaterial key: " << setw(16) << pos.material_key()
187+
<< "\npawn key: " << setw(16) << pos.pawn_key()
188+
<< dec << sync_endl;
189+
190+
else if (token == "uci")
191+
sync_cout << "id name " << engine_info(true)
192+
<< "\n" << Options
193+
<< "\nuciok" << sync_endl;
194+
195+
else if (token == "eval")
196+
{
197+
Search::RootColor = pos.side_to_move(); // Ensure it is set
198+
sync_cout << Eval::trace(pos) << sync_endl;
199+
}
200+
else if (token == "ucinewgame") TT.clear();
201+
else if (token == "go") go(pos, is);
202+
else if (token == "position") position(pos, is);
203+
else if (token == "setoption") setoption(is);
204+
else if (token == "flip") pos.flip();
205+
else if (token == "bench") benchmark(pos, is);
206+
else if (token == "d") sync_cout << pos.pretty() << sync_endl;
207+
else if (token == "isready") sync_cout << "readyok" << sync_endl;
208+
else
209+
sync_cout << "Unknown command: " << cmd << sync_endl;
210+
211+
} while (token != "quit" && args.empty()); // Args have one-shot behaviour
212+
213+
Threads.wait_for_think_finished(); // Cannot quit whilst the search is running
220214
}

0 commit comments

Comments
 (0)