avoid doing this calculations in multiple places.
closes https://github.com/official-stockfish/Stockfish/pull/4686
No functional change
string currentEvalFileName = "None";
- static double to_cp(Value v) { return double(v) / UCI::NormalizeToPawnValue; }
-
/// NNUE::init() tries to load a NNUE network at startup time, or when the engine
/// receives a UCI command "setoption name EvalFile value nn-[a-z0-9]{12}.nnue"
/// The name of the NNUE network is always retrieved from the EvalFile option.
Value v;
v = NNUE::evaluate(pos, false);
v = pos.side_to_move() == WHITE ? v : -v;
- ss << "NNUE evaluation " << to_cp(v) << " (white side)\n";
+ ss << "NNUE evaluation " << 0.01 * UCI::to_cp(v) << " (white side)\n";
v = evaluate(pos);
v = pos.side_to_move() == WHITE ? v : -v;
- ss << "Final evaluation " << to_cp(v) << " (white side)";
+ ss << "Final evaluation " << 0.01 * UCI::to_cp(v) << " (white side)";
ss << " [with scaled NNUE, ...]";
ss << "\n";
buffer[0] = (v < 0 ? '-' : v > 0 ? '+' : ' ');
- int cp = std::abs(100 * v / UCI::NormalizeToPawnValue);
+ int cp = std::abs(UCI::to_cp(v));
if (cp >= 10000)
{
buffer[1] = '0' + cp / 10000; cp %= 10000;
}
- // format_cp_aligned_dot() converts a Value into (centi)pawns, always keeping two decimals.
+ // format_cp_aligned_dot() converts a Value into pawns, always keeping two decimals.
static void format_cp_aligned_dot(Value v, std::stringstream &stream) {
- const double cp = 1.0 * std::abs(int(v)) / UCI::NormalizeToPawnValue;
+ const double pawns = std::abs(0.01 * UCI::to_cp(v));
stream << (v < 0 ? '-' : v > 0 ? '+' : ' ')
<< std::setiosflags(std::ios::fixed)
<< std::setw(6)
<< std::setprecision(2)
- << cp;
+ << pawns;
}
}
+/// Turns a Value to an integer centipawn number,
+/// without treatment of mate and similar special scores.
+int UCI::to_cp(Value v) {
+
+ return 100 * v / UCI::NormalizeToPawnValue;
+}
+
/// UCI::value() converts a Value to a string by adhering to the UCI protocol specification:
///
/// cp <x> The score from the engine's point of view in centipawns.
stringstream ss;
if (abs(v) < VALUE_TB_WIN_IN_MAX_PLY)
- ss << "cp " << v * 100 / NormalizeToPawnValue;
+ ss << "cp " << UCI::to_cp(v);
else if (abs(v) < VALUE_MATE_IN_MAX_PLY)
{
const int ply = VALUE_MATE_IN_MAX_PLY - 1 - std::abs(v); // recompute ss->ply
void init(OptionsMap&);
void loop(int argc, char* argv[]);
+int to_cp(Value v);
std::string value(Value v);
std::string square(Square s);
std::string move(Move m, bool chess960);