Skip to content

Commit

Permalink
Small cleanups
Browse files Browse the repository at this point in the history
closes #2628

No functional change
  • Loading branch information
vondele committed Apr 29, 2020
1 parent 4776dc0 commit 353e206
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/evaluate.cpp
Expand Up @@ -740,7 +740,7 @@ namespace {
// 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)
Expand Down Expand Up @@ -815,14 +815,16 @@ namespace {
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 >()
+ pieces<WHITE, QUEEN >() - pieces<BLACK, QUEEN >();

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>()
Expand Down
4 changes: 2 additions & 2 deletions src/pawns.cpp
Expand Up @@ -86,7 +86,6 @@ namespace {
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)
Expand All @@ -106,7 +105,7 @@ namespace {
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.
Expand Down Expand Up @@ -178,6 +177,7 @@ Entry* probe(const Position& pos) {
return e;

e->key = key;
e->blockedCount = 0;
e->scores[WHITE] = evaluate<WHITE>(pos, e);
e->scores[BLACK] = evaluate<BLACK>(pos, e);

Expand Down
4 changes: 2 additions & 2 deletions src/pawns.h
Expand Up @@ -38,7 +38,7 @@ struct Entry {
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) {
Expand All @@ -60,7 +60,7 @@ struct Entry {
Square kingSquares[COLOR_NB];
Score kingSafety[COLOR_NB];
int castlingRights[COLOR_NB];
int blockedCount[COLOR_NB];
int blockedCount;
};

typedef HashTable<Entry, 131072> Table;
Expand Down
2 changes: 1 addition & 1 deletion src/position.cpp
Expand Up @@ -306,7 +306,7 @@ void Position::set_castling_right(Color c, Square rfrom) {
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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/position.h
Expand Up @@ -269,7 +269,7 @@ inline bool Position::can_castle(CastlingRights cr) const {
}

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 {
Expand Down
14 changes: 7 additions & 7 deletions src/search.cpp
Expand Up @@ -61,8 +61,8 @@ namespace {
// 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;
Expand Down Expand Up @@ -378,7 +378,7 @@ void Thread::search() {
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

Expand Down Expand Up @@ -702,8 +702,8 @@ namespace {
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
Expand Down Expand Up @@ -1170,12 +1170,12 @@ namespace {
|| 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.
Expand Down

0 comments on commit 353e206

Please sign in to comment.