Skip to content

Commit fcf2a34

Browse files
committed
Some more work in pretty_pv
No functional change.
1 parent 698b645 commit fcf2a34

3 files changed

Lines changed: 34 additions & 39 deletions

File tree

src/bitbase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ namespace {
114114
result = UNKNOWN;
115115

116116
// Check if two pieces are on the same square or if a king can be captured
117-
if ( square_distance(wksq, bksq) <= 1 || wksq == psq || bksq == psq
117+
if ( square_distance(wksq, bksq) <= 1
118+
|| wksq == psq
119+
|| bksq == psq
118120
|| (us == WHITE && (StepAttacksBB[PAWN][psq] & bksq)))
119121
result = INVALID;
120122

src/notation.cpp

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ static const char* PieceToChar[COLOR_NB] = { " PNBRQK", " pnbrqk" };
4040

4141
string 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
}

src/notation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ std::string score_to_uci(Value v, Value alpha = -VALUE_INFINITE, Value beta = VA
3030
Move move_from_uci(const Position& pos, std::string& str);
3131
const std::string move_to_uci(Move m, bool chess960);
3232
const std::string move_to_san(Position& pos, Move m);
33-
std::string pretty_pv(Position& pos, int depth, Value score, uint64_t msecs, Move pv[]);
33+
std::string pretty_pv(Position& pos, int depth, Value score, int64_t msecs, Move pv[]);
3434

3535
#endif // #ifndef NOTATION_H_INCLUDED

0 commit comments

Comments
 (0)