template<Color Us> Score passed() const;
template<Color Us> Score space() const;
ScaleFactor scale_factor(Value eg) const;
- Score initiative(Value eg) const;
+ Score initiative(Score score) const;
const Position& pos;
Material::Entry* me;
if (relative_rank(Us, s) >= RANK_5)
score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]);
- // Bonus for rook on same file as their queen
- if (file_bb(s) & pos.pieces(Them, QUEEN))
+ // Bonus for rook on the same file as a queen
+ if (file_bb(s) & pos.pieces(QUEEN))
score += RookOnQueenFile;
// Bonus for rook on an open or semi-open file
if (pos.is_on_semiopen_file(Us, s))
- score += RookOnFile[bool(pos.is_on_semiopen_file(Them, s))];
+ score += RookOnFile[pos.is_on_semiopen_file(Them, s)];
// Penalty when trapped by the king, even more if the king cannot castle
else if (mob <= 3)
|| (pos.pieces(PAWN) & (s + Up)))
bonus = bonus / 2;
- score += bonus - PassedFile * std::min(f, ~f);
+ score += bonus - PassedFile * map_to_queenside(f);
}
if (T)
// known attacking/defending status of the players.
template<Tracing T>
- Score Evaluation<T>::initiative(Value eg) const {
+ Score Evaluation<T>::initiative(Score score) const {
+
+ Value mg = mg_value(score);
+ Value eg = eg_value(score);
int outflanking = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
- distance<Rank>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
- 36 * almostUnwinnable
-103 ;
- // Now apply the bonus: note that we find the attacking side by extracting
- // the sign of the endgame value, and that we carefully cap the bonus so
- // that the endgame score will never change sign after the bonus.
+ // Now apply the bonus: note that we find the attacking side by extracting the
+ // sign of the midgame or endgame values, and that we carefully cap the bonus
+ // so that the midgame and endgame scores do not change sign after the bonus.
+ int u = ((mg > 0) - (mg < 0)) * std::max(std::min(complexity + 50, 0), -abs(mg));
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));
if (T)
- Trace::add(INITIATIVE, make_score(0, v));
+ Trace::add(INITIATIVE, make_score(u, v));
- return make_score(0, v);
+ return make_score(u, v);
}
&& pos.non_pawn_material() == 2 * BishopValueMg)
sf = 16 + 4 * pe->passed_count();
else
- sf = std::min(40 + (pos.opposite_bishops() ? 2 : 7) * pos.count<PAWN>(strongSide), sf);
+ sf = std::min(sf, 36 + (pos.opposite_bishops() ? 2 : 7) * pos.count<PAWN>(strongSide));
+ sf = std::max(0, sf - (pos.rule50_count() - 12) / 4 );
}
return ScaleFactor(sf);
+ passed< WHITE>() - passed< BLACK>()
+ space< WHITE>() - space< BLACK>();
- score += initiative(eg_value(score));
+ score += initiative(score);
// Interpolate between a middlegame and a (scaled by 'sf') endgame score
ScaleFactor sf = scale_factor(eg_value(score));