constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
- constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
+ Bitboard LowRanks = rank_bb(relative_rank(Us, RANK_2, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_3, pos.max_rank()));
// Find our pawns that are blocked or on the first two ranks
Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
if (pos.count<KING>(Us) && pos.non_pawn_material(Them) >= RookValueMg + KnightValueMg)
{
kingRing[Us] = attackedBy[Us][KING];
- if (relative_rank(Us, pos.square<KING>(Us)) == RANK_1)
+ if (relative_rank(Us, pos.square<KING>(Us), pos.max_rank()) == RANK_1)
kingRing[Us] |= shift<Up>(kingRing[Us]);
if (file_of(pos.square<KING>(Us)) == FILE_H)
score += Outpost[Pt == BISHOP][bool(attackedBy[Us][PAWN] & bb)];
// Bonus when behind a pawn
- if ( relative_rank(Us, s) < RANK_5
+ if ( relative_rank(Us, s, pos.max_rank()) < RANK_5
&& (pos.pieces(PAWN) & (s + pawn_push(Us))))
score += MinorBehindPawn;
if (Pt == ROOK)
{
// Bonus for aligning rook with enemy pawns on the same rank/file
- if (relative_rank(Us, s) >= RANK_5)
+ if (relative_rank(Us, s, pos.max_rank()) >= RANK_5)
score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[Us][ROOK][s]);
// Bonus for rook on an open or semi-open file
Square s = pop_lsb(&b);
score += ThreatByMinor[type_of(pos.piece_on(s))];
if (type_of(pos.piece_on(s)) != PAWN)
- score += ThreatByRank * (int)relative_rank(Them, s);
+ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank());
}
b = (pos.pieces(Them, QUEEN) | weak) & attackedBy[Us][ROOK];
Square s = pop_lsb(&b);
score += ThreatByRook[type_of(pos.piece_on(s))];
if (type_of(pos.piece_on(s)) != PAWN)
- score += ThreatByRank * (int)relative_rank(Them, s);
+ score += ThreatByRank * (int)relative_rank(Them, s, pos.max_rank());
}
b = weak & attackedBy[Us][KING];
bb = forward_file_bb(Us, s) & (attackedBy[Them][ALL_PIECES] | pos.pieces(Them));
score -= HinderPassedPawn * popcount(bb);
- int r = relative_rank(Us, s);
+ int r = relative_rank(Us, s, pos.max_rank());
int w = PassedDanger[r];
Score bonus = PassedRank[r];
e->passedPawns[Us] |= s;
else if ( stoppers == SquareBB[s + Up]
- && relative_rank(Us, s) >= RANK_5)
+ && relative_rank(Us, s, pos.max_rank()) >= RANK_5)
{
b = shift<Up>(supported) & ~theirPawns;
while (b)
// Score this pawn
if (supported | phalanx)
- score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s)];
+ score += Connected[opposed][bool(phalanx)][popcount(supported)][relative_rank(Us, s, pos.max_rank())];
else if (!neighbours)
score -= Isolated, e->weakUnopposed[Us] += !opposed;
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
- constexpr Bitboard BlockRanks = (Us == WHITE ? Rank1BB | Rank2BB : Rank8BB | Rank7BB);
+ Bitboard BlockRanks = rank_bb(relative_rank(Us, RANK_1, pos.max_rank())) | rank_bb(relative_rank(Us, RANK_2, pos.max_rank()));
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
Bitboard ourPawns = b & pos.pieces(Us);
for (File f = File(center - 1); f <= File(center + 1); ++f)
{
b = ourPawns & file_bb(f);
- int ourRank = b ? relative_rank(Us, backmost_sq(Us, b)) : 0;
+ int ourRank = b ? relative_rank(Us, backmost_sq(Us, b), pos.max_rank()) : 0;
b = theirPawns & file_bb(f);
- int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
+ int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b), pos.max_rank()) : 0;
int d = std::min(f, ~f);
safety += ShelterStrength[d][ourRank];