1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Bitwise operator overloads between Bitboard and Square

Yes, we try to be fancy here ;-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-01-29 09:54:17 +01:00
parent 875a8079bc
commit a492a9dd07
9 changed files with 98 additions and 112 deletions

View file

@ -134,8 +134,8 @@ namespace {
return RESULT_INVALID; return RESULT_INVALID;
// Check if a king can be captured // Check if a king can be captured
if ( bit_is_set(wk_attacks(), blackKingSquare) if ( (wk_attacks() & blackKingSquare)
|| (bit_is_set(pawn_attacks(), blackKingSquare) && sideToMove == WHITE)) || ((pawn_attacks() & blackKingSquare) && sideToMove == WHITE))
return RESULT_INVALID; return RESULT_INVALID;
// The position is an immediate win if it is white to move and the // The position is an immediate win if it is white to move and the
@ -144,7 +144,7 @@ namespace {
&& sideToMove == WHITE && sideToMove == WHITE
&& whiteKingSquare != pawnSquare + DELTA_N && whiteKingSquare != pawnSquare + DELTA_N
&& ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1 && ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
|| bit_is_set(wk_attacks(), pawnSquare + DELTA_N))) || (wk_attacks() & (pawnSquare + DELTA_N))))
return RESULT_WIN; return RESULT_WIN;
// Check for known draw positions // Check for known draw positions
@ -156,7 +156,7 @@ namespace {
// Case 2: King can capture pawn // Case 2: King can capture pawn
if ( sideToMove == BLACK if ( sideToMove == BLACK
&& bit_is_set(bk_attacks(), pawnSquare) && !bit_is_set(wk_attacks(), pawnSquare)) && (bk_attacks() & pawnSquare) && !(wk_attacks() & pawnSquare))
return RESULT_DRAW; return RESULT_DRAW;
// Case 3: Black king in front of white pawn // Case 3: Black king in front of white pawn

View file

@ -77,7 +77,7 @@ void print_bitboard(Bitboard b) {
{ {
std::cout << "+---+---+---+---+---+---+---+---+" << '\n'; std::cout << "+---+---+---+---+---+---+---+---+" << '\n';
for (File f = FILE_A; f <= FILE_H; f++) for (File f = FILE_A; f <= FILE_H; f++)
std::cout << "| " << (bit_is_set(b, make_square(f, r)) ? "X " : " "); std::cout << "| " << ((b & make_square(f, r)) ? "X " : " ");
std::cout << "|\n"; std::cout << "|\n";
} }
@ -213,7 +213,7 @@ void bitboards_init() {
Square to = s + Square(c == WHITE ? steps[pt][k] : -steps[pt][k]); Square to = s + Square(c == WHITE ? steps[pt][k] : -steps[pt][k]);
if (square_is_ok(to) && square_distance(s, to) < 3) if (square_is_ok(to) && square_distance(s, to) < 3)
set_bit(&StepAttacksBB[make_piece(c, pt)][s], to); StepAttacksBB[make_piece(c, pt)][s] |= to;
} }
Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W }; Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
@ -231,12 +231,12 @@ void bitboards_init() {
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++) for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++) for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
if (bit_is_set(PseudoAttacks[QUEEN][s1], s2)) if (PseudoAttacks[QUEEN][s1] & s2)
{ {
Square delta = (s2 - s1) / square_distance(s1, s2); Square delta = (s2 - s1) / square_distance(s1, s2);
for (Square s = s1 + delta; s != s2; s += delta) for (Square s = s1 + delta; s != s2; s += delta)
set_bit(&BetweenBB[s1][s2], s); BetweenBB[s1][s2] |= s;
} }
} }
@ -252,9 +252,9 @@ namespace {
square_is_ok(s) && square_distance(s, s - deltas[i]) == 1; square_is_ok(s) && square_distance(s, s - deltas[i]) == 1;
s += deltas[i]) s += deltas[i])
{ {
set_bit(&attack, s); attack |= s;
if (bit_is_set(occupied, s)) if (occupied & s)
break; break;
} }

View file

