Skip to content

Commit f84f047

Browse files
committed
Skip a couple of popcount in previous patch
And some little tidy up No functional change.
1 parent cc40d1c commit f84f047

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/bitboard.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
6363
extern Bitboard AttackSpanMask[COLOR_NB][SQUARE_NB];
6464
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
6565

66-
const Bitboard WhiteSquares = 0x55AA55AA55AA55AAULL;
6766
const Bitboard BlackSquares = 0xAA55AA55AA55AA55ULL;
6867

6968
/// Overloads of bitwise operators between a Bitboard and a Square for testing
@@ -201,8 +200,7 @@ inline bool squares_aligned(Square s1, Square s2, Square s3) {
201200
/// the same color of the given square.
202201

203202
inline Bitboard same_color_squares(Square s) {
204-
return Bitboard(0xAA55AA55AA55AA55ULL) & s ? 0xAA55AA55AA55AA55ULL
205-
: ~0xAA55AA55AA55AA55ULL;
203+
return BlackSquares & s ? BlackSquares : ~BlackSquares;
206204
}
207205

208206

src/evaluate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ namespace {
171171
// right to castle.
172172
const Value TrappedRookPenalty = Value(180);
173173

174+
// Penalty for bishop with pawns on the same coloured squares
175+
const Score BishopPawnsPenalty = make_score(8, 12);
176+
174177
// Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
175178
// a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
176179
// happen in Chess960 games.
@@ -584,7 +587,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
584587

585588
// Penalty for bishop with same coloured pawns
586589
if (Piece == BISHOP)
587-
score -= make_score(8, 12) * ei.pi->same_colored_pawn_count(s, Us);
590+
score -= BishopPawnsPenalty * ei.pi->pawns_on_same_color_squares(Us, s);
588591

589592
// Bishop and knight outposts squares
590593
if ( (Piece == BISHOP || Piece == KNIGHT)

src/pawns.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ namespace {
176176
value += CandidateBonus[relative_rank(Us, s)];
177177
}
178178

179-
e->pawnsOnWhiteSquaresCount[Us] = popcount<Max15>(ourPawns & WhiteSquares);
180-
e->pawnsOnWhiteSquaresCount[Them] = popcount<Max15>(theirPawns & WhiteSquares);
179+
e->pawnsOnSquares[Us][BLACK] = popcount<Max15>(ourPawns & BlackSquares);
180+
e->pawnsOnSquares[Us][WHITE] = pos.piece_count(Us, PAWN) - e->pawnsOnSquares[Us][BLACK];
181181

182-
e->pawnsOnBlackSquaresCount[Us] = popcount<Max15>(ourPawns & BlackSquares);
183-
e->pawnsOnBlackSquaresCount[Them] = popcount<Max15>(theirPawns & BlackSquares);
182+
e->pawnsOnSquares[Them][BLACK] = popcount<Max15>(theirPawns & BlackSquares);
183+
e->pawnsOnSquares[Them][WHITE] = pos.piece_count(Them, PAWN) - e->pawnsOnSquares[Them][BLACK];
184184

185185
return value;
186186
}

src/pawns.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct Entry {
4040
int file_is_half_open(Color c, File f) const { return halfOpenFiles[c] & (1 << int(f)); }
4141
int has_open_file_to_left(Color c, File f) const { return halfOpenFiles[c] & ((1 << int(f)) - 1); }
4242
int has_open_file_to_right(Color c, File f) const { return halfOpenFiles[c] & ~((1 << int(f+1)) - 1); }
43-
int same_colored_pawn_count(Square s, Color c) const { return (BlackSquares & s) ? pawnsOnBlackSquaresCount[c] : pawnsOnWhiteSquaresCount[c]; }
43+
int pawns_on_same_color_squares(Color c, Square s) const { return pawnsOnSquares[c][!!(BlackSquares & s)]; }
4444

4545
template<Color Us>
4646
Score king_safety(const Position& pos, Square ksq) {
@@ -64,8 +64,7 @@ struct Entry {
6464
Score value;
6565
int halfOpenFiles[COLOR_NB];
6666
Score kingSafety[COLOR_NB];
67-
int pawnsOnWhiteSquaresCount[COLOR_NB];
68-
int pawnsOnBlackSquaresCount[COLOR_NB];
67+
int pawnsOnSquares[COLOR_NB][COLOR_NB];
6968
};
7069

7170
typedef HashTable<Entry, 16384> Table;

0 commit comments

Comments
 (0)