// king is on g8 and there's a white knight on g5, this knight adds
// 2 to kingAdjacentZoneAttacksCount[BLACK].
int kingAdjacentZoneAttacksCount[COLOR_NB];
+
+ Bitboard pinnedPieces[COLOR_NB];
};
// Evaluation grain size, must be a power of 2
const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Down = (Us == WHITE ? DELTA_S : DELTA_N);
+ ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
+
Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
: Piece == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN))
: pos.attacks_from<Piece>(s);
+ if (ei.pinnedPieces[Us] & s)
+ b &= PseudoAttacks[QUEEN][pos.king_square(Us)];
+
ei.attackedBy[Us][Piece] |= b;
if (b & ei.kingRing[Them])
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) {
ExtMove *end, *cur = mlist;
- Bitboard pinned = pos.pinned_pieces();
+ Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
Square ksq = pos.king_square(pos.side_to_move());
end = pos.checkers() ? generate<EVASIONS>(pos, mlist)
while (b)
{
Move move = make_move(pop_lsb(&b), to);
- if (!pos.legal(move, pos.pinned_pieces()))
+ if (!pos.legal(move, pos.pinned_pieces(pos.side_to_move())))
others ^= from_sq(move);
}
Color them = ~pos.side_to_move();
ksq = pos.king_square(them);
- pinned = pos.pinned_pieces();
+ pinned = pos.pinned_pieces(pos.side_to_move());
dcCandidates = pos.discovered_check_candidates();
checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
/// pieces, according to the call parameters. Pinned pieces protect our king,
/// discovery check pieces attack the enemy king.
-Bitboard Position::hidden_checkers(Square ksq, Color c) const {
+Bitboard Position::hidden_checkers(Square ksq, Color c, Color toMove) const {
Bitboard b, pinners, result = 0;
b = between_bb(ksq, pop_lsb(&pinners)) & pieces();
if (!more_than_one(b))
- result |= b & pieces(sideToMove);
+ result |= b & pieces(toMove);
}
return result;
}
bool Position::legal(Move m, Bitboard pinned) const {
assert(is_ok(m));
- assert(pinned == pinned_pieces());
+ assert(pinned == pinned_pieces(pos.side_to_move()));
Color us = sideToMove;
Square from = from_sq(m);
// Checking
Bitboard checkers() const;
Bitboard discovered_check_candidates() const;
- Bitboard pinned_pieces() const;
+ Bitboard pinned_pieces(Color toMove) const;
// Attacks to/from a given square
Bitboard attackers_to(Square s) const;
// Helper functions
void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
- Bitboard hidden_checkers(Square ksq, Color c) const;
+ Bitboard hidden_checkers(Square ksq, Color c, Color toMove) const;
void put_piece(Square s, Color c, PieceType pt);
void remove_piece(Square s, Color c, PieceType pt);
void move_piece(Square from, Square to, Color c, PieceType pt);
}
inline Bitboard Position::discovered_check_candidates() const {
- return hidden_checkers(king_square(~sideToMove), sideToMove);
+ return hidden_checkers(king_square(~sideToMove), sideToMove, sideToMove);
}
-inline Bitboard Position::pinned_pieces() const {
- return hidden_checkers(king_square(sideToMove), ~sideToMove);
+inline Bitboard Position::pinned_pieces(Color toMove) const {
+ return hidden_checkers(king_square(toMove), ~toMove, toMove);
}
inline bool Position::pawn_passed(Color c, Square s) const {
} while ( tte
&& pos.pseudo_legal(m = tte->move()) // Local copy, TT could change
- && pos.legal(m, pos.pinned_pieces())
+ && pos.legal(m, pos.pinned_pieces(pos.side_to_move()))
&& ply < MAX_PLY
&& (!pos.is_draw() || ply < 2));