@ -47,31 +47,19 @@ extern Bitboard AttackSpanMask[2][64];
extern Bitboard PseudoAttacks[6][64]; extern Bitboard PseudoAttacks[6][64];
/// Functions for testing whether a given bit is set in a bitboard, and for /// Overloads of bitwise operators between a Bitboard and a Square for testing
/// setting and clearing bits. /// whether a given bit is set in a bitboard, and for setting and clearing bits.
inline Bitboard bit_is_set(Bitboard b, Square s) { inline Bitboard operator&(Bitboard b, Square s) {
return b & SquareBB[s]; return b & SquareBB[s];
} }
inline void set_bit(Bitboard* b, Square s) { inline Bitboard& operator|=(Bitboard& b, Square s) {
*b |= SquareBB[s]; return b |= SquareBB[s], b;
} }
inline void xor_bit(Bitboard* b, Square s) { inline Bitboard& operator^=(Bitboard& b, Square s) {
*b ^= SquareBB[s]; return b ^= SquareBB[s], b;
}
/// Functions used to update a bitboard after a move. This is faster
/// then calling a sequence of clear_bit() + set_bit()
inline Bitboard make_move_bb(Square from, Square to) {
return SquareBB[from] | SquareBB[to];
}
inline void do_move_bb(Bitboard* b, Bitboard move_bb) {
*b ^= move_bb;
} }
@ -217,8 +205,8 @@ inline bool squares_aligned(Square s1, Square s2, Square s3) {
/// the same color of the given square. /// the same color of the given square.
inline Bitboard same_color_squares(Square s) { inline Bitboard same_color_squares(Square s) {
return bit_is_set(0xAA55AA55AA55AA55ULL, s) ? 0xAA55AA55AA55AA55ULL return Bitboard(0xAA55AA55AA55AA55ULL) & s ? 0xAA55AA55AA55AA55ULL
: ~0xAA55AA55AA55AA55ULL; : ~0xAA55AA55AA55AA55ULL;
} }

View file

@ -453,7 +453,7 @@ namespace {
// Increase bonus if supported by pawn, especially if the opponent has // Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece. // no minor piece which can exchange the outpost piece.
if (bonus && bit_is_set(ei.attackedBy[Us][PAWN], s)) if (bonus && (ei.attackedBy[Us][PAWN] & s))
{ {
if ( !pos.pieces(KNIGHT, Them) if ( !pos.pieces(KNIGHT, Them)
&& !(same_color_squares(s) & pos.pieces(BISHOP, Them))) && !(same_color_squares(s) & pos.pieces(BISHOP, Them)))
@ -514,7 +514,7 @@ namespace {
// Decrease score if we are attacked by an enemy pawn. Remaining part // 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. // of threat evaluation must be done later when we have full attack info.
if (bit_is_set(ei.attackedBy[Them][PAWN], s)) if (ei.attackedBy[Them][PAWN] & s)
score -= ThreatenedByPawnPenalty[Piece]; score -= ThreatenedByPawnPenalty[Piece];
// Bishop and knight outposts squares // Bishop and knight outposts squares
@ -944,7 +944,7 @@ namespace {
// Check if (without even considering any obstacles) we're too far away or doubled // Check if (without even considering any obstacles) we're too far away or doubled
if ( pliesToQueen[winnerSide] + 3 <= pliesToGo if ( pliesToQueen[winnerSide] + 3 <= pliesToGo
|| (squares_in_front_of(loserSide, s) & pos.pieces(PAWN, loserSide))) || (squares_in_front_of(loserSide, s) & pos.pieces(PAWN, loserSide)))
xor_bit(&candidates, s); candidates ^= s;
} }
// If any candidate is already a passed pawn it _may_ promote in time. We give up. // If any candidate is already a passed pawn it _may_ promote in time. We give up.

View file

@ -98,7 +98,7 @@ const string move_to_san(Position& pos, Move m) {
// Disambiguation if we have more then one piece with destination 'to' // Disambiguation if we have more then one piece with destination 'to'
// note that for pawns is not needed because starting file is explicit. // note that for pawns is not needed because starting file is explicit.
attackers = pos.attackers_to(to) & pos.pieces(pt, pos.side_to_move()); attackers = pos.attackers_to(to) & pos.pieces(pt, pos.side_to_move());
xor_bit(&attackers, from); attackers ^= from;
ambiguousMove = ambiguousFile = ambiguousRank = false; ambiguousMove = ambiguousFile = ambiguousRank = false;
while (attackers) while (attackers)

View file

@ -74,7 +74,7 @@ namespace {
if (pos.is_chess960()) if (pos.is_chess960())
{ {
Bitboard occ = pos.occupied_squares(); Bitboard occ = pos.occupied_squares();
xor_bit(&occ, rfrom); occ ^= rfrom;
if (pos.attackers_to(kto, occ) & enemies) if (pos.attackers_to(kto, occ) & enemies)
return mlist; return mlist;
} }
@ -121,7 +121,7 @@ namespace {
// Knight-promotion is the only one that can give a direct check not // Knight-promotion is the only one that can give a direct check not
// already included in the queen-promotion. // already included in the queen-promotion.
if (Type == MV_QUIET_CHECK && bit_is_set(StepAttacksBB[W_KNIGHT][to], ksq)) if (Type == MV_QUIET_CHECK && (StepAttacksBB[W_KNIGHT][to] & ksq))
(*mlist++).move = make_promotion(to - Delta, to, KNIGHT); (*mlist++).move = make_promotion(to - Delta, to, KNIGHT);
else else
(void)ksq; // Silence a warning under MSVC (void)ksq; // Silence a warning under MSVC
@ -219,7 +219,7 @@ namespace {
// An en passant capture can be an evasion only if the checking piece // An en passant capture can be an evasion only if the checking piece
// is the double pushed pawn and so is in the target. Otherwise this // is the double pushed pawn and so is in the target. Otherwise this
// is a discovery check and we are forced to do otherwise. // is a discovery check and we are forced to do otherwise.
if (Type == MV_EVASION && !bit_is_set(target, pos.ep_square() - UP)) if (Type == MV_EVASION && !(target & (pos.ep_square() - UP)))
return mlist; return mlist;
b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them); b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them);
@ -255,7 +255,7 @@ namespace {
&& !(PseudoAttacks[Pt][from] & target)) && !(PseudoAttacks[Pt][from] & target))
continue; continue;
if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from)) if (ci.dcCandidates && (ci.dcCandidates & from))
continue; continue;
b = pos.attacks_from<Pt>(from) & target; b = pos.attacks_from<Pt>(from) & target;
@ -430,7 +430,7 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
// If queen and king are far or not on a diagonal line we can safely // If queen and king are far or not on a diagonal line we can safely
// remove all the squares attacked in the other direction becuase are // remove all the squares attacked in the other direction becuase are
// not reachable by the king anyway. // not reachable by the king anyway.
if (squares_between(ksq, checksq) || !bit_is_set(PseudoAttacks[BISHOP][checksq], ksq)) if (squares_between(ksq, checksq) || !(PseudoAttacks[BISHOP][checksq] & ksq))
sliderAttacks |= PseudoAttacks[QUEEN][checksq]; sliderAttacks |= PseudoAttacks[QUEEN][checksq];
// Otherwise we need to use real rook attacks to check if king is safe // Otherwise we need to use real rook attacks to check if king is safe

View file

@ -188,7 +188,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
// full attack info to evaluate passed pawns. Only the frontmost passed // full attack info to evaluate passed pawns. Only the frontmost passed
// pawn on each file is considered a true passed pawn. // pawn on each file is considered a true passed pawn.
if (passed && !doubled) if (passed && !doubled)
set_bit(&(pi->passedPawns[Us]), s); pi->passedPawns[Us] |= s;
// Score this pawn // Score this pawn
if (isolated) if (isolated)

View file

@ -426,10 +426,11 @@ bool Position::move_attacks_square(Move m, Square s) const {
// Update occupancy as if the piece is moving // Update occupancy as if the piece is moving
occ = occupied_squares(); occ = occupied_squares();
do_move_bb(&occ, make_move_bb(from, to)); occ ^= from;
occ ^= to;
// The piece moved in 'to' attacks the square 's' ? // The piece moved in 'to' attacks the square 's' ?
if (bit_is_set(attacks_from(piece, to, occ), s)) if (attacks_from(piece, to, occ) & s)
return true; return true;
// Scan for possible X-ray attackers behind the moved piece // Scan for possible X-ray attackers behind the moved piece
@ -470,9 +471,9 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
assert(piece_on(capsq) == make_piece(them, PAWN)); assert(piece_on(capsq) == make_piece(them, PAWN));
assert(piece_on(to) == NO_PIECE); assert(piece_on(to) == NO_PIECE);
xor_bit(&b, from); b ^= from;
xor_bit(&b, capsq); b ^= capsq;
set_bit(&b, to); b |= to;
return !(rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, them)) return !(rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, them))
&& !(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, them)); && !(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, them));
@ -487,7 +488,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
// A non-king move is legal if and only if it is not pinned or it // A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king. // is moving along the ray towards or away from the king.
return !pinned return !pinned
|| !bit_is_set(pinned, from) || !(pinned & from)
|| squares_aligned(from, to_sq(m), king_square(us)); || squares_aligned(from, to_sq(m), king_square(us));
} }
@ -597,7 +598,7 @@ bool Position::is_pseudo_legal(const Move m) const {
return false; return false;
} }
} }
else if (!bit_is_set(attacks_from(pc, from), to)) else if (!(attacks_from(pc, from) & to))
return false; return false;
// Evasions generator already takes care to avoid some kind of illegal moves // Evasions generator already takes care to avoid some kind of illegal moves
@ -610,7 +611,7 @@ bool Position::is_pseudo_legal(const Move m) const {
if (type_of(piece_on(from)) == KING) if (type_of(piece_on(from)) == KING)
{ {
Bitboard b = occupied_squares(); Bitboard b = occupied_squares();
xor_bit(&b, from); b ^= from;
if (attackers_to(to_sq(m), b) & pieces(~us)) if (attackers_to(to_sq(m), b) & pieces(~us))
return false; return false;
} }
@ -624,7 +625,7 @@ bool Position::is_pseudo_legal(const Move m) const {
// Our move must be a blocking evasion or a capture of the checking piece // Our move must be a blocking evasion or a capture of the checking piece
target = squares_between(checksq, king_square(us)) | checkers(); target = squares_between(checksq, king_square(us)) | checkers();
if (!bit_is_set(target, to_sq(m))) if (!(target & to_sq(m)))
return false; return false;
} }
} }
@ -646,11 +647,11 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
PieceType pt = type_of(piece_on(from)); PieceType pt = type_of(piece_on(from));
// Direct check ? // Direct check ?
if (bit_is_set(ci.checkSq[pt], to)) if (ci.checkSq[pt] & to)
return true; return true;
// Discovery check ? // Discovery check ?
if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from)) if (ci.dcCandidates && (ci.dcCandidates & from))
{ {
// For pawn and king moves we need to verify also direction // For pawn and king moves we need to verify also direction
if ( (pt != PAWN && pt != KING) if ( (pt != PAWN && pt != KING)
@ -669,8 +670,8 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
// Promotion with check ? // Promotion with check ?
if (is_promotion(m)) if (is_promotion(m))
{ {
xor_bit(&b, from); b ^= from;
return bit_is_set(attacks_from(Piece(promotion_piece_type(m)), to, b), ksq); return attacks_from(Piece(promotion_piece_type(m)), to, b) & ksq;
} }
// En passant capture with check ? We have already handled the case // En passant capture with check ? We have already handled the case
@ -680,9 +681,9 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
if (is_enpassant(m)) if (is_enpassant(m))
{ {
Square capsq = make_square(file_of(to), rank_of(from)); Square capsq = make_square(file_of(to), rank_of(from));
xor_bit(&b, from); b ^= from;
xor_bit(&b, capsq); b ^= capsq;
set_bit(&b, to); b |= to;
return (rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, us)) return (rook_attacks_bb(ksq, b) & pieces(ROOK, QUEEN, us))
||(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, us)); ||(bishop_attacks_bb(ksq, b) & pieces(BISHOP, QUEEN, us));
} }
@ -702,11 +703,11 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
kto = relative_square(us, SQ_C1); kto = relative_square(us, SQ_C1);
rto = relative_square(us, SQ_D1); rto = relative_square(us, SQ_D1);
} }
xor_bit(&b, kfrom); b ^= kfrom;
xor_bit(&b, rfrom); b ^= rfrom;
set_bit(&b, rto); b |= rto;
set_bit(&b, kto); b |= kto;
return bit_is_set(rook_attacks_bb(rto, b), ksq); return rook_attacks_bb(rto, b) & ksq;
} }
return false; return false;
@ -801,9 +802,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->npMaterial[them] -= PieceValueMidgame[capture]; st->npMaterial[them] -= PieceValueMidgame[capture];
// Remove the captured piece // Remove the captured piece
xor_bit(&byColorBB[them], capsq); byColorBB[them] ^= capsq;
xor_bit(&byTypeBB[capture], capsq); byTypeBB[capture] ^= capsq;
xor_bit(&occupied, capsq); occupied ^= capsq;
// Update piece list, move the last piece at index[capsq] position and // Update piece list, move the last piece at index[capsq] position and
// shrink the list. // shrink the list.
@ -851,10 +852,10 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
prefetch((char*)TT.first_entry(k)); prefetch((char*)TT.first_entry(k));
// Move the piece // Move the piece
Bitboard move_bb = make_move_bb(from, to); Bitboard from_to_bb = SquareBB[from] | SquareBB[to];
do_move_bb(&byColorBB[us], move_bb); byColorBB[us] ^= from_to_bb;
do_move_bb(&byTypeBB[pt], move_bb); byTypeBB[pt] ^= from_to_bb;
do_move_bb(&occupied, move_bb); occupied ^= from_to_bb;
board[to] = board[from]; board[to] = board[from];
board[from] = NO_PIECE; board[from] = NO_PIECE;
@ -883,8 +884,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
assert(promotion >= KNIGHT && promotion <= QUEEN); assert(promotion >= KNIGHT && promotion <= QUEEN);
// Replace the pawn with the promoted piece // Replace the pawn with the promoted piece
xor_bit(&byTypeBB[PAWN], to); byTypeBB[PAWN] ^= to;
set_bit(&byTypeBB[promotion], to); byTypeBB[promotion] |= to;
board[to] = make_piece(us, promotion); board[to] = make_piece(us, promotion);
// Update piece lists, move the last pawn at index[to] position // Update piece lists, move the last pawn at index[to] position
@ -940,11 +941,11 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
else else
{ {
// Direct checks // Direct checks
if (bit_is_set(ci.checkSq[pt], to)) if (ci.checkSq[pt] & to)
st->checkersBB = SquareBB[to]; st->checkersBB |= to;
// Discovery checks // Discovery checks
if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from)) if (ci.dcCandidates && (ci.dcCandidates & from))
{ {
if (pt != ROOK) if (pt != ROOK)
st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(ROOK, QUEEN, us); st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(ROOK, QUEEN, us);
@ -999,8 +1000,8 @@ void Position::undo_move(Move m) {
assert(promotion >= KNIGHT && promotion <= QUEEN); assert(promotion >= KNIGHT && promotion <= QUEEN);
// Replace the promoted piece with the pawn // Replace the promoted piece with the pawn
xor_bit(&byTypeBB[promotion], to); byTypeBB[promotion] ^= to;
set_bit(&byTypeBB[PAWN], to); byTypeBB[PAWN] |= to;
board[to] = make_piece(us, PAWN); board[to] = make_piece(us, PAWN);
// Update piece lists, move the last promoted piece at index[to] position // Update piece lists, move the last promoted piece at index[to] position
@ -1016,10 +1017,10 @@ void Position::undo_move(Move m) {
} }
// Put the piece back at the source square // Put the piece back at the source square
Bitboard move_bb = make_move_bb(to, from); Bitboard from_to_bb = SquareBB[from] | SquareBB[to];
do_move_bb(&byColorBB[us], move_bb); byColorBB[us] ^= from_to_bb;
do_move_bb(&byTypeBB[pt], move_bb); byTypeBB[pt] ^= from_to_bb;
do_move_bb(&occupied, move_bb); occupied ^= from_to_bb;
board[from] = board[to]; board[from] = board[to];
board[to] = NO_PIECE; board[to] = NO_PIECE;
@ -1044,9 +1045,9 @@ void Position::undo_move(Move m) {
} }
// Restore the captured piece // Restore the captured piece
set_bit(&byColorBB[them], capsq); byColorBB[them] |= capsq;
set_bit(&byTypeBB[capture], capsq); byTypeBB[capture] |= capsq;
set_bit(&occupied, capsq); occupied |= capsq;
board[capsq] = make_piece(them, capture); board[capsq] = make_piece(them, capture);
@ -1100,20 +1101,20 @@ void Position::do_castle_move(Move m) {
assert(piece_on(rfrom) == make_piece(us, ROOK)); assert(piece_on(rfrom) == make_piece(us, ROOK));
// Remove pieces from source squares // Remove pieces from source squares
xor_bit(&byColorBB[us], kfrom); byColorBB[us] ^= kfrom;
xor_bit(&byTypeBB[KING], kfrom); byTypeBB[KING] ^= kfrom;
xor_bit(&occupied, kfrom); occupied ^= kfrom;
xor_bit(&byColorBB[us], rfrom); byColorBB[us] ^= rfrom;
xor_bit(&byTypeBB[ROOK], rfrom); byTypeBB[ROOK] ^= rfrom;
xor_bit(&occupied, rfrom); occupied ^= rfrom;
// Put pieces on destination squares // Put pieces on destination squares
set_bit(&byColorBB[us], kto); byColorBB[us] |= kto;
set_bit(&byTypeBB[KING], kto); byTypeBB[KING] |= kto;
set_bit(&occupied, kto); occupied |= kto;
set_bit(&byColorBB[us], rto); byColorBB[us] |= rto;
set_bit(&byTypeBB[ROOK], rto); byTypeBB[ROOK] |= rto;
set_bit(&occupied, rto); occupied |= rto;
// Update board // Update board
Piece king = make_piece(us, KING); Piece king = make_piece(us, KING);
@ -1268,13 +1269,13 @@ int Position::see(Move m) const {
assert(type_of(piece_on(capQq)) == PAWN); assert(type_of(piece_on(capQq)) == PAWN);
// Remove the captured pawn // Remove the captured pawn
xor_bit(&occ, capQq); occ ^= capQq;
capturedType = PAWN; capturedType = PAWN;
} }
// Find all attackers to the destination square, with the moving piece // Find all attackers to the destination square, with the moving piece
// removed, but possibly an X-ray attacker added behind it. // removed, but possibly an X-ray attacker added behind it.
xor_bit(&occ, from); occ ^= from;
attackers = attackers_to(to, occ); attackers = attackers_to(to, occ);
// If the opponent has no attackers we are finished // If the opponent has no attackers we are finished
@ -1378,9 +1379,9 @@ void Position::put_piece(Piece p, Square s) {
index[s] = pieceCount[c][pt]++; index[s] = pieceCount[c][pt]++;
pieceList[c][pt][index[s]] = s; pieceList[c][pt][index[s]] = s;
set_bit(&byTypeBB[pt], s); byTypeBB[pt] |= s;
set_bit(&byColorBB[c], s); byColorBB[c] |= s;
set_bit(&occupied, s); occupied |= s;
} }

