// Init king safety tables only if we are going to use them
if ( pos.piece_count(Us, QUEEN)
- && pos.non_pawn_material(Us) >= QueenValueMg + RookValueMg)
+ && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg)
{
ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8));
b &= ei.attackedBy[Us][PAWN];
mobility += MobilityBonus[Piece][mob];
+ // Add a bonus if a slider is pinning an enemy piece
+ if ( (Piece == BISHOP || Piece == ROOK || Piece == QUEEN)
+ && (PseudoAttacks[Piece][pos.king_square(Them)] & s))
+ {
+ b = BetweenBB[s][pos.king_square(Them)] & pos.pieces();
+
+ assert(b);
+
+ if (!more_than_one(b) && (b & pos.pieces(Them)))
+ score += ThreatBonus[Piece][type_of(pos.piece_on(lsb(b)))];
+ }
+
// Decrease score if we are attacked by an enemy pawn. Remaining part
// of threat evaluation must be done later when we have full attack info.
if (ei.attackedBy[Them][PAWN] & s)
& ~ei.attackedBy[Them][0];
if (undefendedMinors)
- score += UndefendedMinorPenalty;
+ score += more_than_one(undefendedMinors) ? UndefendedMinorPenalty * 2
+ : UndefendedMinorPenalty;
// Enemy pieces not defended by a pawn and under our attack
weakEnemies = pos.pieces(Them)