mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43: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>
|
||||
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);
|
||||
|
||||
template<Color Us>
|
||||
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_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 tactical threats, we need full attack information including king
|
||||
score += evaluate_threats<WHITE>(pos, ei)
|
||||
- evaluate_threats<BLACK>(pos, ei);
|
||||
score += evaluate_threats<WHITE, Trace>(pos, ei)
|
||||
- evaluate_threats<BLACK, Trace>(pos, ei);
|
||||
|
||||
// Evaluate passed pawns, we need full attack information including king
|
||||
score += evaluate_passed_pawns<WHITE>(pos, ei)
|
||||
- evaluate_passed_pawns<BLACK>(pos, ei);
|
||||
score += evaluate_passed_pawns<WHITE, Trace>(pos, ei)
|
||||
- evaluate_passed_pawns<BLACK, Trace>(pos, ei);
|
||||
|
||||
// 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))
|
||||
|
@ -444,9 +444,6 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
trace_add(PST, pos.psq_score());
|
||||
trace_add(IMBALANCE, ei.mi->material_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));
|
||||
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);
|
||||
|
@ -631,7 +628,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
// evaluate_threats<>() assigns bonuses according to the type of attacking piece
|
||||
// and the type of attacked one.
|
||||
|
||||
template<Color Us>
|
||||
template<Color Us, bool Trace>
|
||||
Score evaluate_threats(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
|
@ -651,20 +648,22 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
& ~ei.attackedBy[Them][PAWN]
|
||||
& ei.attackedBy[Us][ALL_PIECES];
|
||||
|
||||
if (!weakEnemies)
|
||||
return score;
|
||||
|
||||
// Add bonus according to type of attacked enemy piece and to the
|
||||
// type of attacking piece, from knights to queens. Kings are not
|
||||
// considered because are already handled in king evaluation.
|
||||
for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++)
|
||||
{
|
||||
b = ei.attackedBy[Us][pt1] & weakEnemies;
|
||||
if (b)
|
||||
for (PieceType pt2 = PAWN; pt2 < KING; pt2++)
|
||||
if (b & pos.pieces(pt2))
|
||||
score += ThreatBonus[pt1][pt2];
|
||||
}
|
||||
if (weakEnemies)
|
||||
for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++)
|
||||
{
|
||||
b = ei.attackedBy[Us][pt1] & weakEnemies;
|
||||
if (b)
|
||||
for (PieceType pt2 = PAWN; pt2 < KING; pt2++)
|
||||
if (b & pos.pieces(pt2))
|
||||
score += ThreatBonus[pt1][pt2];
|
||||
}
|
||||
|
||||
if (Trace)
|
||||
TracedScores[Us][THREAT] = 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][BISHOP] | ei.attackedBy[Us][ROOK]
|
||||
| ei.attackedBy[Us][QUEEN] | ei.attackedBy[Us][KING];
|
||||
if (Trace)
|
||||
TracedScores[Us][MOBILITY] = apply_weight(mobility, Weights[Mobility]);
|
||||
|
||||
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
|
||||
|
||||
template<Color Us>
|
||||
template<Color Us, bool Trace>
|
||||
Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
|
||||
|
||||
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);
|
||||
|
||||
if (!b)
|
||||
return SCORE_ZERO;
|
||||
|
||||
do {
|
||||
while (b)
|
||||
{
|
||||
Square s = pop_lsb(&b);
|
||||
|
||||
assert(pos.pawn_is_passed(Us, s));
|
||||
|
@ -902,7 +902,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
|
|||
}
|
||||
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
|
||||
return apply_weight(score, Weights[PassedPawns]);
|
||||
|
|
Loading…
Add table
Reference in a new issue