View file

@ -1363,8 +1363,7 @@ split_point_start: // At split points actual search starts from here
return true; return true;
// Rule 2. Queen contact check is very dangerous // Rule 2. Queen contact check is very dangerous
if ( type_of(pc) == QUEEN if (type_of(pc) == QUEEN && (kingAtt & to))
&& bit_is_set(kingAtt, to))
return true; return true;
// Rule 3. Creating new double threats with checks // Rule 3. Creating new double threats with checks
@ -1419,23 +1418,21 @@ split_point_start: // At split points actual search starts from here
// Case 3: Moving through the vacated square // Case 3: Moving through the vacated square
p2 = pos.piece_on(f2); p2 = pos.piece_on(f2);
if ( piece_is_slider(p2) if (piece_is_slider(p2) && (squares_between(f2, t2) & f1))
&& bit_is_set(squares_between(f2, t2), f1))
return true; return true;
// Case 4: The destination square for m2 is defended by the moving piece in m1 // Case 4: The destination square for m2 is defended by the moving piece in m1
p1 = pos.piece_on(t1); p1 = pos.piece_on(t1);
if (bit_is_set(pos.attacks_from(p1, t1), t2)) if (pos.attacks_from(p1, t1) & t2)
return true; return true;
// Case 5: Discovered check, checking piece is the piece moved in m1 // Case 5: Discovered check, checking piece is the piece moved in m1
ksq = pos.king_square(pos.side_to_move()); ksq = pos.king_square(pos.side_to_move());
if ( piece_is_slider(p1) if (piece_is_slider(p1) && (squares_between(t1, ksq) & f2))
&& bit_is_set(squares_between(t1, ksq), f2))
{ {
Bitboard occ = pos.occupied_squares(); Bitboard occ = pos.occupied_squares();
xor_bit(&occ, f2); occ ^= f2;
if (bit_is_set(pos.attacks_from(p1, t1, occ), ksq)) if (pos.attacks_from(p1, t1, occ) & ksq)
return true; return true;
} }
return false; return false;
@ -1505,9 +1502,9 @@ split_point_start: // At split points actual search starts from here
// Case 3: If the moving piece in the threatened move is a slider, don't // Case 3: If the moving piece in the threatened move is a slider, don't
// prune safe moves which block its ray. // prune safe moves which block its ray.
if ( piece_is_slider(pos.piece_on(tfrom)) if ( piece_is_slider(pos.piece_on(tfrom))
&& bit_is_set(squares_between(tfrom, tto), mto) && (squares_between(tfrom, tto) & mto)
&& pos.see_sign(m) >= 0) && pos.see_sign(m) >= 0)
return true; return true;
return false; return false;