+ // 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)));
+ }
+