mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Introduce single_bit() helper
Self-documenting code instead of a tricky bitwise tweak, not known by everybody. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
cf0561d31a
commit
19540c9ee8
4 changed files with 11 additions and 4 deletions
|
@ -207,6 +207,14 @@ inline Bitboard same_color_squares(Square s) {
|
|||
}
|
||||
|
||||
|
||||
/// 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.
|
||||
|
|
|
@ -517,7 +517,7 @@ namespace {
|
|||
|
||||
assert(b);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -379,8 +379,7 @@ Bitboard Position::hidden_checkers() const {
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -1351,7 +1351,7 @@ split_point_start: // At split points actual search starts from here
|
|||
// 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
|
||||
|
|
Loading…
Add table
Reference in a new issue