summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
cf0561d)
Self-documenting code instead of a tricky
bitwise tweak, not known by everybody.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
+/// single_bit() returns true if in the 'b' bitboard is set a single bit (or if
+/// b == 0).
+
+inline bool single_bit(Bitboard b) {
+ return !(b & (b - 1));
+}
+
+
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard.
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard.
- if (!(b & (b - 1)) && (b & pos.pieces(Them)))
+ if (single_bit(b) && (b & pos.pieces(Them)))
score += ThreatBonus[Piece][type_of(pos.piece_on(first_1(b)))] / 2;
}
score += ThreatBonus[Piece][type_of(pos.piece_on(first_1(b)))] / 2;
}
{
b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
{
b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
- // Only one bit set and is an our piece?
- if (b && !(b & (b - 1)) && (b & pieces(sideToMove)))
+ if (b && single_bit(b) && (b & pieces(sideToMove)))
result |= b;
}
return result;
result |= b;
}
return result;
// Rule 1. Checks which give opponent's king at most one escape square are dangerous
b = kingAtt & ~pos.pieces(them) & ~newAtt & ~(1ULL << to);
// Rule 1. Checks which give opponent's king at most one escape square are dangerous
b = kingAtt & ~pos.pieces(them) & ~newAtt & ~(1ULL << to);
- if (!(b && (b & (b - 1))))
+ if (single_bit(b)) // Catches also !b
return true;
// Rule 2. Queen contact check is very dangerous
return true;
// Rule 2. Queen contact check is very dangerous