Skip to content

Commit 353e206

Browse files
committed
Small cleanups
closes #2628 No functional change
1 parent 4776dc0 commit 353e206

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

src/evaluate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ namespace {
740740
// Now apply the bonus: note that we find the attacking side by extracting the
741741
// sign of the midgame or endgame values, and that we carefully cap the bonus
742742
// so that the midgame and endgame scores do not change sign after the bonus.
743-
int u = ((mg > 0) - (mg < 0)) * std::max(std::min(complexity + 50, 0), -abs(mg));
743+
int u = ((mg > 0) - (mg < 0)) * Utility::clamp(complexity + 50, -abs(mg), 0);
744744
int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg));
745745

746746
if (T)
@@ -815,14 +815,16 @@ namespace {
815815
initialize<WHITE>();
816816
initialize<BLACK>();
817817

818-
// Pieces should be evaluated first (populate attack tables)
818+
// Pieces evaluated first (also populates attackedBy, attackedBy2).
819+
// Note that the order of evaluation of the terms is left unspecified
819820
score += pieces<WHITE, KNIGHT>() - pieces<BLACK, KNIGHT>()
820821
+ pieces<WHITE, BISHOP>() - pieces<BLACK, BISHOP>()
821822
+ pieces<WHITE, ROOK >() - pieces<BLACK, ROOK >()
822823
+ pieces<WHITE, QUEEN >() - pieces<BLACK, QUEEN >();
823824

824825
score += mobility[WHITE] - mobility[BLACK];
825826

827+
// More complex interactions that require fully populated attack bitboards
826828
score += king< WHITE>() - king< BLACK>()
827829
+ threats<WHITE>() - threats<BLACK>()
828830
+ passed< WHITE>() - passed< BLACK>()

src/pawns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ namespace {
8686
e->passedPawns[Us] = 0;
8787
e->kingSquares[Us] = SQ_NONE;
8888
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
89-
e->blockedCount[Us] = 0;
9089

9190
// Loop through all pawns of the current color and score each pawn
9291
while ((s = *pl++) != SQ_NONE)
@@ -106,7 +105,7 @@ namespace {
106105
phalanx = neighbours & rank_bb(s);
107106
support = neighbours & rank_bb(s - Up);
108107

109-
e->blockedCount[Us] += blocked || more_than_one(leverPush);
108+
e->blockedCount += blocked || more_than_one(leverPush);
110109

111110
// A pawn is backward when it is behind all pawns of the same color on
112111
// the adjacent files and cannot safely advance.
@@ -178,6 +177,7 @@ Entry* probe(const Position& pos) {
178177
return e;
179178

180179
e->key = key;
180+
e->blockedCount = 0;
181181
e->scores[WHITE] = evaluate<WHITE>(pos, e);
182182
e->scores[BLACK] = evaluate<BLACK>(pos, e);
183183

src/pawns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Entry {
3838
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
3939
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
4040
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
41-
int blocked_count() const { return blockedCount[WHITE] + blockedCount[BLACK]; }
41+
int blocked_count() const { return blockedCount; }
4242

4343
template<Color Us>
4444
Score king_safety(const Position& pos) {
@@ -60,7 +60,7 @@ struct Entry {
6060
Square kingSquares[COLOR_NB];
6161
Score kingSafety[COLOR_NB];
6262
int castlingRights[COLOR_NB];
63-
int blockedCount[COLOR_NB];
63+
int blockedCount;
6464
};
6565

6666
typedef HashTable<Entry, 131072> Table;

src/position.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void Position::set_castling_right(Color c, Square rfrom) {
306306
Square rto = relative_square(c, cr & KING_SIDE ? SQ_F1 : SQ_D1);
307307

308308
castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
309-
& ~(square_bb(kfrom) | rfrom);
309+
& ~(kfrom | rfrom);
310310
}
311311

312312

src/position.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ inline bool Position::can_castle(CastlingRights cr) const {
269269
}
270270

271271
inline int Position::castling_rights(Color c) const {
272-
return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
272+
return c & CastlingRights(st->castlingRights);
273273
}
274274

275275
inline bool Position::castling_impeded(CastlingRights cr) const {

src/search.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ namespace {
6161
// Different node types, used as a template parameter
6262
enum NodeType { NonPV, PV };
6363

64-
constexpr uint64_t ttHitAverageWindow = 4096;
65-
constexpr uint64_t ttHitAverageResolution = 1024;
64+
constexpr uint64_t TtHitAverageWindow = 4096;
65+
constexpr uint64_t TtHitAverageResolution = 1024;
6666

6767
// Razor and futility margins
6868
constexpr int RazorMargin = 531;
@@ -378,7 +378,7 @@ void Thread::search() {
378378
multiPV = std::max(multiPV, (size_t)4);
379379

380380
multiPV = std::min(multiPV, rootMoves.size());
381-
ttHitAverage = ttHitAverageWindow * ttHitAverageResolution / 2;
381+
ttHitAverage = TtHitAverageWindow * TtHitAverageResolution / 2;
382382

383383
int ct = int(Options["Contempt"]) * PawnValueEg / 100; // From centipawns
384384

@@ -702,8 +702,8 @@ namespace {
702702
thisThread->lowPlyHistory[ss->ply - 1][from_to((ss-1)->currentMove)] << stat_bonus(depth - 5);
703703

704704
// thisThread->ttHitAverage can be used to approximate the running average of ttHit
705-
thisThread->ttHitAverage = (ttHitAverageWindow - 1) * thisThread->ttHitAverage / ttHitAverageWindow
706-
+ ttHitAverageResolution * ttHit;
705+
thisThread->ttHitAverage = (TtHitAverageWindow - 1) * thisThread->ttHitAverage / TtHitAverageWindow
706+
+ TtHitAverageResolution * ttHit;
707707

708708
// At non-PV nodes we check for an early TT cutoff
709709
if ( !PvNode
@@ -1170,12 +1170,12 @@ namespace {
11701170
|| moveCountPruning
11711171
|| ss->staticEval + PieceValue[EG][pos.captured_piece()] <= alpha
11721172
|| cutNode
1173-
|| thisThread->ttHitAverage < 375 * ttHitAverageResolution * ttHitAverageWindow / 1024))
1173+
|| thisThread->ttHitAverage < 375 * TtHitAverageResolution * TtHitAverageWindow / 1024))
11741174
{
11751175
Depth r = reduction(improving, depth, moveCount);
11761176

11771177
// Decrease reduction if the ttHit running average is large
1178-
if (thisThread->ttHitAverage > 500 * ttHitAverageResolution * ttHitAverageWindow / 1024)
1178+
if (thisThread->ttHitAverage > 500 * TtHitAverageResolution * TtHitAverageWindow / 1024)
11791179
r--;
11801180

11811181
// Reduction if other threads are searching this position.

0 commit comments

Comments
 (0)