@@ -40,16 +40,16 @@ static const char* PieceToChar[COLOR_NB] = { " PNBRQK", " pnbrqk" };
4040
4141string score_to_uci (Value v, Value alpha, Value beta) {
4242
43- stringstream s ;
43+ stringstream ss ;
4444
4545 if (abs (v) < VALUE_MATE_IN_MAX_PLY )
46- s << " cp " << v * 100 / int (PawnValueMg);
46+ ss << " cp " << v * 100 / int (PawnValueMg);
4747 else
48- s << " mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2 ;
48+ ss << " mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2 ;
4949
50- s << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : " " );
50+ ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : " " );
5151
52- return s .str ();
52+ return ss .str ();
5353}
5454
5555
@@ -177,7 +177,7 @@ const string move_to_san(Position& pos, Move m) {
177177// / appended to the search log file. It uses the two helpers below to pretty
178178// / format the time and score respectively.
179179
180- static string time_to_string (int64_t msecs) {
180+ static string format (int64_t msecs) {
181181
182182 const int MSecMinute = 1000 * 60 ;
183183 const int MSecHour = 1000 * 60 * 60 ;
@@ -186,71 +186,64 @@ static string time_to_string(int64_t msecs) {
186186 int64_t minutes = (msecs % MSecHour) / MSecMinute;
187187 int64_t seconds = ((msecs % MSecHour) % MSecMinute) / 1000 ;
188188
189- stringstream s ;
189+ stringstream ss ;
190190
191191 if (hours)
192- s << hours << ' :' ;
192+ ss << hours << ' :' ;
193193
194- s << setfill (' 0' ) << setw (2 ) << minutes << ' :' << setw (2 ) << seconds;
194+ ss << setfill (' 0' ) << setw (2 ) << minutes << ' :' << setw (2 ) << seconds;
195195
196- return s .str ();
196+ return ss .str ();
197197}
198198
199- static string score_to_string (Value v) {
199+ static string format (Value v) {
200200
201- stringstream s ;
201+ stringstream ss ;
202202
203203 if (v >= VALUE_MATE_IN_MAX_PLY )
204- s << " #" << (VALUE_MATE - v + 1 ) / 2 ;
204+ ss << " #" << (VALUE_MATE - v + 1 ) / 2 ;
205205
206206 else if (v <= VALUE_MATED_IN_MAX_PLY )
207- s << " -#" << (VALUE_MATE + v) / 2 ;
207+ ss << " -#" << (VALUE_MATE + v) / 2 ;
208208
209209 else
210- s << setprecision (2 ) << fixed << showpos << double (v) / PawnValueMg;
210+ ss << setprecision (2 ) << fixed << showpos << double (v) / PawnValueMg;
211211
212- return s .str ();
212+ return ss .str ();
213213}
214214
215- string pretty_pv (Position& pos, int depth, Value value, uint64_t msecs, Move pv[]) {
215+ string pretty_pv (Position& pos, int depth, Value value, int64_t msecs, Move pv[]) {
216216
217217 const uint64_t K = 1000 ;
218218 const uint64_t M = 1000000 ;
219219
220220 std::stack<StateInfo> st;
221221 Move* m = pv;
222- string san, padding;
223- size_t length;
224- stringstream s;
222+ string san, str, padding;
223+ stringstream ss;
225224
226- s << setw (2 ) << depth
227- << setw (8 ) << score_to_string (value)
228- << setw (8 ) << time_to_string (msecs);
225+ ss << setw (2 ) << depth << setw (8 ) << format (value) << setw (8 ) << format (msecs);
229226
230227 if (pos.nodes_searched () < M)
231- s << setw (8 ) << pos.nodes_searched () / 1 << " " ;
228+ ss << setw (8 ) << pos.nodes_searched () / 1 << " " ;
232229
233230 else if (pos.nodes_searched () < K * M)
234- s << setw (7 ) << pos.nodes_searched () / K << " K " ;
231+ ss << setw (7 ) << pos.nodes_searched () / K << " K " ;
235232
236233 else
237- s << setw (7 ) << pos.nodes_searched () / M << " M " ;
234+ ss << setw (7 ) << pos.nodes_searched () / M << " M " ;
238235
239- padding = string (s .str (). length (), ' ' );
240- length = padding .length ();
236+ str = ss .str ();
237+ padding = string (str .length (), ' ' );
241238
242239 while (*m != MOVE_NONE )
243240 {
244- san = move_to_san (pos, *m);
241+ san = move_to_san (pos, *m) + ' ' ;
245242
246- if (length + san.length () > 80 )
247- {
248- s << " \n " + padding;
249- length = padding.length ();
250- }
243+ if ((str.length () + san.length ()) % 80 <= san.length ()) // Exceed 80 cols
244+ str += " \n " + padding;
251245
252- s << san << ' ' ;
253- length += san.length () + 1 ;
246+ str += san;
254247
255248 st.push (StateInfo ());
256249 pos.do_move (*m++, st.top ());
@@ -259,5 +252,5 @@ string pretty_pv(Position& pos, int depth, Value value, uint64_t msecs, Move pv[
259252 while (m != pv)
260253 pos.undo_move (*--m);
261254
262- return s. str () ;
255+ return str;
263256}
0 commit comments