constexpr Score KingProtector[] = { S(3, 5), S(4, 3), S(3, 0), S(1, -1) };
// Assorted bonuses and penalties
- constexpr Score BishopPawns = S( 8, 12);
+ constexpr Score BishopPawns = S( 3, 5);
constexpr Score CloseEnemies = S( 7, 0);
constexpr Score Connectivity = S( 3, 1);
constexpr Score CorneredBishop = S( 50, 50);
// Find our pawns that are blocked or on the first two ranks
Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
- // Squares occupied by those pawns, by our king, or controlled by enemy pawns
+ // Squares occupied by those pawns, by our king or queen, or controlled by enemy pawns
// are excluded from the mobility area.
- mobilityArea[Us] = ~(b | pos.square<KING>(Us) | pe->pawn_attacks(Them));
+ mobilityArea[Us] = ~(b | pos.pieces(Us, KING, QUEEN) | pe->pawn_attacks(Them));
// Initialise attackedBy bitboards for kings and pawns
attackedBy[Us][KING] = pos.attacks_from<KING>(pos.square<KING>(Us));
template<Tracing T> template<Color Us, PieceType Pt>
Score Evaluation<T>::pieces() {
- constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
+ constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
+ constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
: Rank5BB | Rank4BB | Rank3BB);
const Square* pl = pos.squares<Pt>(Us);
Bitboard b, bb;
Square s;
Score score = SCORE_ZERO;
- int mob;
attackedBy[Us][Pt] = 0;
kingAttacksCount[Us] += popcount(b & attackedBy[Them][KING]);
}
- mob = (Pt == KNIGHT || Pt == BISHOP) ? popcount(b & mobilityArea[Us] & ~pos.pieces(Us, QUEEN))
- : popcount(b & mobilityArea[Us]);
+ int mob = popcount(b & mobilityArea[Us]);
mobility[Us] += MobilityBonus[Pt - 2][mob];
if (Pt == BISHOP)
{
- // Penalty according to number of pawns on the same color square as the bishop
- score -= BishopPawns * pe->pawns_on_same_color_squares(Us, s);
+ // Penalty according to number of pawns on the same color square as the
+ // bishop, bigger when the center files are blocked with pawns.
+ Bitboard blocked = pos.pieces(Us, PAWN) & shift<Down>(pos.pieces());
+
+ score -= BishopPawns * pe->pawns_on_same_color_squares(Us, s)
+ * (1 + popcount(blocked & CenterFiles));
// Bonus for bishop on a long diagonal which can "see" both center squares
if (more_than_one(Center & (attacks_bb<BISHOP>(s, pos.pieces(PAWN)) | s)))
} // w != 0
// Scale down bonus for candidate passers which need more than one
- // pawn push to become passed or have a pawn in front of them.
+ // pawn push to become passed, or have a pawn in front of them.
if ( !pos.pawn_passed(Us, s + Up)
|| (pos.pieces(PAWN) & forward_file_bb(Us, s)))
bonus = bonus / 2;
if (pos.non_pawn_material() < SpaceThreshold)
return SCORE_ZERO;
- // Find the safe squares for our pieces inside the area defined by
- // SpaceMask. A square is unsafe if it is attacked by an enemy
- // pawn, or if it is undefended and attacked by an enemy piece.
+ // Find the available squares for our pieces inside the area defined by SpaceMask
Bitboard safe = SpaceMask
& ~pos.pieces(Us, PAWN)
& ~attackedBy[Them][PAWN];
Color strongSide = eg > VALUE_DRAW ? WHITE : BLACK;
int sf = me->scale_factor(pos, strongSide);
- // If we don't already have an unusual scale factor, check for certain
- // types of endgames, and use a lower scale for those.
- if (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN)
+ // If scale is not already specific, scale down the endgame via general heuristics
+ if (sf == SCALE_FACTOR_NORMAL)
{
if (pos.opposite_bishops())
{
else
sf = 46;
}
- // Endings where weaker side can place his king in front of the enemy's
- // pawns are drawish.
- else if ( abs(eg) <= BishopValueEg
- && pos.count<PAWN>(strongSide) <= 2
- && !pos.pawn_passed(~strongSide, pos.square<KING>(~strongSide)))
- sf = 37 + 7 * pos.count<PAWN>(strongSide);
+ else
+ sf = std::min(40 + 7 * pos.count<PAWN>(strongSide), sf);
}
return ScaleFactor(sf);