#include "bitcount.h"
#include "rkiss.h"
+CACHE_LINE_ALIGNMENT
+
Bitboard RMasks[64];
Bitboard RMagics[64];
Bitboard* RAttacks[64];
Bitboard* BAttacks[64];
int BShifts[64];
-Bitboard SetMaskBB[65];
-Bitboard ClearMaskBB[65];
-
+Bitboard SquareBB[64];
Bitboard FileBB[8];
Bitboard RankBB[8];
Bitboard AdjacentFilesBB[8];
Bitboard SquaresInFrontMask[2][64];
Bitboard PassedPawnMask[2][64];
Bitboard AttackSpanMask[2][64];
-
Bitboard PseudoAttacks[6][64];
uint8_t BitCount8Bit[256];
BitCount8Bit[b] = (uint8_t)popcount<Max15>(b);
for (Square s = SQ_A1; s <= SQ_H8; s++)
- {
- SetMaskBB[s] = 1ULL << s;
- ClearMaskBB[s] = ~SetMaskBB[s];
- }
-
- ClearMaskBB[SQ_NONE] = ~0ULL;
+ SquareBB[s] = 1ULL << s;
FileBB[FILE_A] = FileABB;
RankBB[RANK_1] = Rank1BB;
#include "types.h"
+extern Bitboard RMasks[64];
+extern Bitboard RMagics[64];
+extern Bitboard* RAttacks[64];
+extern int RShifts[64];
+
+extern Bitboard BMasks[64];
+extern Bitboard BMagics[64];
+extern Bitboard* BAttacks[64];
+extern int BShifts[64];
+
+extern Bitboard SquareBB[64];
extern Bitboard FileBB[8];
+extern Bitboard RankBB[8];
extern Bitboard AdjacentFilesBB[8];
extern Bitboard ThisAndAdjacentFilesBB[8];
-extern Bitboard RankBB[8];
extern Bitboard InFrontBB[2][8];
-
-extern Bitboard SetMaskBB[65];
-extern Bitboard ClearMaskBB[65];
-
extern Bitboard StepAttacksBB[16][64];
extern Bitboard BetweenBB[64][64];
-
extern Bitboard SquaresInFrontMask[2][64];
extern Bitboard PassedPawnMask[2][64];
extern Bitboard AttackSpanMask[2][64];
-
-extern uint64_t RMagics[64];
-extern int RShifts[64];
-extern Bitboard RMasks[64];
-extern Bitboard* RAttacks[64];
-
-extern uint64_t BMagics[64];
-extern int BShifts[64];
-extern Bitboard BMasks[64];
-extern Bitboard* BAttacks[64];
-
extern Bitboard PseudoAttacks[6][64];
-extern uint8_t BitCount8Bit[256];
-
/// Functions for testing whether a given bit is set in a bitboard, and for
/// setting and clearing bits.
inline Bitboard bit_is_set(Bitboard b, Square s) {
- return b & SetMaskBB[s];
+ return b & SquareBB[s];
}
inline void set_bit(Bitboard* b, Square s) {
- *b |= SetMaskBB[s];
+ *b |= SquareBB[s];
}
-inline void clear_bit(Bitboard* b, Square s) {
- *b &= ClearMaskBB[s];
+inline void xor_bit(Bitboard* b, Square s) {
+ *b ^= SquareBB[s];
}
/// then calling a sequence of clear_bit() + set_bit()
inline Bitboard make_move_bb(Square from, Square to) {
- return SetMaskBB[from] | SetMaskBB[to];
+ return SquareBB[from] | SquareBB[to];
}
inline void do_move_bb(Bitboard* b, Bitboard move_bb) {
inline bool squares_aligned(Square s1, Square s2, Square s3) {
return (BetweenBB[s1][s2] | BetweenBB[s1][s3] | BetweenBB[s2][s3])
- & ( SetMaskBB[s1] | SetMaskBB[s2] | SetMaskBB[s3]);
+ & ( SquareBB[s1] | SquareBB[s2] | SquareBB[s3]);
}
// Check if (without even considering any obstacles) we're too far away or doubled
if ( pliesToQueen[winnerSide] + 3 <= pliesToGo
|| (squares_in_front_of(loserSide, s) & pos.pieces(PAWN, loserSide)))
- clear_bit(&candidates, s);
+ xor_bit(&candidates, s);
}
// If any candidate is already a passed pawn it _may_ promote in time. We give up.
// Disambiguation if we have more then one piece with destination 'to'
// note that for pawns is not needed because starting file is explicit.
attackers = pos.attackers_to(to) & pos.pieces(pt, pos.side_to_move());
- clear_bit(&attackers, from);
+ xor_bit(&attackers, from);
ambiguousMove = ambiguousFile = ambiguousRank = false;
while (attackers)
if (pos.is_chess960())
{
Bitboard occ = pos.occupied_squares();
- clear_bit(&occ, rfrom);
+ xor_bit(&occ, rfrom);
if (pos.attackers_to(kto, occ) & enemies)
return mlist;
}
assert(piece_on(capsq) == make_piece(them, PAWN));
assert(piece_on(to) == NO_PIECE);
- clear_bit(&b, from);
- clear_bit(&b, capsq);
+ xor_bit(&b, from);
+ xor_bit(&b, capsq);
set_bit(&b, to);
return !(rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, them))
if (type_of(piece_on(from)) == KING)
{
Bitboard b = occupied_squares();
- clear_bit(&b, from);
+ xor_bit(&b, from);
if (attackers_to(to_sq(m), b) & pieces(~us))
return false;
}
// Promotion with check ?
if (is_promotion(m))
{
- clear_bit(&b, from);
+ xor_bit(&b, from);
return bit_is_set(attacks_from(Piece(promotion_piece_type(m)), to, b), ksq);
}
if (is_enpassant(m))
{
Square capsq = make_square(file_of(to), rank_of(from));
- clear_bit(&b, from);
- clear_bit(&b, capsq);
+ xor_bit(&b, from);
+ xor_bit(&b, capsq);
set_bit(&b, to);
return (rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, us))
||(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, us));
kto = relative_square(us, SQ_C1);
rto = relative_square(us, SQ_D1);
}
- clear_bit(&b, kfrom);
- clear_bit(&b, rfrom);
+ xor_bit(&b, kfrom);
+ xor_bit(&b, rfrom);
set_bit(&b, rto);
set_bit(&b, kto);
return bit_is_set(rook_attacks_bb(rto, b), ksq);
st->npMaterial[them] -= PieceValueMidgame[capture];
// Remove the captured piece
- clear_bit(&byColorBB[them], capsq);
- clear_bit(&byTypeBB[capture], capsq);
- clear_bit(&occupied, capsq);
+ xor_bit(&byColorBB[them], capsq);
+ xor_bit(&byTypeBB[capture], capsq);
+ xor_bit(&occupied, capsq);
// Update piece list, move the last piece at index[capsq] position and
// shrink the list.
assert(promotion >= KNIGHT && promotion <= QUEEN);
// Replace the pawn with the promoted piece
- clear_bit(&byTypeBB[PAWN], to);
+ xor_bit(&byTypeBB[PAWN], to);
set_bit(&byTypeBB[promotion], to);
board[to] = make_piece(us, promotion);
{
// Direct checks
if (bit_is_set(ci.checkSq[pt], to))
- st->checkersBB = SetMaskBB[to];
+ st->checkersBB = SquareBB[to];
// Discovery checks
if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from))
assert(promotion >= KNIGHT && promotion <= QUEEN);
// Replace the promoted piece with the pawn
- clear_bit(&byTypeBB[promotion], to);
+ xor_bit(&byTypeBB[promotion], to);
set_bit(&byTypeBB[PAWN], to);
board[to] = make_piece(us, PAWN);
assert(piece_on(rfrom) == make_piece(us, ROOK));
// Remove pieces from source squares
- clear_bit(&byColorBB[us], kfrom);
- clear_bit(&byTypeBB[KING], kfrom);
- clear_bit(&occupied, kfrom);
- clear_bit(&byColorBB[us], rfrom);
- clear_bit(&byTypeBB[ROOK], rfrom);
- clear_bit(&occupied, rfrom);
+ xor_bit(&byColorBB[us], kfrom);
+ xor_bit(&byTypeBB[KING], kfrom);
+ xor_bit(&occupied, kfrom);
+ xor_bit(&byColorBB[us], rfrom);
+ xor_bit(&byTypeBB[ROOK], rfrom);
+ xor_bit(&occupied, rfrom);
// Put pieces on destination squares
set_bit(&byColorBB[us], kto);
assert(type_of(piece_on(capQq)) == PAWN);
// Remove the captured pawn
- clear_bit(&occ, capQq);
+ xor_bit(&occ, capQq);
capturedType = PAWN;
}
// Find all attackers to the destination square, with the moving piece
// removed, but possibly an X-ray attacker added behind it.
- clear_bit(&occ, from);
+ xor_bit(&occ, from);
attackers = attackers_to(to, occ);
// If the opponent has no attackers we are finished
&& bit_is_set(squares_between(t1, ksq), f2))
{
Bitboard occ = pos.occupied_squares();
- clear_bit(&occ, f2);
+ xor_bit(&occ, f2);
if (bit_is_set(pos.attacks_from(p1, t1, occ), ksq))
return true;
}
extern const Value PieceValueMidgame[17]; // Indexed by Piece or PieceType
extern const Value PieceValueEndgame[17];
extern int SquareDistance[64][64];
+extern uint8_t BitCount8Bit[256];
inline Color operator~(Color c) {
return Color(c ^ 1);