// MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game,
// indexed by piece type and number of attacked squares in the mobility area.
constexpr Score MobilityBonus[][32] = {
- { S(-62,-81), S(-53,-56), S(-12,-30), S( -4,-14), S( 3, 8), S( 13, 15), // Knight
- S( 22, 23), S( 28, 27), S( 33, 33) },
+ { S(-62,-81), S(-53,-56), S(-12,-31), S( -4,-16), S( 3, 5), S( 13, 11), // Knight
+ S( 22, 17), S( 28, 20), S( 33, 25) },
{ S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishop
S( 55, 54), S( 63, 57), S( 63, 65), S( 68, 73), S( 81, 78), S( 81, 86),
S( 91, 88), S( 98, 97) },
{ S(-60,-78), S(-20,-17), S( 2, 23), S( 3, 39), S( 3, 70), S( 11, 99), // Rook
S( 22,103), S( 31,121), S( 40,134), S( 40,139), S( 41,158), S( 48,164),
S( 57,168), S( 57,169), S( 62,172) },
- { S(-34,-36), S(-15,-21), S(-10, -1), S(-10, 22), S( 20, 41), S( 23, 56), // Queen
+ { S(-30,-48), S(-12,-30), S( -8, -7), S( -9, 19), S( 20, 40), S( 23, 55), // Queen
S( 23, 59), S( 35, 75), S( 38, 78), S( 53, 96), S( 64, 96), S( 65,100),
S( 65,121), S( 66,127), S( 67,131), S( 67,133), S( 72,136), S( 72,141),
S( 77,147), S( 79,150), S( 93,151), S(108,168), S(108,168), S(108,171),
// Assorted bonuses and penalties
constexpr Score BishopPawns = S( 3, 7);
+ constexpr Score BishopXRayPawns = S( 4, 5);
constexpr Score CorneredBishop = S( 50, 50);
constexpr Score FlankAttacks = S( 8, 0);
constexpr Score Hanging = S( 69, 36);
constexpr Score PassedFile = S( 11, 8);
constexpr Score PawnlessFlank = S( 17, 95);
constexpr Score RestrictedPiece = S( 7, 7);
+ constexpr Score RookOnKingRing = S( 16, 0);
constexpr Score RookOnQueenFile = S( 5, 9);
constexpr Score SliderOnQueen = S( 59, 18);
constexpr Score ThreatByKing = S( 24, 89);
kingAttackersWeight[Us] += KingAttackWeights[Pt];
kingAttacksCount[Us] += popcount(b & attackedBy[Them][KING]);
}
+ else if (Pt == ROOK && (file_bb(s) & kingRing[Them]))
+ score += RookOnKingRing;
int mob = popcount(b & mobilityArea[Us]);
if (Pt == BISHOP)
{
- // Penalty according to number of pawns on the same color square as the
+ // Penalty according to the number of our pawns on the same color square as the
// bishop, bigger when the center files are blocked with pawns and smaller
// when the bishop is outside the pawn chain.
Bitboard blocked = pos.pieces(Us, PAWN) & shift<Down>(pos.pieces());
score -= BishopPawns * pos.pawns_on_same_color_squares(Us, s)
* (!(attackedBy[Us][PAWN] & s) + popcount(blocked & CenterFiles));
+ // Penalty for all enemy pawns x-rayed
+ score -= BishopXRayPawns * popcount(PseudoAttacks[BISHOP][s] & pos.pieces(Them, PAWN));
+
// Bonus for bishop on a long diagonal which can "see" both center squares
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
score += LongDiagonalBishop;
return std::min(distance(pos.square<KING>(c), s), 5);
};
- Bitboard b, bb, squaresToQueen, unsafeSquares, candidatePassers, leverable;
+ Bitboard b, bb, squaresToQueen, unsafeSquares, blockedPassers, helpers;
Score score = SCORE_ZERO;
b = pe->passed_pawns(Us);
- candidatePassers = b & shift<Down>(pos.pieces(Them, PAWN));
- if (candidatePassers)
+ blockedPassers = b & shift<Down>(pos.pieces(Them, PAWN));
+ if (blockedPassers)
{
- // Can we lever the blocker of a candidate passer?
- leverable = shift<Up>(pos.pieces(Us, PAWN))
- & ~pos.pieces(Them)
- & (~attackedBy2[Them] | attackedBy[Us][ALL_PIECES])
- & (~(attackedBy[Them][KNIGHT] | attackedBy[Them][BISHOP])
- | (attackedBy[Us ][KNIGHT] | attackedBy[Us ][BISHOP]));
-
- // Remove candidate otherwise
- b &= ~candidatePassers
- | shift<WEST>(leverable)
- | shift<EAST>(leverable);
+ helpers = shift<Up>(pos.pieces(Us, PAWN))
+ & ~pos.pieces(Them)
+ & (~attackedBy2[Them] | attackedBy[Us][ALL_PIECES]);
+
+ // Remove blocked candidate passers that don't have help to pass
+ b &= ~blockedPassers
+ | shift<WEST>(helpers)
+ | shift<EAST>(helpers);
}
while (b)
// Compute the initiative bonus for the attacking side
int complexity = 9 * pe->passed_count()
- + 11 * pos.count<PAWN>()
+ + 12 * pos.count<PAWN>()
+ 9 * outflanking
+ 21 * pawnsOnBothFlanks
+ 24 * infiltration
+ 51 * !pos.non_pawn_material()
- 43 * almostUnwinnable
+ - 2 * pos.rule50_count()
-110 ;
Value mg = mg_value(score);
{
if ( pos.non_pawn_material(WHITE) == BishopValueMg
&& pos.non_pawn_material(BLACK) == BishopValueMg)
- sf = 22;
+ sf = 18 + 4 * popcount(pe->passed_pawns(strongSide));
else
sf = 22 + 3 * pos.count<ALL_PIECES>(strongSide);
}
else
sf = std::min(sf, 36 + 7 * pos.count<PAWN>(strongSide));
-
- sf = std::max(0, sf - (pos.rule50_count() - 12) / 4);
}
return ScaleFactor(sf);
Trace::add(TOTAL, score);
}
- return (pos.side_to_move() == WHITE ? v : -v) + Tempo; // Side to move point of view
+ // Side to move point of view
+ return (pos.side_to_move() == WHITE ? v : -v) + Tempo;
}
} // namespace