@@ -159,15 +159,18 @@ namespace {
159
159
S (0 , 0 ), S (0 , 0 ), S (176 , 139 ), S (131 , 127 ), S (217 , 218 ), S (203 , 215 )
160
160
};
161
161
162
- // Threat[by minor/by rook][attacked PieceType] contains
163
- // bonuses according to which piece type attacks which one.
164
- // Attacks on lesser pieces which are pawn-defended are not considered.
165
- const Score Threat[][PIECE_TYPE_NB] = {
166
- { S (0 , 0 ), S (0 , 33 ), S (45 , 43 ), S (46 , 47 ), S (72 ,107 ), S (48 ,118 ) }, // by Minor
167
- { S (0 , 0 ), S (0 , 25 ), S (40 , 62 ), S (40 , 59 ), S ( 0 , 34 ), S (35 , 48 ) } // by Rook
162
+ // ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
163
+ // which piece type attacks which one. Attacks on lesser pieces which are
164
+ // pawn-defended are not considered.
165
+ const Score ThreatByMinor[PIECE_TYPE_NB] = {
166
+ S (0 , 0 ), S (0 , 33 ), S (45 , 43 ), S (46 , 47 ), S (72 , 107 ), S (48 , 118 )
168
167
};
169
168
170
- // ThreatByKing[on one/on many] contains bonuses for King attacks on
169
+ const Score ThreatByRook[PIECE_TYPE_NB] = {
170
+ S (0 , 0 ), S (0 , 25 ), S (40 , 62 ), S (40 , 59 ), S ( 0 , 34 ), S (35 , 48 )
171
+ };
172
+
173
+ // ThreatByKing[on one/on many] contains bonuses for king attacks on
171
174
// pawns or pieces which are not pawn-defended.
172
175
const Score ThreatByKing[2 ] = { S (3 , 62 ), S (9 , 138 ) };
173
176
@@ -181,24 +184,24 @@ namespace {
181
184
// PassedFile[File] contains a bonus according to the file of a passed pawn
182
185
const Score PassedFile[FILE_NB] = {
183
186
S ( 9 , 10 ), S ( 2 , 10 ), S ( 1 , -8 ), S (-20 ,-12 ),
184
- S (-20 ,-12 ), S ( 1 , -8 ), S ( 2 , 10 ), S ( 9 , 10 )
187
+ S (-20 ,-12 ), S ( 1 , -8 ), S ( 2 , 10 ), S ( 9 , 10 )
185
188
};
186
189
187
190
// Assorted bonuses and penalties used by evaluation
188
191
const Score MinorBehindPawn = S(16 , 0 );
189
192
const Score BishopPawns = S( 8 , 12 );
190
193
const Score RookOnPawn = S( 8 , 24 );
191
194
const Score TrappedRook = S(92 , 0 );
192
- const Score CloseEnemies = S( 7 , 0 );
195
+ const Score WeakQueen = S(50 , 10 );
193
196
const Score OtherCheck = S(10 , 10 );
194
- const Score ThreatByHangingPawn = S(71 , 61 );
197
+ const Score CloseEnemies = S( 7 , 0 );
198
+ const Score PawnlessFlank = S(20 , 80 );
195
199
const Score LooseEnemies = S( 0 , 25 );
196
- const Score WeakQueen = S(50 , 10 );
200
+ const Score ThreatByHangingPawn = S(71 , 61 );
201
+ const Score ThreatByRank = S(16 , 3 );
197
202
const Score Hanging = S(48 , 27 );
198
203
const Score ThreatByPawnPush = S(38 , 22 );
199
- const Score PawnlessFlank = S(20 , 80 );
200
204
const Score HinderPassedPawn = S( 7 , 0 );
201
- const Score ThreatByRank = S(16 , 3 );
202
205
203
206
// Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
204
207
// a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
@@ -238,8 +241,7 @@ namespace {
238
241
if (pos.non_pawn_material (Us) >= QueenValueMg)
239
242
{
240
243
ei.kingRing [Them] = b | shift<Down>(b);
241
- b &= ei.attackedBy [Us][PAWN];
242
- ei.kingAttackersCount [Us] = popcount (b);
244
+ ei.kingAttackersCount [Us] = popcount (b & ei.attackedBy [Us][PAWN]);
243
245
ei.kingAdjacentZoneAttacksCount [Us] = ei.kingAttackersWeight [Us] = 0 ;
244
246
}
245
247
else
@@ -253,16 +255,16 @@ namespace {
253
255
template <bool DoTrace, Color Us = WHITE, PieceType Pt = KNIGHT>
254
256
Score evaluate_pieces (const Position& pos, EvalInfo& ei, Score* mobility,
255
257
const Bitboard* mobilityArea) {
256
- Bitboard b, bb;
257
- Square s;
258
- Score score = SCORE_ZERO;
259
-
260
258
const PieceType NextPt = (Us == WHITE ? Pt : PieceType (Pt + 1 ));
261
259
const Color Them = (Us == WHITE ? BLACK : WHITE);
262
260
const Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
263
261
: Rank5BB | Rank4BB | Rank3BB);
264
262
const Square* pl = pos.squares <Pt>(Us);
265
263
264
+ Bitboard b, bb;
265
+ Square s;
266
+ Score score = SCORE_ZERO;
267
+
266
268
ei.attackedBy [Us][Pt] = 0 ;
267
269
268
270
while ((s = *pl++) != SQ_NONE)
@@ -376,28 +378,24 @@ namespace {
376
378
377
379
// evaluate_king() assigns bonuses and penalties to a king of a given color
378
380
379
- const Bitboard WhiteCamp = Rank1BB | Rank2BB | Rank3BB | Rank4BB | Rank5BB;
380
- const Bitboard BlackCamp = Rank8BB | Rank7BB | Rank6BB | Rank5BB | Rank4BB;
381
- const Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
382
381
const Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
383
- const Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
384
382
385
- const Bitboard KingFlank[COLOR_NB][FILE_NB] = {
386
- { QueenSide & WhiteCamp, QueenSide & WhiteCamp, QueenSide & WhiteCamp, CenterFiles & WhiteCamp,
387
- CenterFiles & WhiteCamp, KingSide & WhiteCamp, KingSide & WhiteCamp, KingSide & WhiteCamp },
388
- { QueenSide & BlackCamp, QueenSide & BlackCamp, QueenSide & BlackCamp, CenterFiles & BlackCamp,
389
- CenterFiles & BlackCamp, KingSide & BlackCamp, KingSide & BlackCamp, KingSide & BlackCamp },
383
+ const Bitboard KingFlank[FILE_NB] = {
384
+ CenterFiles >> 2 , CenterFiles >> 2 , CenterFiles >> 2 , CenterFiles, CenterFiles,
385
+ CenterFiles << 2 , CenterFiles << 2 , CenterFiles << 2
390
386
};
391
387
392
388
template <Color Us, bool DoTrace>
393
389
Score evaluate_king (const Position& pos, const EvalInfo& ei) {
394
390
395
- const Color Them = (Us == WHITE ? BLACK : WHITE);
396
- const Square Up = (Us == WHITE ? NORTH : SOUTH);
391
+ const Color Them = (Us == WHITE ? BLACK : WHITE);
392
+ const Square Up = (Us == WHITE ? NORTH : SOUTH);
393
+ const Bitboard Camp = (Us == WHITE ? ~Bitboard (0 ) ^ Rank6BB ^ Rank7BB ^ Rank8BB
394
+ : ~Bitboard (0 ) ^ Rank1BB ^ Rank2BB ^ Rank3BB);
397
395
396
+ const Square ksq = pos.square <KING>(Us);
398
397
Bitboard undefended, b, b1, b2, safe, other;
399
398
int kingDanger;
400
- const Square ksq = pos.square <KING>(Us);
401
399
402
400
// King shelter and enemy pawns storm
403
401
Score score = ei.pi ->king_safety <Us>(pos, ksq);
@@ -483,7 +481,7 @@ namespace {
483
481
484
482
// King tropism: firstly, find squares that opponent attacks in our king flank
485
483
File kf = file_of (ksq);
486
- b = ei.attackedBy [Them][ALL_PIECES] & KingFlank[Us][ kf];
484
+ b = ei.attackedBy [Them][ALL_PIECES] & KingFlank[kf] & Camp ;
487
485
488
486
assert (((Us == WHITE ? b << 4 : b >> 4 ) & b) == 0 );
489
487
assert (popcount (Us == WHITE ? b << 4 : b >> 4 ) == popcount (b));
@@ -496,7 +494,7 @@ namespace {
496
494
score -= CloseEnemies * popcount (b);
497
495
498
496
// Penalty when our king is on a pawnless flank
499
- if (!(pos.pieces (PAWN) & ( KingFlank[WHITE][ kf] | KingFlank[BLACK][kf]) ))
497
+ if (!(pos.pieces (PAWN) & KingFlank[kf]))
500
498
score -= PawnlessFlank;
501
499
502
500
if (DoTrace)
@@ -519,8 +517,6 @@ namespace {
519
517
const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB);
520
518
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
521
519
522
- enum { Minor, Rook };
523
-
524
520
Bitboard b, weak, defended, safeThreats;
525
521
Score score = SCORE_ZERO;
526
522
@@ -561,7 +557,7 @@ namespace {
561
557
while (b)
562
558
{
563
559
Square s = pop_lsb (&b);
564
- score += Threat[Minor] [type_of (pos.piece_on (s))];
560
+ score += ThreatByMinor [type_of (pos.piece_on (s))];
565
561
if (type_of (pos.piece_on (s)) != PAWN)
566
562
score += ThreatByRank * (int )relative_rank (Them, s);
567
563
}
@@ -570,7 +566,7 @@ namespace {
570
566
while (b)
571
567
{
572
568
Square s = pop_lsb (&b);
573
- score += Threat[Rook] [type_of (pos.piece_on (s))];
569
+ score += ThreatByRook [type_of (pos.piece_on (s))];
574
570
if (type_of (pos.piece_on (s)) != PAWN)
575
571
score += ThreatByRank * (int )relative_rank (Them, s);
576
572
}
@@ -702,8 +698,8 @@ namespace {
702
698
703
699
const Color Them = (Us == WHITE ? BLACK : WHITE);
704
700
const Bitboard SpaceMask =
705
- Us == WHITE ? (FileCBB | FileDBB | FileEBB | FileFBB) & (Rank2BB | Rank3BB | Rank4BB)
706
- : (FileCBB | FileDBB | FileEBB | FileFBB) & (Rank7BB | Rank6BB | Rank5BB);
701
+ Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB)
702
+ : CenterFiles & (Rank7BB | Rank6BB | Rank5BB);
707
703
708
704
// Find the safe squares for our pieces inside the area defined by
709
705
// SpaceMask. A square is unsafe if it is attacked by an enemy
0 commit comments