Skip to content

Commit 4ae5a7b

Browse files
mcostalbasnicolet
authored andcommitted
Assorted trivial cleanups June 2019
No functional change.
1 parent c83cbe4 commit 4ae5a7b

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

src/evaluate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ namespace {
142142
constexpr Score KnightOnQueen = S( 16, 12);
143143
constexpr Score LongDiagonalBishop = S( 45, 0);
144144
constexpr Score MinorBehindPawn = S( 18, 3);
145-
constexpr Score Outpost = S( 36, 12);
145+
constexpr Score Outpost = S( 18, 6);
146146
constexpr Score PawnlessFlank = S( 17, 95);
147147
constexpr Score RestrictedPiece = S( 7, 7);
148148
constexpr Score RookOnPawn = S( 10, 32);
@@ -222,7 +222,7 @@ namespace {
222222
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
223223
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
224224
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
225-
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
225+
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB : Rank7BB | Rank6BB);
226226

227227
const Square ksq = pos.square<KING>(Us);
228228

@@ -305,10 +305,10 @@ namespace {
305305
// Bonus if piece is on an outpost square or can reach one
306306
bb = OutpostRanks & attackedBy[Us][PAWN] & ~pe->pawn_attacks_span(Them);
307307
if (bb & s)
308-
score += Outpost * (Pt == KNIGHT ? 2 : 1);
308+
score += Outpost * (Pt == KNIGHT ? 4 : 2);
309309

310310
else if (bb & b & ~pos.pieces(Us))
311-
score += Outpost / (Pt == KNIGHT ? 1 : 2);
311+
score += Outpost * (Pt == KNIGHT ? 2 : 1);
312312

313313
// Knight and Bishop bonus for being right behind a pawn
314314
if (shift<Down>(pos.pieces(PAWN)) & s)
@@ -561,7 +561,7 @@ namespace {
561561
b &= ~attackedBy[Them][PAWN] & safe;
562562

563563
// Bonus for safe pawn threats on the next move
564-
b = pawn_attacks_bb<Us>(b) & pos.pieces(Them);
564+
b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
565565
score += ThreatByPawnPush * popcount(b);
566566

567567
// Our safe or protected pawns

src/pawns.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ namespace {
3232
#define S(mg, eg) make_score(mg, eg)
3333

3434
// Pawn penalties
35-
constexpr Score Backward = S( 9, 24);
36-
constexpr Score Doubled = S(11, 56);
37-
constexpr Score Isolated = S( 5, 15);
35+
constexpr Score Backward = S( 9, 24);
36+
constexpr Score Doubled = S(11, 56);
37+
constexpr Score Isolated = S( 5, 15);
3838
constexpr Score WeakUnopposed = S( 13, 27);
3939
constexpr Score Attacked2Unsupported = S( 0, 20);
4040

@@ -108,17 +108,18 @@ namespace {
108108
phalanx = neighbours & rank_bb(s);
109109
support = neighbours & rank_bb(s - Up);
110110

111-
// A pawn is backward when it is behind all pawns of the same color
112-
// on the adjacent files and cannot be safely advanced.
113-
backward = !(ourPawns & pawn_attack_span(Them, s + Up))
111+
// A pawn is backward when it is behind all pawns of the same color on
112+
// the adjacent files and cannot safely advance. Phalanx and isolated
113+
// pawns will be excluded when the pawn is scored.
114+
backward = !(neighbours & forward_ranks_bb(Them, s))
114115
&& (stoppers & (leverPush | (s + Up)));
115116

116117
// Passed pawns will be properly scored in evaluation because we need
117118
// full attack info to evaluate them. Include also not passed pawns
118119
// which could become passed after one or two pawn pushes when are
119120
// not attacked more times than defended.
120-
if ( !(stoppers ^ lever) ||
121-
(!(stoppers ^ leverPush) && popcount(phalanx) >= popcount(leverPush)))
121+
if ( !(stoppers ^ lever) ||
122+
(!(stoppers ^ leverPush) && popcount(phalanx) >= popcount(leverPush)))
122123
e->passedPawns[Us] |= s;
123124

124125
else if (stoppers == square_bb(s + Up) && r >= RANK_5)
@@ -137,6 +138,7 @@ namespace {
137138

138139
score += make_score(v, v * (r - 2) / 4);
139140
}
141+
140142
else if (!neighbours)
141143
score -= Isolated + WeakUnopposed * int(!opposed);
142144

src/position.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING
5555
// valuable attacker for the side to move, remove the attacker we just found
5656
// from the bitboards and scan for new X-ray attacks behind it.
5757

58-
template<int Pt>
58+
template<PieceType Pt>
5959
PieceType min_attacker(const Bitboard* byTypeBB, Square to, Bitboard stmAttackers,
6060
Bitboard& occupied, Bitboard& attackers) {
6161

6262
Bitboard b = stmAttackers & byTypeBB[Pt];
6363
if (!b)
64-
return min_attacker<Pt + 1>(byTypeBB, to, stmAttackers, occupied, attackers);
64+
return min_attacker<PieceType(Pt + 1)>(byTypeBB, to, stmAttackers, occupied, attackers);
6565

6666
occupied ^= lsb(b); // Remove the attacker from occupied
6767

@@ -77,7 +77,7 @@ PieceType min_attacker(const Bitboard* byTypeBB, Square to, Bitboard stmAttacker
7777
// X-ray may add already processed pieces because byTypeBB[] is constant: in
7878
// the rook example, now attackers contains _again_ rook in a7, so remove it.
7979
attackers &= occupied;
80-
return (PieceType)Pt;
80+
return Pt;
8181
}
8282

8383
template<>

src/position.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Position {
108108
Bitboard checkers() const;
109109
Bitboard blockers_for_king(Color c) const;
110110
Bitboard check_squares(PieceType pt) const;
111+
bool is_discovery_check_on_king(Color c, Move m) const;
111112

112113
// Attacks to/from a given square
113114
Bitboard attackers_to(Square s) const;
@@ -316,6 +317,10 @@ inline Bitboard Position::check_squares(PieceType pt) const {
316317
return st->checkSquares[pt];
317318
}
318319

320+
inline bool Position::is_discovery_check_on_king(Color c, Move m) const {
321+
return st->blockersForKing[c] & from_sq(m);
322+
}
323+
319324
inline bool Position::pawn_passed(Color c, Square s) const {
320325
return !(pieces(~c, PAWN) & passed_pawn_span(c, s));
321326
}

src/search.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ namespace {
739739
}
740740
else if (ttHit)
741741
{
742-
// Never assume anything on values stored in TT
742+
// Never assume anything about values stored in TT
743743
ss->staticEval = eval = tte->eval();
744744
if (eval == VALUE_NONE)
745745
ss->staticEval = eval = evaluate(pos);
@@ -978,7 +978,7 @@ namespace {
978978

979979
// Check extension (~2 Elo)
980980
else if ( givesCheck
981-
&& (pos.blockers_for_king(~us) & from_sq(move) || pos.see_ge(move)))
981+
&& (pos.is_discovery_check_on_king(~us, move) || pos.see_ge(move)))
982982
extension = ONE_PLY;
983983

984984
// Castling extension
@@ -1013,7 +1013,7 @@ namespace {
10131013
&& !givesCheck
10141014
&& (!pos.advanced_pawn_push(move) || pos.non_pawn_material(~us) > BishopValueMg))
10151015
{
1016-
// Move count based pruning (~30 Elo)
1016+
// Move count based pruning
10171017
if (moveCountPruning)
10181018
continue;
10191019

@@ -1037,8 +1037,8 @@ namespace {
10371037
if (!pos.see_ge(move, Value(-29 * lmrDepth * lmrDepth)))
10381038
continue;
10391039
}
1040-
else if ((!givesCheck || !extension)
1041-
&& !pos.see_ge(move, -PawnValueEg * (depth / ONE_PLY))) // (~20 Elo)
1040+
else if ( (!givesCheck || !extension)
1041+
&& !pos.see_ge(move, -PawnValueEg * (depth / ONE_PLY))) // (~20 Elo)
10421042
continue;
10431043
}
10441044

@@ -1341,7 +1341,7 @@ namespace {
13411341
{
13421342
if (ttHit)
13431343
{
1344-
// Never assume anything on values stored in TT
1344+
// Never assume anything about values stored in TT
13451345
if ((ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
13461346
ss->staticEval = bestValue = evaluate(pos);
13471347

0 commit comments

Comments
 (0)