+
+
+ // trace_row() is an helper function used by tracing code to register the
+ // values of a single evaluation term.
+
+ void trace_row(const char *name, int idx) {
+
+ Score term_w = TracedTerms[WHITE][idx];
+ Score term_b = TracedTerms[BLACK][idx];
+
+ switch (idx) {
+ case PST: case IMBALANCE: case PAWN: case UNSTOPPABLE: case TOTAL:
+ TraceStream << std::setw(20) << name << " | --- --- | --- --- | "
+ << std::setw(6) << to_cp(mg_value(term_w)) << " "
+ << std::setw(6) << to_cp(eg_value(term_w)) << " \n";
+ break;
+ default:
+ TraceStream << std::setw(20) << name << " | " << std::noshowpos
+ << std::setw(5) << to_cp(mg_value(term_w)) << " "
+ << std::setw(5) << to_cp(eg_value(term_w)) << " | "
+ << std::setw(5) << to_cp(mg_value(term_b)) << " "
+ << std::setw(5) << to_cp(eg_value(term_b)) << " | "
+ << std::showpos
+ << std::setw(6) << to_cp(mg_value(term_w - term_b)) << " "
+ << std::setw(6) << to_cp(eg_value(term_w - term_b)) << " \n";
+ }
+ }
+}
+
+
+/// trace_evaluate() is like evaluate() but instead of a value returns a string
+/// suitable to be print on stdout with the detailed descriptions and values of
+/// each evaluation term. Used mainly for debugging.
+
+std::string trace_evaluate(const Position& pos) {
+
+ Value margin;
+ std::string totals;
+
+ TraceStream.str("");
+ TraceStream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
+ memset(TracedTerms, 0, 2 * 16 * sizeof(Score));
+
+ do_evaluate<false, true>(pos, margin);
+
+ totals = TraceStream.str();
+ TraceStream.str("");
+
+ TraceStream << std::setw(21) << "Eval term " << "| White | Black | Total \n"
+ << " | MG EG | MG EG | MG EG \n"
+ << "---------------------+-------------+-------------+---------------\n";
+
+ trace_row("Material, PST, Tempo", PST);
+ trace_row("Material imbalance", IMBALANCE);
+ trace_row("Pawns", PAWN);
+ trace_row("Knights", KNIGHT);
+ trace_row("Bishops", BISHOP);
+ trace_row("Rooks", ROOK);
+ trace_row("Queens", QUEEN);
+ trace_row("Mobility", MOBILITY);
+ trace_row("King safety", KING);
+ trace_row("Threats", THREAT);
+ trace_row("Passed pawns", PASSED);
+ trace_row("Unstoppable pawns", UNSTOPPABLE);
+ trace_row("Space", SPACE);
+
+ TraceStream << "---------------------+-------------+-------------+---------------\n";
+ trace_row("Total", TOTAL);
+ TraceStream << totals;
+
+ return TraceStream.str();