Skip to content

Commit dba097c

Browse files
Rocky640IIvec
authored andcommitted
Undefended King Ring
There was already a penalty for squares only defended by King (undefended) This test records a penalty for completely undefended squares in the so called extended king-ring (so if we exclude squares defended by a Kg8 for example, we only look at h6 g6 and f6) We also exclude squares occupied by opponent pieces in this computation, based on the following results Was yellow at STC LLR: -2.97 (-2.94,2.94) [0.00,5.00] Total: 112499 W: 20649 L: 20293 D: 71557 and passed LTC LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 36805 W: 5100 L: 4857 D: 26848 Bench: 8430233 Resolves: #619
1 parent 970328d commit dba097c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/evaluate.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,17 @@ namespace {
384384
// Main king safety evaluation
385385
if (ei.kingAttackersCount[Them])
386386
{
387-
// Find the attacked squares around the king which have no defenders
388-
// apart from the king itself.
387+
// Find the attacked squares which are defended only by the king...
389388
undefended = ei.attackedBy[Them][ALL_PIECES]
390389
& ei.attackedBy[Us][KING]
391390
& ~( ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT]
392391
| ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
393392
| ei.attackedBy[Us][QUEEN]);
394393

394+
// ... and those which are not defended at all in the larger king ring
395+
b = ei.attackedBy[Them][ALL_PIECES] & ~ei.attackedBy[Us][ALL_PIECES]
396+
& ei.kingRing[Us] & ~pos.pieces(Them);
397+
395398
// Initialize the 'attackUnits' variable, which is used later on as an
396399
// index into the KingDanger[] array. The initial value is based on the
397400
// number and types of the enemy's attacking pieces, the number of
@@ -400,7 +403,7 @@ namespace {
400403
attackUnits = std::min(72, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
401404
+ 9 * ei.kingAdjacentZoneAttacksCount[Them]
402405
+ 27 * popcount(undefended)
403-
+ 11 * !!ei.pinnedPieces[Us]
406+
+ 11 * (popcount(b) + !!ei.pinnedPieces[Us])
404407
- 64 * !pos.count<QUEEN>(Them)
405408
- mg_value(score) / 8;
406409

0 commit comments

Comments
 (0)