Material::Entry* me;
Pawns::Entry* pe;
- Bitboard pinnedPieces[COLOR_NB];
Bitboard mobilityArea[COLOR_NB];
// attackedBy[color][piece type] is a bitboard representing all squares
const Score OtherCheck = S(10, 10);
const Score CloseEnemies = S( 7, 0);
const Score PawnlessFlank = S(20, 80);
- const Score LooseEnemies = S( 0, 25);
const Score ThreatByHangingPawn = S(71, 61);
const Score ThreatByRank = S(16, 3);
const Score Hanging = S(48, 27);
const int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 78, 56, 45, 11 };
// Penalties for enemy's safe checks
- const int QueenContactCheck = 997;
const int QueenCheck = 745;
const int RookCheck = 688;
const int BishopCheck = 588;
const Square Down = (Us == WHITE ? SOUTH : NORTH);
const Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
- ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
-
// Find our pawns on the first two ranks, and those which are blocked
Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
: Pt == ROOK ? attacks_bb< ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN))
: pos.attacks_from<Pt>(s);
- if (ei.pinnedPieces[Us] & s)
+ if (pos.pinned_pieces(Us) & s)
b &= LineBB[pos.square<KING>(Us)][s];
ei.attackedBy2[Us] |= ei.attackedBy[Us][ALL_PIECES] & b;
ei.kingAdjacentZoneAttacksCount[Us] += popcount(b & ei.attackedBy[Them][KING]);
}
- if (Pt == QUEEN)
- b &= ~( ei.attackedBy[Them][KNIGHT]
- | ei.attackedBy[Them][BISHOP]
- | ei.attackedBy[Them][ROOK]);
-
int mob = popcount(b & ei.mobilityArea[Us]);
mobility[Us] += MobilityBonus[Pt][mob];
kingDanger = std::min(807, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
+ 101 * ei.kingAdjacentZoneAttacksCount[Them]
+ 235 * popcount(undefended)
- + 134 * (popcount(b) + !!ei.pinnedPieces[Us])
+ + 134 * (popcount(b) + !!pos.pinned_pieces(Us))
- 717 * !pos.count<QUEEN>(Them)
- 7 * mg_value(score) / 5 - 5;
- // Analyse the enemy's safe queen contact checks. Firstly, find the
- // undefended squares around our king reachable by the enemy queen...
- b = undefended & ei.attackedBy[Them][QUEEN] & ~pos.pieces(Them);
-
- // ...and keep squares supported by another enemy piece.
- kingDanger += QueenContactCheck * popcount(b & ei.attackedBy2[Them]);
-
// Analyse the safe enemy's checks which are possible on next move
- safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them));
+ safe = ~pos.pieces(Them);
+ safe &= ~ei.attackedBy[Us][ALL_PIECES] | (undefended & ei.attackedBy2[Them]);
b1 = pos.attacks_from<ROOK >(ksq);
b2 = pos.attacks_from<BISHOP>(ksq);
Bitboard b, weak, defended, safeThreats;
Score score = SCORE_ZERO;
- // Small bonus if the opponent has loose pawns or pieces
- if ( (pos.pieces(Them) ^ pos.pieces(Them, QUEEN, KING))
- & ~(ei.attackedBy[Us][ALL_PIECES] | ei.attackedBy[Them][ALL_PIECES]))
- score += LooseEnemies;
-
// Non-pawn enemies attacked by a pawn
weak = (pos.pieces(Them) ^ pos.pieces(Them, PAWN)) & ei.attackedBy[Us][PAWN];
}
- // evaluate_passed_pawns() evaluates the passed pawns of the given color
+ // evaluate_passer_pawns() evaluates the passed pawns and candidate passed
+ // pawns of the given color.
template<Color Us, bool DoTrace>
- Score evaluate_passed_pawns(const Position& pos, const EvalInfo& ei) {
+ Score evaluate_passer_pawns(const Position& pos, const EvalInfo& ei) {
const Color Them = (Us == WHITE ? BLACK : WHITE);
{
Square s = pop_lsb(&b);
- assert(pos.pawn_passed(Us, s));
assert(!(pos.pieces(PAWN) & forward_bb(Us, s)));
bb = forward_bb(Us, s) & (ei.attackedBy[Them][ALL_PIECES] | pos.pieces(Them));
mbonus += rr + r * 2, ebonus += rr + r * 2;
} // rr != 0
- // Assign a small bonus when the opponent has no pieces left
- if (!pos.non_pawn_material(Them))
- ebonus += 20;
+ // Scale down bonus for candidate passers which need more than one pawn
+ // push to become passed.
+ if (!pos.pawn_passed(Us, s + pawn_push(Us)))
+ mbonus /= 2, ebonus /= 2;
score += make_score(mbonus, ebonus) + PassedFile[file_of(s)];
}
// If we don't already have an unusual scale factor, check for certain
// types of endgames, and use a lower scale for those.
- if ( ei.me->game_phase() < PHASE_MIDGAME
- && (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN))
+ if (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN)
{
if (pos.opposite_bishops())
{
// is almost a draw, in case of KBP vs KB, it is even more a draw.
if ( pos.non_pawn_material(WHITE) == BishopValueMg
&& pos.non_pawn_material(BLACK) == BishopValueMg)
- sf = more_than_one(pos.pieces(PAWN)) ? ScaleFactor(31) : ScaleFactor(9);
+ return more_than_one(pos.pieces(PAWN)) ? ScaleFactor(31) : ScaleFactor(9);
// Endgame with opposite-colored bishops, but also other pieces. Still
// a bit drawish, but not as drawish as with only the two bishops.
- else
- sf = ScaleFactor(46);
+ return ScaleFactor(46);
}
// Endings where weaker side can place his king in front of the opponent's
// pawns are drawish.
else if ( abs(eg) <= BishopValueEg
&& pos.count<PAWN>(strongSide) <= 2
&& !pos.pawn_passed(~strongSide, pos.square<KING>(~strongSide)))
- sf = ScaleFactor(37 + 7 * pos.count<PAWN>(strongSide));
+ return ScaleFactor(37 + 7 * pos.count<PAWN>(strongSide));
}
return sf;
- evaluate_threats<BLACK, DoTrace>(pos, ei);
// Evaluate passed pawns, we need full attack information including king
- score += evaluate_passed_pawns<WHITE, DoTrace>(pos, ei)
- - evaluate_passed_pawns<BLACK, DoTrace>(pos, ei);
+ score += evaluate_passer_pawns<WHITE, DoTrace>(pos, ei)
+ - evaluate_passer_pawns<BLACK, DoTrace>(pos, ei);
// Evaluate space for both sides, only during opening
if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 12222)