mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 01:29:36 +00:00
Add lsb() overload
Helper to find least significant bit relative to the given color. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
e6482b7d97
commit
aecdbfc4a0
3 changed files with 10 additions and 17 deletions
|
@ -319,4 +319,9 @@ extern Square pop_lsb(Bitboard* b);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// lsb() overload finds least significant bit relative to the given color
|
||||||
|
inline Square lsb(Color c, Bitboard b) {
|
||||||
|
return c == WHITE ? lsb(b) : msb(b);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // #ifndef BITBOARD_H_INCLUDED
|
#endif // #ifndef BITBOARD_H_INCLUDED
|
||||||
|
|
|
@ -443,18 +443,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
||||||
// The bishop has the wrong color, and the defending king is on the
|
// The bishop has the wrong color, and the defending king is on the
|
||||||
// file of the pawn(s) or the adjacent file. Find the rank of the
|
// file of the pawn(s) or the adjacent file. Find the rank of the
|
||||||
// frontmost pawn.
|
// frontmost pawn.
|
||||||
Rank rank;
|
Rank rank = relative_rank(strongerSide, lsb(weakerSide, pawns));
|
||||||
if (strongerSide == WHITE)
|
|
||||||
{
|
|
||||||
for (rank = RANK_7; !(rank_bb(rank) & pawns); rank--) {}
|
|
||||||
assert(rank >= RANK_2 && rank <= RANK_7);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (rank = RANK_2; !(rank_bb(rank) & pawns); rank++) {}
|
|
||||||
rank = Rank(rank ^ 7); // HACK to get the relative rank
|
|
||||||
assert(rank >= RANK_2 && rank <= RANK_7);
|
|
||||||
}
|
|
||||||
// If the defending king has distance 1 to the promotion square or
|
// If the defending king has distance 1 to the promotion square or
|
||||||
// is placed somewhere in front of the pawn, it's a draw.
|
// is placed somewhere in front of the pawn, it's a draw.
|
||||||
if ( square_distance(kingSq, queeningSq) <= 1
|
if ( square_distance(kingSq, queeningSq) <= 1
|
||||||
|
@ -469,9 +458,8 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
|
||||||
&& pos.non_pawn_material(weakerSide) == 0
|
&& pos.non_pawn_material(weakerSide) == 0
|
||||||
&& pos.count<PAWN>(weakerSide) >= 1)
|
&& pos.count<PAWN>(weakerSide) >= 1)
|
||||||
{
|
{
|
||||||
// Get weaker pawn closest to opponent's queening square
|
// Get weakerSide pawn that is closest to home rank
|
||||||
Bitboard wkPawns = pos.pieces(weakerSide, PAWN);
|
Square weakerPawnSq = lsb(weakerSide, pos.pieces(weakerSide, PAWN));
|
||||||
Square weakerPawnSq = strongerSide == WHITE ? msb(wkPawns) : lsb(wkPawns);
|
|
||||||
|
|
||||||
Square strongerKingSq = pos.king_square(strongerSide);
|
Square strongerKingSq = pos.king_square(strongerSide);
|
||||||
Square weakerKingSq = pos.king_square(weakerSide);
|
Square weakerKingSq = pos.king_square(weakerSide);
|
||||||
|
|
|
@ -229,11 +229,11 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||||
for (int f = kf - 1; f <= kf + 1; f++)
|
for (int f = kf - 1; f <= kf + 1; f++)
|
||||||
{
|
{
|
||||||
b = ourPawns & FileBB[f];
|
b = ourPawns & FileBB[f];
|
||||||
rkUs = b ? relative_rank(Us, Us == WHITE ? lsb(b) : msb(b)) : RANK_1;
|
rkUs = b ? relative_rank(Us, lsb(Us, b)) : RANK_1;
|
||||||
safety -= ShelterWeakness[rkUs];
|
safety -= ShelterWeakness[rkUs];
|
||||||
|
|
||||||
b = theirPawns & FileBB[f];
|
b = theirPawns & FileBB[f];
|
||||||
rkThem = b ? relative_rank(Us, Us == WHITE ? lsb(b) : msb(b)) : RANK_1;
|
rkThem = b ? relative_rank(Us, lsb(Us, b)) : RANK_1;
|
||||||
safety -= StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
|
safety -= StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue