- // Add the scores for this pawn to the middle game and endgame eval.
- ei.mgValue += apply_weight(Sign[Us] * mbonus, WeightPassedPawnsMidgame);
- ei.egValue += apply_weight(Sign[Us] * ebonus, WeightPassedPawnsEndgame);
-
- } // while
- }
-
-
- // evaluate_passed_pawns() evaluates the passed pawns for both sides
-
- void evaluate_passed_pawns(const Position& pos, EvalInfo& ei) {
-
- int movesToGo[2] = {0, 0};
- Square pawnToGo[2] = {SQ_NONE, SQ_NONE};
-
- // Evaluate pawns for each color
- evaluate_passed_pawns_of_color<WHITE>(pos, movesToGo, pawnToGo, ei);
- evaluate_passed_pawns_of_color<BLACK>(pos, movesToGo, pawnToGo, ei);
-
- // Neither side has an unstoppable passed pawn?
- if (!(movesToGo[WHITE] | movesToGo[BLACK]))
- return;
-
- // Does only one side have an unstoppable passed pawn?
- if (!movesToGo[WHITE] || !movesToGo[BLACK])
- {
- Color winnerSide = movesToGo[WHITE] ? WHITE : BLACK;
- ei.egValue += Sign[winnerSide] * (UnstoppablePawnValue - Value(0x40 * movesToGo[winnerSide]));
- }
- else
- { // Both sides have unstoppable pawns! Try to find out who queens
- // first. We begin by transforming 'movesToGo' to the number of
- // plies until the pawn queens for both sides.
- movesToGo[WHITE] *= 2;
- movesToGo[BLACK] *= 2;
- movesToGo[pos.side_to_move()]--;
-
- Color winnerSide = movesToGo[WHITE] < movesToGo[BLACK] ? WHITE : BLACK;
- Color loserSide = opposite_color(winnerSide);
-
- // If one side queens at least three plies before the other, that side wins
- if (movesToGo[winnerSide] <= movesToGo[loserSide] - 3)
- ei.egValue += Sign[winnerSide] * (UnstoppablePawnValue - Value(0x40 * (movesToGo[winnerSide]/2)));
-
- // If one side queens one ply before the other and checks the king or attacks
- // the undefended opponent's queening square, that side wins. To avoid cases
- // where the opponent's king could move somewhere before first pawn queens we
- // consider only free paths to queen for both pawns.
- else if ( !(squares_in_front_of(WHITE, pawnToGo[WHITE]) & pos.occupied_squares())
- && !(squares_in_front_of(BLACK, pawnToGo[BLACK]) & pos.occupied_squares()))
- {
- assert(movesToGo[loserSide] - movesToGo[winnerSide] == 1);
-
- Square winnerQSq = relative_square(winnerSide, make_square(square_file(pawnToGo[winnerSide]), RANK_8));
- Square loserQSq = relative_square(loserSide, make_square(square_file(pawnToGo[loserSide]), RANK_8));
-
- Bitboard b = pos.attacks_from<QUEEN>(winnerQSq);
-
- if ( (b & pos.pieces(KING, loserSide))
- ||(bit_is_set(b, loserQSq) && !bit_is_set(ei.attacked_by(loserSide), loserQSq)))
- ei.egValue += Sign[winnerSide] * (UnstoppablePawnValue - Value(0x40 * (movesToGo[winnerSide]/2)));
- }
- }
- }
-
-
- // evaluate_trapped_bishop_a7h7() determines whether a bishop on a7/h7
- // (a2/h2 for black) is trapped by enemy pawns, and assigns a penalty
- // if it is.
-
- void evaluate_trapped_bishop_a7h7(const Position& pos, Square s, Color us, EvalInfo &ei) {
-
- assert(square_is_ok(s));
- assert(pos.piece_on(s) == piece_of_color_and_type(us, BISHOP));
-
- Square b6 = relative_square(us, (square_file(s) == FILE_A) ? SQ_B6 : SQ_G6);
- Square b8 = relative_square(us, (square_file(s) == FILE_A) ? SQ_B8 : SQ_G8);
-
- if ( pos.piece_on(b6) == piece_of_color_and_type(opposite_color(us), PAWN)
- && pos.see(s, b6) < 0
- && pos.see(s, b8) < 0)
- {
- ei.mgValue -= Sign[us] * TrappedBishopA7H7Penalty;
- ei.egValue -= Sign[us] * TrappedBishopA7H7Penalty;
- }
- }
-
-
- // evaluate_trapped_bishop_a1h1() determines whether a bishop on a1/h1
- // (a8/h8 for black) is trapped by a friendly pawn on b2/g2 (b7/g7 for
- // black), and assigns a penalty if it is. This pattern can obviously
- // only occur in Chess960 games.
-
- void evaluate_trapped_bishop_a1h1(const Position& pos, Square s, Color us, EvalInfo& ei) {
-
- Piece pawn = piece_of_color_and_type(us, PAWN);
- Square b2, b3, c3;
-
- assert(Chess960);
- assert(square_is_ok(s));
- assert(pos.piece_on(s) == piece_of_color_and_type(us, BISHOP));
-
- if (square_file(s) == FILE_A)
- {
- b2 = relative_square(us, SQ_B2);
- b3 = relative_square(us, SQ_B3);
- c3 = relative_square(us, SQ_C3);
- }
- else
- {
- b2 = relative_square(us, SQ_G2);
- b3 = relative_square(us, SQ_G3);
- c3 = relative_square(us, SQ_F3);
- }