mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
More uniform tracing code
No functional change.
This commit is contained in:
parent
d4a02b135d
commit
eafb66e1aa
1 changed files with 30 additions and 27 deletions
|
@ -237,13 +237,13 @@ namespace {
|
||||||
template<Color Us, bool Trace>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]);
|
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]);
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_threats(const Position& pos, EvalInfo& ei);
|
Score evaluate_threats(const Position& pos, EvalInfo& ei);
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
int evaluate_space(const Position& pos, EvalInfo& ei);
|
int evaluate_space(const Position& pos, EvalInfo& ei);
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
|
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
|
||||||
|
|
||||||
Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei);
|
Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei);
|
||||||
|
@ -392,12 +392,12 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
- evaluate_king<BLACK, Trace>(pos, ei, margins);
|
- evaluate_king<BLACK, Trace>(pos, ei, margins);
|
||||||
|
|
||||||
// Evaluate tactical threats, we need full attack information including king
|
// Evaluate tactical threats, we need full attack information including king
|
||||||
score += evaluate_threats<WHITE>(pos, ei)
|
score += evaluate_threats<WHITE, Trace>(pos, ei)
|
||||||
- evaluate_threats<BLACK>(pos, ei);
|
- evaluate_threats<BLACK, Trace>(pos, ei);
|
||||||
|
|
||||||
// Evaluate passed pawns, we need full attack information including king
|
// Evaluate passed pawns, we need full attack information including king
|
||||||
score += evaluate_passed_pawns<WHITE>(pos, ei)
|
score += evaluate_passed_pawns<WHITE, Trace>(pos, ei)
|
||||||
- evaluate_passed_pawns<BLACK>(pos, ei);
|
- evaluate_passed_pawns<BLACK, Trace>(pos, ei);
|
||||||
|
|
||||||
// If one side has only a king, check whether exists any unstoppable passed pawn
|
// If one side has only a king, check whether exists any unstoppable passed pawn
|
||||||
if (!pos.non_pawn_material(WHITE) || !pos.non_pawn_material(BLACK))
|
if (!pos.non_pawn_material(WHITE) || !pos.non_pawn_material(BLACK))
|
||||||
|
@ -444,9 +444,6 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
trace_add(PST, pos.psq_score());
|
trace_add(PST, pos.psq_score());
|
||||||
trace_add(IMBALANCE, ei.mi->material_value());
|
trace_add(IMBALANCE, ei.mi->material_value());
|
||||||
trace_add(PAWN, ei.pi->pawns_value());
|
trace_add(PAWN, ei.pi->pawns_value());
|
||||||
trace_add(MOBILITY, apply_weight(mobilityWhite, Weights[Mobility]), apply_weight(mobilityBlack, Weights[Mobility]));
|
|
||||||
trace_add(THREAT, evaluate_threats<WHITE>(pos, ei), evaluate_threats<BLACK>(pos, ei));
|
|
||||||
trace_add(PASSED, evaluate_passed_pawns<WHITE>(pos, ei), evaluate_passed_pawns<BLACK>(pos, ei));
|
|
||||||
trace_add(UNSTOPPABLE, evaluate_unstoppable_pawns(pos, ei));
|
trace_add(UNSTOPPABLE, evaluate_unstoppable_pawns(pos, ei));
|
||||||
Score w = make_score(ei.mi->space_weight() * evaluate_space<WHITE>(pos, ei), 0);
|
Score w = make_score(ei.mi->space_weight() * evaluate_space<WHITE>(pos, ei), 0);
|
||||||
Score b = make_score(ei.mi->space_weight() * evaluate_space<BLACK>(pos, ei), 0);
|
Score b = make_score(ei.mi->space_weight() * evaluate_space<BLACK>(pos, ei), 0);
|
||||||
|
@ -631,7 +628,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
// evaluate_threats<>() assigns bonuses according to the type of attacking piece
|
// evaluate_threats<>() assigns bonuses according to the type of attacking piece
|
||||||
// and the type of attacked one.
|
// and the type of attacked one.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_threats(const Position& pos, EvalInfo& ei) {
|
Score evaluate_threats(const Position& pos, EvalInfo& ei) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
@ -651,12 +648,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
& ~ei.attackedBy[Them][PAWN]
|
& ~ei.attackedBy[Them][PAWN]
|
||||||
& ei.attackedBy[Us][ALL_PIECES];
|
& ei.attackedBy[Us][ALL_PIECES];
|
||||||
|
|
||||||
if (!weakEnemies)
|
|
||||||
return score;
|
|
||||||
|
|
||||||
// Add bonus according to type of attacked enemy piece and to the
|
// Add bonus according to type of attacked enemy piece and to the
|
||||||
// type of attacking piece, from knights to queens. Kings are not
|
// type of attacking piece, from knights to queens. Kings are not
|
||||||
// considered because are already handled in king evaluation.
|
// considered because are already handled in king evaluation.
|
||||||
|
if (weakEnemies)
|
||||||
for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++)
|
for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++)
|
||||||
{
|
{
|
||||||
b = ei.attackedBy[Us][pt1] & weakEnemies;
|
b = ei.attackedBy[Us][pt1] & weakEnemies;
|
||||||
|
@ -665,6 +660,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
if (b & pos.pieces(pt2))
|
if (b & pos.pieces(pt2))
|
||||||
score += ThreatBonus[pt1][pt2];
|
score += ThreatBonus[pt1][pt2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Trace)
|
||||||
|
TracedScores[Us][THREAT] = score;
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,6 +690,9 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
ei.attackedBy[Us][ALL_PIECES] = ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT]
|
ei.attackedBy[Us][ALL_PIECES] = ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT]
|
||||||
| ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
|
| ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
|
||||||
| ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING];
|
| ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING];
|
||||||
|
if (Trace)
|
||||||
|
TracedScores[Us][MOBILITY] = apply_weight(mobility, Weights[Mobility]);
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +812,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
|
|
||||||
// evaluate_passed_pawns<>() evaluates the passed pawns of the given color
|
// evaluate_passed_pawns<>() evaluates the passed pawns of the given color
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
|
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
@ -820,10 +822,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
|
|
||||||
b = ei.pi->passed_pawns(Us);
|
b = ei.pi->passed_pawns(Us);
|
||||||
|
|
||||||
if (!b)
|
while (b)
|
||||||
return SCORE_ZERO;
|
{
|
||||||
|
|
||||||
do {
|
|
||||||
Square s = pop_lsb(&b);
|
Square s = pop_lsb(&b);
|
||||||
|
|
||||||
assert(pos.pawn_is_passed(Us, s));
|
assert(pos.pawn_is_passed(Us, s));
|
||||||
|
@ -902,7 +902,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
||||||
}
|
}
|
||||||
score += make_score(mbonus, ebonus);
|
score += make_score(mbonus, ebonus);
|
||||||
|
|
||||||
} while (b);
|
}
|
||||||
|
|
||||||
|
if (Trace)
|
||||||
|
TracedScores[Us][PASSED] = apply_weight(score, Weights[PassedPawns]);
|
||||||
|
|
||||||
// Add the scores to the middle game and endgame eval
|
// Add the scores to the middle game and endgame eval
|
||||||
return apply_weight(score, Weights[PassedPawns]);
|
return apply_weight(score, Weights[PassedPawns]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue