uint64_t book_key(const Position& pos) {
uint64_t key = 0;
- Bitboard b = pos.occupied_squares();
+ Bitboard b = pos.pieces();
while (b)
{
if (Piece == KNIGHT || Piece == QUEEN)
b = pos.attacks_from<Piece>(s);
else if (Piece == BISHOP)
- b = attacks_bb<BISHOP>(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
+ b = attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN, Us));
else if (Piece == ROOK)
- b = attacks_bb<ROOK>(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
+ b = attacks_bb<ROOK>(s, pos.pieces() ^ pos.pieces(ROOK, QUEEN, Us));
else
assert(false);
if ( (Piece == BISHOP || Piece == ROOK || Piece == QUEEN)
&& (PseudoAttacks[Piece][pos.king_square(Them)] & s))
{
- b = BetweenBB[s][pos.king_square(Them)] & pos.occupied_squares();
+ b = BetweenBB[s][pos.king_square(Them)] & pos.pieces();
assert(b);
// Opponent king cannot block because path is defended and position
// is not in check. So only friendly pieces can be blockers.
assert(!pos.in_check());
- assert((queeningPath & pos.occupied_squares()) == (queeningPath & pos.pieces(c)));
+ assert((queeningPath & pos.pieces()) == (queeningPath & pos.pieces(c)));
// Add moves needed to free the path from friendly pieces and retest condition
movesToGo += popcount<Max15>(queeningPath & pos.pieces(c));
// when moving the castling rook we do not discover some hidden checker.
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
if ( pos.is_chess960()
- && (pos.attackers_to(kto, pos.occupied_squares() ^ rfrom) & enemies))
+ && (pos.attackers_to(kto, pos.pieces() ^ rfrom) & enemies))
return mlist;
(*mlist++).move = make_castle(kfrom, rfrom);
// Single and double pawn pushes, no promotions
if (Type != MV_CAPTURE)
{
- emptySquares = (Type == MV_QUIET ? target : ~pos.occupied_squares());
+ emptySquares = (Type == MV_QUIET ? target : ~pos.pieces());
b1 = move_pawns<UP>(pawnsNotOn7) & emptySquares;
b2 = move_pawns<UP>(b1 & TRank3BB) & emptySquares;
if (pawnsOn7 && (Type != MV_EVASION || (target & TRank8BB)))
{
if (Type == MV_CAPTURE)
- emptySquares = ~pos.occupied_squares();
+ emptySquares = ~pos.pieces();
if (Type == MV_EVASION)
emptySquares &= target;
if (*pl != SQ_NONE)
{
- target = ci.checkSq[Pt] & ~pos.occupied_squares(); // Non capture checks only
+ target = ci.checkSq[Pt] & ~pos.pieces(); // Non capture checks only
do {
from = *pl;
target = pos.pieces(~us);
else if (Type == MV_QUIET)
- target = ~pos.occupied_squares();
+ target = ~pos.pieces();
else if (Type == MV_NON_EVASION)
- target = pos.pieces(~us) | ~pos.occupied_squares();
+ target = ~pos.pieces(us);
mlist = (us == WHITE ? generate_pawn_moves<WHITE, Type>(pos, mlist, target)
: generate_pawn_moves<BLACK, Type>(pos, mlist, target));
if (pt == PAWN)
continue; // Will be generated togheter with direct checks
- Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.occupied_squares();
+ Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
if (pt == KING)
b &= ~PseudoAttacks[QUEEN][ci.ksq];
while (pinners)
{
- b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
+ b = squares_between(ksq, pop_1st_bit(&pinners)) & pieces();
if (b && single_bit(b) && (b & pieces(sideToMove)))
result |= b;
assert(!square_is_empty(from));
// Update occupancy as if the piece is moving
- occ = occupied_squares() ^ from ^ to;
+ occ = pieces() ^ from ^ to;
// The piece moved in 'to' attacks the square 's' ?
if (attacks_from(piece, to, occ) & s)
Square to = to_sq(m);
Square capsq = to + pawn_push(them);
Square ksq = king_square(us);
- Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
+ Bitboard b = (pieces() ^ from ^ capsq) | to;
assert(to == ep_square());
assert(piece_moved(m) == make_piece(us, PAWN));
}
// In case of king moves under check we have to remove king so to catch
// as invalid moves like b1a1 when opposite queen is on c1.
- else if (attackers_to(to, occupied_squares() ^ from) & pieces(~us))
+ else if (attackers_to(to, pieces() ^ from) & pieces(~us))
return false;
}
// Promotion with check ?
if (is_promotion(m))
- return attacks_from(Piece(promotion_type(m)), to, occupied_squares() ^ from) & ksq;
+ return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
// En passant capture with check ? We have already handled the case
// of direct checks and ordinary discovered check, the only case we
if (is_enpassant(m))
{
Square capsq = make_square(file_of(to), rank_of(from));
- Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
+ Bitboard b = (pieces() ^ from ^ capsq) | to;
return (attacks_bb< ROOK>(ksq, b) & pieces( ROOK, QUEEN, us))
| (attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, us));
Square rfrom = to; // 'King captures the rook' notation
Square kto = relative_square(us, rfrom > kfrom ? SQ_G1 : SQ_C1);
Square rto = relative_square(us, rfrom > kfrom ? SQ_F1 : SQ_D1);
- Bitboard b = (occupied_squares() ^ kfrom ^ rfrom) | rto | kto;
+ Bitboard b = (pieces() ^ kfrom ^ rfrom) | rto | kto;
return attacks_bb<ROOK>(rto, b) & ksq;
}
from = from_sq(m);
to = to_sq(m);
capturedType = type_of(piece_on(to));
- occ = occupied_squares();
+ occ = pieces();
// Handle en passant moves
if (is_enpassant(m))
// The union of the white and black pieces must be equal to all
// occupied squares
- if ((pieces(WHITE) | pieces(BLACK)) != occupied_squares())
+ if ((pieces(WHITE) | pieces(BLACK)) != pieces())
return false;
// Separate piece type bitboards must have empty intersections
Color side_to_move() const;
// Bitboard representation of the position
- Bitboard occupied_squares() const;
+ Bitboard pieces() const;
Bitboard pieces(Color c) const;
Bitboard pieces(PieceType pt) const;
Bitboard pieces(PieceType pt, Color c) const;
return sideToMove;
}
-inline Bitboard Position::occupied_squares() const {
+inline Bitboard Position::pieces() const {
return occupied;
}
template<PieceType Pt>
inline Bitboard Position::attacks_from(Square s) const {
- return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, occupied_squares())
+ return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
: StepAttacksBB[Pt][s];
}
kingAtt = pos.attacks_from<KING>(ksq);
pc = pos.piece_moved(move);
- occ = pos.occupied_squares() & ~(1ULL << from) & ~(1ULL << ksq);
+ occ = pos.pieces() ^ from ^ ksq;
oldAtt = pos.attacks_from(pc, from, occ);
newAtt = pos.attacks_from(pc, to, occ);
ksq = pos.king_square(pos.side_to_move());
if ( piece_is_slider(p1)
&& (squares_between(t1, ksq) & f2)
- && (pos.attacks_from(p1, t1, pos.occupied_squares() ^ f2) & ksq))
+ && (pos.attacks_from(p1, t1, pos.pieces() ^ f2) & ksq))
return true;
return false;