// If the defending king has distance 1 to the promotion square or
// is placed somewhere in front of the pawn, it's a draw.
if(square_distance(kingSq, queeningSq) <= 1 ||
- pawn_rank(strongerSide, kingSq) >= rank)
+ relative_rank(strongerSide, kingSq) >= rank)
return ScaleFactor(0);
}
}
assert(pos.pawn_count(weakerSide) >= 1);
Square kingSq = pos.king_square(weakerSide);
- if(pawn_rank(weakerSide, kingSq) <= RANK_2 &&
- pawn_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4 &&
+ if(relative_rank(weakerSide, kingSq) <= RANK_2 &&
+ relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4 &&
(pos.rooks(weakerSide) & relative_rank_bb(weakerSide, RANK_3)) &&
(pos.pawns(weakerSide) & relative_rank_bb(weakerSide, RANK_2)) &&
(pos.king_attacks(kingSq) & pos.pawns(weakerSide))) {
pos.pawn_is_passed(strongerSide, wpsq2))
return SCALE_FACTOR_NONE;
- Rank r = Max(pawn_rank(strongerSide, wpsq1), pawn_rank(strongerSide, wpsq2));
+ Rank r = Max(relative_rank(strongerSide, wpsq1), relative_rank(strongerSide, wpsq2));
if(file_distance(bksq, wpsq1) <= 1 && file_distance(bksq, wpsq2) <= 1
- && pawn_rank(strongerSide, bksq) > r) {
+ && relative_rank(strongerSide, bksq) > r) {
switch(r) {
case RANK_2: return ScaleFactor(10);
// Case 1: Defending king blocks the pawn, and cannot be driven away.
if(square_file(weakerKingSq) == square_file(pawnSq)
- && pawn_rank(strongerSide, pawnSq) < pawn_rank(strongerSide, weakerKingSq)
+ && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
&& (square_color(weakerKingSq) != square_color(strongerBishopSq)
- || pawn_rank(strongerSide, weakerKingSq) <= RANK_6))
+ || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return ScaleFactor(0);
// Case 2: Opposite colored bishops.
// These rules are probably not perfect, but in practice they work
// reasonably well.
- if(pawn_rank(strongerSide, pawnSq) <= RANK_5)
+ if(relative_rank(strongerSide, pawnSq) <= RANK_5)
return ScaleFactor(0);
else {
Bitboard ray =
Square weakerKingSq = pos.king_square(weakerSide);
if(square_file(weakerKingSq) == square_file(pawnSq)
- && pawn_rank(strongerSide, pawnSq) < pawn_rank(strongerSide, weakerKingSq)
+ && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
&& (square_color(weakerKingSq) != square_color(strongerBishopSq)
- || pawn_rank(strongerSide, weakerKingSq) <= RANK_6))
+ || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return ScaleFactor(0);
return SCALE_FACTOR_NONE;
void evaluate_rook(const Position &p, Square s, Color us, EvalInfo &ei) {
- Color them = opposite_color(us);
-
- // Open and half-open files:
- File f = square_file(s);
- if(ei.pi->file_is_half_open(us, f)) {
- if(ei.pi->file_is_half_open(them, f)) {
- ei.mgValue += Sign[us] * RookOpenFileBonus;
- ei.egValue += Sign[us] * RookOpenFileBonus;
- }
- else {
- ei.mgValue += Sign[us] * RookHalfOpenFileBonus;
- ei.egValue += Sign[us] * RookHalfOpenFileBonus;
- }
- }
-
- // Rook on 7th rank:
- if(pawn_rank(us, s) == RANK_7 &&
- pawn_rank(us, p.king_square(them)) == RANK_8) {
- ei.mgValue += Sign[us] * MidgameRookOn7thBonus;
- ei.egValue += Sign[us] * EndgameRookOn7thBonus;
- }
-
//Bitboard b = p.rook_attacks(s);
Bitboard b = rook_attacks_bb(s, p.occupied_squares() & ~p.rooks_and_queens(us));
ei.attackedBy[us][ROOK] |= b;
int mob = evaluate_common(p, b, us, ei, RookAttackWeight, MidgameRookMobilityBonus,
EndgameRookMobilityBonus);
- // Penalize rooks which are trapped inside a king which has lost the
- // right to castle:
- if(mob <= 6 && !ei.pi->file_is_half_open(us, f)) {
- Square ksq = p.king_square(us);
- if(square_file(ksq) >= FILE_E && square_file(s) > square_file(ksq) &&
- (pawn_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s))) {
- // Is there a half-open file between the king and the edge of the
- // board?
- if(!(ei.pi->has_open_file_to_right(us, square_file(ksq)))) {
- ei.mgValue -= p.can_castle(us)?
- Sign[us] * ((TrappedRookPenalty - mob * 16) / 2) :
- Sign[us] * (TrappedRookPenalty - mob * 16);
+ // Rook on 7th rank
+ Color them = opposite_color(us);
+
+ if ( relative_rank(us, s) == RANK_7
+ && relative_rank(us, p.king_square(them)) == RANK_8)
+ {
+ ei.mgValue += Sign[us] * MidgameRookOn7thBonus;
+ ei.egValue += Sign[us] * EndgameRookOn7thBonus;
+ }
+
+ // Open and half-open files
+ File f = square_file(s);
+ if (ei.pi->file_is_half_open(us, f))
+ {
+ if (ei.pi->file_is_half_open(them, f))
+ {
+ ei.mgValue += Sign[us] * RookOpenFileBonus;
+ ei.egValue += Sign[us] * RookOpenFileBonus;
}
- }
- else if(square_file(ksq) <= FILE_D && square_file(s) < square_file(ksq)
- && (pawn_rank(us, ksq) == RANK_1 ||
- square_rank(ksq) == square_rank(s))) {
- // Is there a half-open file between the king and the edge of the
- // board?
- if(!(ei.pi->has_open_file_to_left(us, square_file(ksq)))) {
- ei.mgValue -= p.can_castle(us)?
- Sign[us] * ((TrappedRookPenalty - mob * 16) / 2) :
- Sign[us] * (TrappedRookPenalty - mob * 16);
+ else
+ {
+ ei.mgValue += Sign[us] * RookHalfOpenFileBonus;
+ ei.egValue += Sign[us] * RookHalfOpenFileBonus;
}
- }
+ }
+
+ // Penalize rooks which are trapped inside a king. Penalize more if
+ // king has lost right to castle
+ if (mob > 6 || ei.pi->file_is_half_open(us, f))
+ return;
+
+ Square ksq = p.king_square(us);
+ if ( square_file(ksq) >= FILE_E
+ && square_file(s) > square_file(ksq)
+ && (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
+ {
+ // Is there a half-open file between the king and the edge of the board?
+ if (!ei.pi->has_open_file_to_right(us, square_file(ksq)))
+ ei.mgValue -= p.can_castle(us)? Sign[us] * ((TrappedRookPenalty - mob * 16) / 2)
+ : Sign[us] * (TrappedRookPenalty - mob * 16);
+ }
+ else if ( square_file(ksq) <= FILE_D
+ && square_file(s) < square_file(ksq)
+ && (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
+ {
+ // Is there a half-open file between the king and the edge of the board?
+ if (!ei.pi->has_open_file_to_left(us, square_file(ksq)))
+ ei.mgValue -= p.can_castle(us)? Sign[us] * ((TrappedRookPenalty - mob * 16) / 2)
+ : Sign[us] * (TrappedRookPenalty - mob * 16);
}
}
void evaluate_queen(const Position &p, Square s, Color us, EvalInfo &ei) {
- Color them = opposite_color(us);
-
- // Queen on 7th rank:
- if(pawn_rank(us, s) == RANK_7 &&
- pawn_rank(us, p.king_square(them)) == RANK_8) {
- ei.mgValue += Sign[us] * MidgameQueenOn7thBonus;
- ei.egValue += Sign[us] * EndgameQueenOn7thBonus;
- }
-
Bitboard b = p.queen_attacks(s);
ei.attackedBy[us][QUEEN] |= b;
// King attack and mobility
evaluate_common(p, b, us, ei, QueenAttackWeight, MidgameQueenMobilityBonus,
EndgameQueenMobilityBonus);
+
+ // Queen on 7th rank
+ Color them = opposite_color(us);
+
+ if ( relative_rank(us, s) == RANK_7
+ && relative_rank(us, p.king_square(them)) == RANK_8)
+ {
+ ei.mgValue += Sign[us] * MidgameQueenOn7thBonus;
+ ei.egValue += Sign[us] * EndgameQueenOn7thBonus;
+ }
}
int shelter = 0, sign = Sign[us];
// King shelter.
- if(pawn_rank(us, s) <= RANK_4) {
+ if(relative_rank(us, s) <= RANK_4) {
Bitboard pawns = p.pawns(us) & this_and_neighboring_files_bb(s);
Rank r = square_rank(s);
for(int i = 0; i < 3; i++)
assert(pos.piece_on(s) == pawn_of_color(us));
assert(pos.pawn_is_passed(us, s));
- int r = int(pawn_rank(us, s) - RANK_2);
+ int r = int(relative_rank(us, s) - RANK_2);
int tr = Max(0, r * (r-1));
Square blockSq = s + pawn_push(us);
+ ((us == pos.side_to_move())? 0 : 1);
if(d < 0) {
- int mtg = RANK_8 - pawn_rank(us, s);
+ int mtg = RANK_8 - relative_rank(us, s);
int blockerCount =
count_1s_max_15(squares_in_front_of(us,s)&pos.occupied_squares());
mtg += blockerCount;
from = move_from(m);
to = move_to(m);
- assert(pawn_rank(us, to) == RANK_8);
+ assert(relative_rank(us, to) == RANK_8);
assert(this->piece_on(from) == pawn_of_color(us));
assert(this->color_of_piece_on(to) == them || this->square_is_empty(to));
capsq = (us == WHITE)? (to - DELTA_N) : (to - DELTA_S);
assert(to == epSquare);
- assert(pawn_rank(us, to) == RANK_6);
+ assert(relative_rank(us, to) == RANK_6);
assert(this->piece_on(to) == EMPTY);
assert(this->piece_on(from) == pawn_of_color(us));
assert(this->piece_on(capsq) == pawn_of_color(them));
from = move_from(m);
to = move_to(m);
- assert(pawn_rank(us, to) == RANK_8);
+ assert(relative_rank(us, to) == RANK_8);
assert(this->piece_on(from) == EMPTY);
// Remove promoted piece:
capsq = (us == WHITE)? (to - DELTA_N) : (to - DELTA_S);
assert(to == this->ep_square());
- assert(pawn_rank(us, to) == RANK_6);
+ assert(relative_rank(us, to) == RANK_6);
assert(this->piece_on(to) == pawn_of_color(us));
assert(this->piece_on(from) == EMPTY);
assert(this->piece_on(capsq) == EMPTY);
if(this->ep_square() != SQ_NONE) {
// The en passant square must be on rank 6, from the point of view of the
// side to move.
- if(pawn_rank(this->side_to_move(), this->ep_square()) != RANK_6)
+ if(relative_rank(this->side_to_move(), this->ep_square()) != RANK_6)
return false;
}