// which piece type attacks which one. Attacks on lesser pieces which are
// pawn-defended are not considered.
constexpr Score ThreatByMinor[PIECE_TYPE_NB] = {
- S(0, 0), S(6, 32), S(59, 41), S(79, 56), S(90, 119), S(79, 161)
+ S(0, 0), S(5, 32), S(57, 41), S(77, 56), S(88, 119), S(79, 161)
};
constexpr Score ThreatByRook[PIECE_TYPE_NB] = {
- S(0, 0), S(3, 44), S(38, 71), S(38, 61), S(0, 38), S(51, 38)
+ S(0, 0), S(2, 44), S(36, 71), S(36, 61), S(0, 38), S(51, 38)
};
// PassedRank[Rank] contains a bonus according to the rank of a passed pawn
};
// Assorted bonuses and penalties
- constexpr Score BishopPawns = S( 3, 7);
- constexpr Score CorneredBishop = S( 50, 50);
- constexpr Score FlankAttacks = S( 8, 0);
- constexpr Score Hanging = S( 69, 36);
- constexpr Score KingProtector = S( 7, 8);
- constexpr Score KnightOnQueen = S( 16, 12);
- constexpr Score LongDiagonalBishop = S( 45, 0);
- constexpr Score MinorBehindPawn = S( 18, 3);
- constexpr Score Outpost = S( 30, 21);
- constexpr Score PassedFile = S( 11, 8);
- constexpr Score PawnlessFlank = S( 17, 95);
- constexpr Score RestrictedPiece = S( 7, 7);
- constexpr Score ReachableOutpost = S( 32, 10);
- constexpr Score RookOnQueenFile = S( 7, 6);
- constexpr Score SliderOnQueen = S( 59, 18);
- constexpr Score ThreatByKing = S( 24, 89);
- constexpr Score ThreatByPawnPush = S( 48, 39);
- constexpr Score ThreatBySafePawn = S(173, 94);
- constexpr Score TrappedRook = S( 52, 10);
- constexpr Score WeakQueen = S( 49, 15);
+ constexpr Score BishopPawns = S( 3, 7);
+ constexpr Score CorneredBishop = S( 50, 50);
+ constexpr Score FlankAttacks = S( 8, 0);
+ constexpr Score Hanging = S( 69, 36);
+ constexpr Score KingProtector = S( 7, 8);
+ constexpr Score KnightOnQueen = S( 16, 12);
+ constexpr Score LongDiagonalBishop = S( 45, 0);
+ constexpr Score MinorBehindPawn = S( 18, 3);
+ constexpr Score Outpost = S( 30, 21);
+ constexpr Score PassedFile = S( 11, 8);
+ constexpr Score PawnlessFlank = S( 17, 95);
+ constexpr Score RestrictedPiece = S( 7, 7);
+ constexpr Score RookOnQueenFile = S( 7, 6);
+ constexpr Score SliderOnQueen = S( 59, 18);
+ constexpr Score ThreatByKing = S( 24, 89);
+ constexpr Score ThreatByPawnPush = S( 48, 39);
+ constexpr Score ThreatBySafePawn = S(173, 94);
+ constexpr Score TrappedRook = S( 52, 10);
+ constexpr Score WeakQueen = S( 49, 15);
+ constexpr Score WeakQueenProtection = S( 14, 0);
#undef S
attackedBy2[Us] = dblAttackByPawn | (attackedBy[Us][KING] & attackedBy[Us][PAWN]);
// Init our king safety tables
- Square s = make_square(clamp(file_of(ksq), FILE_B, FILE_G),
- clamp(rank_of(ksq), RANK_2, RANK_7));
+ Square s = make_square(Utility::clamp(file_of(ksq), FILE_B, FILE_G),
+ Utility::clamp(rank_of(ksq), RANK_2, RANK_7));
kingRing[Us] = PseudoAttacks[KING][s] | s;
kingAttackersCount[Them] = popcount(kingRing[Us] & pe->pawn_attacks(Them));
score += Outpost * (Pt == KNIGHT ? 2 : 1);
else if (Pt == KNIGHT && bb & b & ~pos.pieces(Us))
- score += ReachableOutpost;
+ score += Outpost;
// Knight and Bishop bonus for being right behind a pawn
if (shift<Down>(pos.pieces(PAWN)) & s)
// Bonus for bishop on a long diagonal which can "see" both center squares
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
score += LongDiagonalBishop;
- }
- // An important Chess960 pattern: A cornered bishop blocked by a friendly
- // pawn diagonally in front of it is a very serious problem, especially
- // when that pawn is also blocked.
- if ( Pt == BISHOP
- && pos.is_chess960()
- && (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
- {
- Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
- if (pos.piece_on(s + d) == make_piece(Us, PAWN))
- score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
- : pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
- : CorneredBishop;
+ // An important Chess960 pattern: a cornered bishop blocked by a friendly
+ // pawn diagonally in front of it is a very serious problem, especially
+ // when that pawn is also blocked.
+ if ( pos.is_chess960()
+ && (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
+ {
+ Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
+ if (pos.piece_on(s + d) == make_piece(Us, PAWN))
+ score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
+ : pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
+ : CorneredBishop;
+ }
}
}
b = ~attackedBy[Them][ALL_PIECES]
| (nonPawnEnemies & attackedBy2[Us]);
score += Hanging * popcount(weak & b);
+
+ // Additional bonus if weak piece is only protected by a queen
+ score += WeakQueenProtection * popcount(weak & attackedBy[Them][QUEEN]);
}
// Bonus for restricting their piece moves
b = attackedBy[Them][ALL_PIECES]
& ~stronglyProtected
& attackedBy[Us][ALL_PIECES];
-
score += RestrictedPiece * popcount(b);
// Protected or unattacked squares
|| (pos.pieces(PAWN) & (s + Up)))
bonus = bonus / 2;
- score += bonus - PassedFile * map_to_queenside(file_of(s));
+ score += bonus - PassedFile * edge_distance(file_of(s));
}
if (T)
template<Tracing T>
Score Evaluation<T>::initiative(Score score) const {
- Value mg = mg_value(score);
- Value eg = eg_value(score);
-
int outflanking = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
- distance<Rank>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
- bool infiltration = rank_of(pos.square<KING>(WHITE)) > RANK_4
- || rank_of(pos.square<KING>(BLACK)) < RANK_5;
-
bool pawnsOnBothFlanks = (pos.pieces(PAWN) & QueenSide)
&& (pos.pieces(PAWN) & KingSide);
&& outflanking < 0
&& !pawnsOnBothFlanks;
+ bool infiltration = rank_of(pos.square<KING>(WHITE)) > RANK_4
+ || rank_of(pos.square<KING>(BLACK)) < RANK_5;
+
// Compute the initiative bonus for the attacking side
int complexity = 9 * pe->passed_count()
+ 11 * pos.count<PAWN>()
+ 9 * outflanking
- + 12 * infiltration
+ 21 * pawnsOnBothFlanks
+ + 24 * infiltration
+ 51 * !pos.non_pawn_material()
- 43 * almostUnwinnable
- - 100 ;
+ -110 ;
+
+ Value mg = mg_value(score);
+ Value eg = eg_value(score);
// Now apply the bonus: note that we find the attacking side by extracting the
// sign of the midgame or endgame values, and that we carefully cap the bonus
Trace::add(TOTAL, score);
}
- return (pos.side_to_move() == WHITE ? v : -v) // Side to move point of view
- + Eval::Tempo;
+ return (pos.side_to_move() == WHITE ? v : -v) + Tempo; // Side to move point of view
}
} // namespace