// 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
// so that the midgame and endgame scores do not change sign after the bonus.
- int u = ((mg > 0) - (mg < 0)) * std::max(std::min(complexity + 50, 0), -abs(mg));
+ int u = ((mg > 0) - (mg < 0)) * Utility::clamp(complexity + 50, -abs(mg), 0);
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));
if (T)
initialize<WHITE>();
initialize<BLACK>();
- // Pieces should be evaluated first (populate attack tables)
+ // Pieces evaluated first (also populates attackedBy, attackedBy2).
+ // Note that the order of evaluation of the terms is left unspecified
score += pieces<WHITE, KNIGHT>() - pieces<BLACK, KNIGHT>()
+ pieces<WHITE, BISHOP>() - pieces<BLACK, BISHOP>()
+ pieces<WHITE, ROOK >() - pieces<BLACK, ROOK >()
score += mobility[WHITE] - mobility[BLACK];
+ // More complex interactions that require fully populated attack bitboards
score += king< WHITE>() - king< BLACK>()
+ threats<WHITE>() - threats<BLACK>()
+ passed< WHITE>() - passed< BLACK>()
e->passedPawns[Us] = 0;
e->kingSquares[Us] = SQ_NONE;
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
- e->blockedCount[Us] = 0;
// Loop through all pawns of the current color and score each pawn
while ((s = *pl++) != SQ_NONE)
phalanx = neighbours & rank_bb(s);
support = neighbours & rank_bb(s - Up);
- e->blockedCount[Us] += blocked || more_than_one(leverPush);
+ e->blockedCount += blocked || more_than_one(leverPush);
// A pawn is backward when it is behind all pawns of the same color on
// the adjacent files and cannot safely advance.
return e;
e->key = key;
+ e->blockedCount = 0;
e->scores[WHITE] = evaluate<WHITE>(pos, e);
e->scores[BLACK] = evaluate<BLACK>(pos, e);
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
- int blocked_count() const { return blockedCount[WHITE] + blockedCount[BLACK]; }
+ int blocked_count() const { return blockedCount; }
template<Color Us>
Score king_safety(const Position& pos) {
Square kingSquares[COLOR_NB];
Score kingSafety[COLOR_NB];
int castlingRights[COLOR_NB];
- int blockedCount[COLOR_NB];
+ int blockedCount;
};
typedef HashTable<Entry, 131072> Table;
Square rto = relative_square(c, cr & KING_SIDE ? SQ_F1 : SQ_D1);
castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
- & ~(square_bb(kfrom) | rfrom);
+ & ~(kfrom | rfrom);
}
}
inline int Position::castling_rights(Color c) const {
- return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
+ return c & CastlingRights(st->castlingRights);
}
inline bool Position::castling_impeded(CastlingRights cr) const {
// Different node types, used as a template parameter
enum NodeType { NonPV, PV };
- constexpr uint64_t ttHitAverageWindow = 4096;
- constexpr uint64_t ttHitAverageResolution = 1024;
+ constexpr uint64_t TtHitAverageWindow = 4096;
+ constexpr uint64_t TtHitAverageResolution = 1024;
// Razor and futility margins
constexpr int RazorMargin = 531;
multiPV = std::max(multiPV, (size_t)4);
multiPV = std::min(multiPV, rootMoves.size());
- ttHitAverage = ttHitAverageWindow * ttHitAverageResolution / 2;
+ ttHitAverage = TtHitAverageWindow * TtHitAverageResolution / 2;
int ct = int(Options["Contempt"]) * PawnValueEg / 100; // From centipawns
thisThread->lowPlyHistory[ss->ply - 1][from_to((ss-1)->currentMove)] << stat_bonus(depth - 5);
// thisThread->ttHitAverage can be used to approximate the running average of ttHit
- thisThread->ttHitAverage = (ttHitAverageWindow - 1) * thisThread->ttHitAverage / ttHitAverageWindow
- + ttHitAverageResolution * ttHit;
+ thisThread->ttHitAverage = (TtHitAverageWindow - 1) * thisThread->ttHitAverage / TtHitAverageWindow
+ + TtHitAverageResolution * ttHit;
// At non-PV nodes we check for an early TT cutoff
if ( !PvNode
|| moveCountPruning
|| ss->staticEval + PieceValue[EG][pos.captured_piece()] <= alpha
|| cutNode
- || thisThread->ttHitAverage < 375 * ttHitAverageResolution * ttHitAverageWindow / 1024))
+ || thisThread->ttHitAverage < 375 * TtHitAverageResolution * TtHitAverageWindow / 1024))
{
Depth r = reduction(improving, depth, moveCount);
// Decrease reduction if the ttHit running average is large
- if (thisThread->ttHitAverage > 500 * ttHitAverageResolution * ttHitAverageWindow / 1024)
+ if (thisThread->ttHitAverage > 500 * TtHitAverageResolution * TtHitAverageWindow / 1024)
r--;
// Reduction if other threads are searching this position.