- stream.str("");
- stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
- std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
-
- Value margin;
- do_evaluate<true>(pos, margin);
-
- std::string totals = stream.str();
- stream.str("");
-
- stream << std::setw(21) << "Eval term " << "| White | Black | Total \n"
- << " | MG EG | MG EG | MG EG \n"
- << "---------------------+-------------+-------------+---------------\n";
-
- row("Material, PST, Tempo", PST);
- row("Material imbalance", IMBALANCE);
- row("Pawns", PAWN);
- row("Knights", KNIGHT);
- row("Bishops", BISHOP);
- row("Rooks", ROOK);
- row("Queens", QUEEN);
- row("Mobility", MOBILITY);
- row("King safety", KING);
- row("Threats", THREAT);
- row("Passed pawns", PASSED);
- row("Unstoppable pawns", UNSTOPPABLE);
- row("Space", SPACE);
-
- stream << "---------------------+-------------+-------------+---------------\n";
- row("Total", TOTAL);
- stream << totals;
-
- return stream.str();
+ std::memset(terms, 0, sizeof(terms));
+
+ Value v = do_evaluate<true>(pos);
+ v = pos.side_to_move() == WHITE ? v : -v; // White's point of view
+
+ std::stringstream ss;
+ ss << std::showpoint << std::noshowpos << std::fixed << std::setprecision(2)
+ << " Eval term | White | Black | Total \n"
+ << " | MG EG | MG EG | MG EG \n"
+ << "---------------------+-------------+-------------+-------------\n";
+
+ format_row(ss, "Material, PST, Tempo", PST);
+ format_row(ss, "Material imbalance", IMBALANCE);
+ format_row(ss, "Pawns", PAWN);
+ format_row(ss, "Knights", KNIGHT);
+ format_row(ss, "Bishops", BISHOP);
+ format_row(ss, "Rooks", ROOK);
+ format_row(ss, "Queens", QUEEN);
+ format_row(ss, "Mobility", MOBILITY);
+ format_row(ss, "King safety", KING);
+ format_row(ss, "Threats", THREAT);
+ format_row(ss, "Passed pawns", PASSED);
+ format_row(ss, "Space", SPACE);
+
+ ss << "---------------------+-------------+-------------+-------------\n";
+ format_row(ss, "Total", TOTAL);
+
+ ss << "\nTotal Evaluation: " << to_cp(v) << " (white side)\n";
+
+ return ss.str();
+ }
+
+} // namespace
+
+
+namespace Eval {
+
+ /// evaluate() is the main evaluation function. It returns a static evaluation
+ /// of the position always from the point of view of the side to move.
+
+ Value evaluate(const Position& pos) {
+ return do_evaluate<false>(pos);
+ }
+
+
+ /// trace() is like evaluate(), but instead of returning a value, it returns
+ /// a string (suitable for outputting to stdout) that contains the detailed
+ /// descriptions and values of each evaluation term. It's mainly used for
+ /// debugging.
+ std::string trace(const Position& pos) {
+ return Tracing::do_trace(pos);
+ }
+
+
+ /// init() computes evaluation weights from the corresponding UCI parameters
+ /// and setup king tables.
+
+ void init() {
+
+ Weights[Mobility] = weight_option("Mobility (Midgame)", "Mobility (Endgame)", WeightsInternal[Mobility]);
+ Weights[PawnStructure] = weight_option("Pawn Structure (Midgame)", "Pawn Structure (Endgame)", WeightsInternal[PawnStructure]);
+ Weights[PassedPawns] = weight_option("Passed Pawns (Midgame)", "Passed Pawns (Endgame)", WeightsInternal[PassedPawns]);
+ Weights[Space] = weight_option("Space", "Space", WeightsInternal[Space]);
+ Weights[KingDangerUs] = weight_option("Cowardice", "Cowardice", WeightsInternal[KingDangerUs]);
+ Weights[KingDangerThem] = weight_option("Aggressiveness", "Aggressiveness", WeightsInternal[KingDangerThem]);
+
+ const double MaxSlope = 30;
+ const double Peak = 1280;
+
+ for (int t = 0, i = 1; i < 100; ++i)
+ {
+ t = int(std::min(Peak, std::min(0.4 * i * i, t + MaxSlope)));
+
+ KingDanger[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
+ KingDanger[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
+ }