Skip to content

Commit 89d9db2

Browse files
mcostalbazamar
authored andcommitted
Rename Tracing methods
Easier to understand and more in line with standard Trace classes naming like: http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx No functional change.
1 parent 907f912 commit 89d9db2

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/evaluate.cpp

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ namespace {
7979
MATERIAL = 8, IMBALANCE, MOBILITY, THREAT, PASSED, SPACE, TOTAL, TERMS_NB
8080
};
8181

82-
Score terms[COLOR_NB][TERMS_NB];
82+
Score scores[COLOR_NB][TERMS_NB];
8383
EvalInfo ei;
8484
ScaleFactor sf;
8585

8686
double to_cp(Value v);
87-
void add_term(int idx, Score term_w, Score term_b = SCORE_ZERO);
88-
void format_row(std::stringstream& ss, const char* name, int idx);
87+
void write(int idx, Color c, Score s);
88+
void write(int idx, Score w, Score b = SCORE_ZERO);
89+
void print(std::stringstream& ss, const char* name, int idx);
8990
std::string do_trace(const Position& pos);
9091
}
9192

@@ -370,7 +371,7 @@ namespace {
370371
}
371372

372373
if (Trace)
373-
Tracing::terms[Us][Pt] = score;
374+
Tracing::write(Pt, Us, score);
374375

375376
return score - evaluate_pieces<NextPt, Them, Trace>(pos, ei, mobility, mobilityArea);
376377
}
@@ -484,7 +485,7 @@ namespace {
484485
}
485486

486487
if (Trace)
487-
Tracing::terms[Us][KING] = score;
488+
Tracing::write(KING, Us, score);
488489

489490
return score;
490491
}
@@ -536,7 +537,7 @@ namespace {
536537
}
537538

538539
if (Trace)
539-
Tracing::terms[Us][Tracing::THREAT] = score;
540+
Tracing::write(Tracing::THREAT, Us, score);
540541

541542
return score;
542543
}
@@ -619,7 +620,7 @@ namespace {
619620
}
620621

621622
if (Trace)
622-
Tracing::terms[Us][Tracing::PASSED] = apply_weight(score, Weights[PassedPawns]);
623+
Tracing::write(Tracing::PASSED, Us, apply_weight(score, Weights[PassedPawns]));
623624

624625
// Add the scores to the middlegame and endgame eval
625626
return apply_weight(score, Weights[PassedPawns]);
@@ -780,15 +781,15 @@ namespace {
780781
// In case of tracing add all single evaluation contributions for both white and black
781782
if (Trace)
782783
{
783-
Tracing::add_term(Tracing::MATERIAL, pos.psq_score());
784-
Tracing::add_term(Tracing::IMBALANCE, ei.mi->material_value());
785-
Tracing::add_term(PAWN, ei.pi->pawns_value());
786-
Tracing::add_term(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility])
787-
, apply_weight(mobility[BLACK], Weights[Mobility]));
784+
Tracing::write(Tracing::MATERIAL, pos.psq_score());
785+
Tracing::write(Tracing::IMBALANCE, ei.mi->material_value());
786+
Tracing::write(PAWN, ei.pi->pawns_value());
787+
Tracing::write(Tracing::MOBILITY, apply_weight(mobility[WHITE], Weights[Mobility])
788+
, apply_weight(mobility[BLACK], Weights[Mobility]));
788789
Score w = ei.mi->space_weight() * evaluate_space<WHITE>(pos, ei);
789790
Score b = ei.mi->space_weight() * evaluate_space<BLACK>(pos, ei);
790-
Tracing::add_term(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
791-
Tracing::add_term(Tracing::TOTAL, score);
791+
Tracing::write(Tracing::SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
792+
Tracing::write(Tracing::TOTAL, score);
792793
Tracing::ei = ei;
793794
Tracing::sf = sf;
794795
}
@@ -801,16 +802,18 @@ namespace {
801802

802803
double Tracing::to_cp(Value v) { return double(v) / PawnValueEg; }
803804

804-
void Tracing::add_term(int idx, Score wScore, Score bScore) {
805+
void Tracing::write(int idx, Color c, Score s) { scores[c][idx] = s; }
805806

806-
terms[WHITE][idx] = wScore;
807-
terms[BLACK][idx] = bScore;
807+
void Tracing::write(int idx, Score w, Score b) {
808+
809+
write(idx, WHITE, w);
810+
write(idx, BLACK, b);
808811
}
809812

810-
void Tracing::format_row(std::stringstream& ss, const char* name, int idx) {
813+
void Tracing::print(std::stringstream& ss, const char* name, int idx) {
811814

812-
Score wScore = terms[WHITE][idx];
813-
Score bScore = terms[BLACK][idx];
815+
Score wScore = scores[WHITE][idx];
816+
Score bScore = scores[BLACK][idx];
814817

815818
switch (idx) {
816819
case MATERIAL: case IMBALANCE: case PAWN: case TOTAL:
@@ -831,7 +834,7 @@ namespace {
831834

832835
std::string Tracing::do_trace(const Position& pos) {
833836

834-
std::memset(terms, 0, sizeof(terms));
837+
std::memset(scores, 0, sizeof(scores));
835838

836839
Value v = do_evaluate<true>(pos);
837840
v = pos.side_to_move() == WHITE ? v : -v; // White's point of view
@@ -842,21 +845,21 @@ namespace {
842845
<< " | MG EG | MG EG | MG EG \n"
843846
<< "----------------+-------------+-------------+-------------\n";
844847

845-
format_row(ss, "Material", MATERIAL);
846-
format_row(ss, "Imbalance", IMBALANCE);
847-
format_row(ss, "Pawns", PAWN);
848-
format_row(ss, "Knights", KNIGHT);
849-
format_row(ss, "Bishops", BISHOP);
850-
format_row(ss, "Rooks", ROOK);
851-
format_row(ss, "Queens", QUEEN);
852-
format_row(ss, "Mobility", MOBILITY);
853-
format_row(ss, "King safety", KING);
854-
format_row(ss, "Threats", THREAT);
855-
format_row(ss, "Passed pawns", PASSED);
856-
format_row(ss, "Space", SPACE);
848+
print(ss, "Material", MATERIAL);
849+
print(ss, "Imbalance", IMBALANCE);
850+
print(ss, "Pawns", PAWN);
851+
print(ss, "Knights", KNIGHT);
852+
print(ss, "Bishops", BISHOP);
853+
print(ss, "Rooks", ROOK);
854+
print(ss, "Queens", QUEEN);
855+
print(ss, "Mobility", MOBILITY);
856+
print(ss, "King safety", KING);
857+
print(ss, "Threats", THREAT);
858+
print(ss, "Passed pawns", PASSED);
859+
print(ss, "Space", SPACE);
857860

858861
ss << "----------------+-------------+-------------+-------------\n";
859-
format_row(ss, "Total", TOTAL);
862+
print(ss, "Total", TOTAL);
860863

861864
ss << "\nTotal Evaluation: " << to_cp(v) << " (white side)\n";
862865

0 commit comments

Comments
 (0)