constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
constexpr Bitboard KingFlank[FILE_NB] = {
- QueenSide, QueenSide, QueenSide,
+ QueenSide ^ FileDBB, QueenSide, QueenSide,
CenterFiles, CenterFiles,
- KingSide, KingSide, KingSide
+ KingSide, KingSide, KingSide ^ FileEBB
};
// Threshold for lazy and space evaluation
constexpr Score KnightOnQueen = S( 21, 11);
constexpr Score LongDiagonalBishop = S( 22, 0);
constexpr Score MinorBehindPawn = S( 16, 0);
- constexpr Score Overload = S( 16, 7);
+ constexpr Score Overload = S( 13, 6);
constexpr Score PawnlessFlank = S( 20, 80);
constexpr Score RookOnPawn = S( 8, 24);
constexpr Score SliderOnQueen = S( 42, 21);
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
- Bitboard b, weak, defended, nonPawnEnemies, stronglyProtected, safeThreats;
+ Bitboard b, weak, defended, nonPawnEnemies, stronglyProtected, safe;
Score score = SCORE_ZERO;
// Non-pawn enemies
// Enemies not strongly protected and under our attack
weak = pos.pieces(Them) & ~stronglyProtected & attackedBy[Us][ALL_PIECES];
+ // Safe or protected squares
+ safe = ~attackedBy[Them][ALL_PIECES] | attackedBy[Us][ALL_PIECES];
+
// Bonus according to the kind of attacking pieces
if (defended | weak)
{
score += ThreatByMinor[type_of(pos.piece_on(s))];
if (type_of(pos.piece_on(s)) != PAWN)
score += ThreatByRank * (int)relative_rank(Them, s);
+
+ else if (pos.blockers_for_king(Them) & s)
+ score += ThreatByRank * (int)relative_rank(Them, s) / 2;
}
- b = (pos.pieces(Them, QUEEN) | weak) & attackedBy[Us][ROOK];
+ b = weak & attackedBy[Us][ROOK];
while (b)
{
Square s = pop_lsb(&b);
score += ThreatByRook[type_of(pos.piece_on(s))];
if (type_of(pos.piece_on(s)) != PAWN)
score += ThreatByRank * (int)relative_rank(Them, s);
+
+ else if (pos.blockers_for_king(Them) & s)
+ score += ThreatByRank * (int)relative_rank(Them, s) / 2;
}
- // Bonus for king attacks on pawns or pieces which are not pawn-defended
if (weak & attackedBy[Us][KING])
score += ThreatByKing;
score += Hanging * popcount(weak & ~attackedBy[Them][ALL_PIECES]);
- // Bonus for overload (non-pawn enemies attacked once or more and defended exactly once)
- b = nonPawnEnemies
- & attackedBy[Us][ALL_PIECES]
- & attackedBy[Them][ALL_PIECES] & ~attackedBy2[Them];
+ b = weak & nonPawnEnemies & attackedBy[Them][ALL_PIECES];
score += Overload * popcount(b);
}
if (pos.pieces(Us, ROOK, QUEEN))
score += WeakUnopposedPawn * pe->weak_unopposed(Them);
- // Our safe or protected pawns
- b = pos.pieces(Us, PAWN)
- & (~attackedBy[Them][ALL_PIECES] | attackedBy[Us][ALL_PIECES]);
-
- safeThreats = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
- score += ThreatBySafePawn * popcount(safeThreats);
-
// Find squares where our pawns can push on the next move
b = shift<Up>(pos.pieces(Us, PAWN)) & ~pos.pieces();
b |= shift<Up>(b & TRank3BB) & ~pos.pieces();
- // Keep only the squares which are not completely unsafe
- b &= ~attackedBy[Them][PAWN]
- & (attackedBy[Us][ALL_PIECES] | ~attackedBy[Them][ALL_PIECES]);
+ // Keep only the squares which are relatively safe
+ b &= ~attackedBy[Them][PAWN] & safe;
// Bonus for safe pawn threats on the next move
- b = pawn_attacks_bb<Us>(b)
- & pos.pieces(Them)
- & ~attackedBy[Us][PAWN];
-
+ b = pawn_attacks_bb<Us>(b) & pos.pieces(Them);
score += ThreatByPawnPush * popcount(b);
+ // Our safe or protected pawns
+ b = pos.pieces(Us, PAWN) & safe;
+
+ b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
+ score += ThreatBySafePawn * popcount(b);
+
// Bonus for threats on the next moves against enemy queen
if (pos.count<QUEEN>(Them) == 1)
{
Square s = pos.square<QUEEN>(Them);
- safeThreats = mobilityArea[Us] & ~stronglyProtected;
+ safe = mobilityArea[Us] & ~stronglyProtected;
b = attackedBy[Us][KNIGHT] & pos.attacks_from<KNIGHT>(s);
- score += KnightOnQueen * popcount(b & safeThreats);
+ score += KnightOnQueen * popcount(b & safe);
b = (attackedBy[Us][BISHOP] & pos.attacks_from<BISHOP>(s))
| (attackedBy[Us][ROOK ] & pos.attacks_from<ROOK >(s));
- score += SliderOnQueen * popcount(b & safeThreats & attackedBy2[Us]);
+ score += SliderOnQueen * popcount(b & safe & attackedBy2[Us]);
}
if (T)