+ TimePoint elapsed = now();
+
+ for (const auto& cmd : list)
+ {
+ istringstream is(cmd);
+ is >> skipws >> token;
+
+ if (token == "go" || token == "eval")
+ {
+ cerr << "\nPosition: " << cnt++ << '/' << num << " (" << pos.fen() << ")" << endl;
+ if (token == "go")
+ {
+ go(pos, is, states);
+ Threads.main()->wait_for_search_finished();
+ nodes += Threads.nodes_searched();
+ }
+ else
+ trace_eval(pos);
+ }
+ else if (token == "setoption") setoption(is);
+ else if (token == "position") position(pos, is, states);
+ else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take a while
+ }
+
+ elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
+
+ dbg_print();
+
+ cerr << "\n==========================="
+ << "\nTotal time (ms) : " << elapsed
+ << "\nNodes searched : " << nodes
+ << "\nNodes/second : " << 1000 * nodes / elapsed << endl;
+ }
+
+ // The win rate model returns the probability of winning (in per mille units) given an
+ // eval and a game ply. It fits the LTC fishtest statistics rather accurately.
+ int win_rate_model(Value v, int ply) {
+
+ // The model only captures up to 240 plies, so limit the input and then rescale
+ double m = std::min(240, ply) / 64.0;
+
+ // The coefficients of a third-order polynomial fit is based on the fishtest data
+ // for two parameters that need to transform eval to the argument of a logistic
+ // function.
+ constexpr double as[] = { 0.33677609, -4.30175627, 33.08810557, 365.60223431};
+ constexpr double bs[] = { -2.50471102, 14.23235405, -14.33066859, 71.42705250 };
+
+ // Enforce that NormalizeToPawnValue corresponds to a 50% win rate at ply 64
+ static_assert(UCI::NormalizeToPawnValue == int(as[0] + as[1] + as[2] + as[3]));
+
+ double a = (((as[0] * m + as[1]) * m + as[2]) * m) + as[3];
+ double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
+
+ // Transform the eval to centipawns with limited range
+ double x = std::clamp(double(v), -4000.0, 4000.0);
+
+ // Return the win rate in per mille units rounded to the nearest value
+ return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));