Score Evaluation<T>::evaluate_king() {
const Color Them = (Us == WHITE ? BLACK : WHITE);
- const Direction Up = (Us == WHITE ? NORTH : SOUTH);
const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
const Square ksq = pos.square<KING>(Us);
Bitboard weak, b, b1, b2, safe, unsafeChecks;
- int kingDanger;
// King shelter and enemy pawns storm
Score score = pe->king_safety<Us>(pos, ksq);
& ~attackedBy2[Us]
& (attackedBy[Us][KING] | attackedBy[Us][QUEEN] | ~attackedBy[Us][ALL_PIECES]);
- kingDanger = unsafeChecks = 0;
+ int kingDanger = unsafeChecks = 0;
// Analyse the safe enemy's checks which are possible on next move
safe = ~pos.pieces(Them);
unsafeChecks |= b;
// Unsafe or occupied checking squares will also be considered, as long as
- // the square is not defended by our pawns or occupied by a blocked pawn.
- unsafeChecks &= ~( attackedBy[Us][PAWN]
- | (pos.pieces(Them, PAWN) & shift<Up>(pos.pieces(PAWN))));
+ // the square is in the attacker's mobility area.
+ unsafeChecks &= mobilityArea[Them];
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
+ 102 * kingAdjacentZoneAttacksCount[Them]
Trace::add(TOTAL, score);
}
- return (pos.side_to_move() == WHITE ? v : -v) + Eval::Tempo; // Side to move point of view
+ return pos.side_to_move() == WHITE ? v : -v; // Side to move point of view
}
} // namespace
Value Eval::evaluate(const Position& pos)
{
- return Evaluation<>(pos).value();
+ return Evaluation<>(pos).value() + Eval::Tempo;
}
/// trace() is like evaluate(), but instead of returning a value, it returns
std::memset(scores, 0, sizeof(scores));
- Value v = Evaluation<TRACE>(pos).value();
+ Value v = Evaluation<TRACE>(pos).value() + Eval::Tempo;
v = pos.side_to_move() == WHITE ? v : -v; // White's point of view
std::stringstream ss;