1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Consolidate to centipawns conversion

avoid doing this calculations in multiple places.

closes https://github.com/official-stockfish/Stockfish/pull/4686

No functional change
This commit is contained in:
Joost VandeVondele 2023-07-15 13:34:16 +02:00
parent e89469925d
commit e8a5c64988
4 changed files with 15 additions and 9 deletions

View file

@ -58,8 +58,6 @@ namespace Eval {
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.
@ -194,11 +192,11 @@ std::string Eval::trace(Position& pos) {
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";

View file

@ -224,7 +224,7 @@ namespace Stockfish::Eval::NNUE {
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;
@ -249,15 +249,15 @@ namespace Stockfish::Eval::NNUE {
}
// 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;
}

View file

@ -303,6 +303,13 @@ void UCI::loop(int argc, char* argv[]) {
}
/// 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.
@ -316,7 +323,7 @@ string UCI::value(Value v) {
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

View file

@ -76,6 +76,7 @@ private:
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);