Skip to content

Commit

Permalink
Increase king safety score in case of opposite castling
Browse files Browse the repository at this point in the history
  • Loading branch information
snicolet committed Apr 20, 2017
1 parent 57a3334 commit fa55770
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ namespace {
}

// King tropism: firstly, find squares that opponent attacks in our king flank
File kf = file_of(ksq);
b = ei.attackedBy[Them][ALL_PIECES] & KingFlank[kf] & Camp;
Bitboard kingFlank = KingFlank[file_of(ksq)];
b = ei.attackedBy[Them][ALL_PIECES] & kingFlank & Camp;

assert(((Us == WHITE ? b << 4 : b >> 4) & b) == 0);
assert(popcount(Us == WHITE ? b << 4 : b >> 4) == popcount(b));
Expand All @@ -494,8 +494,13 @@ namespace {

score -= CloseEnemies * popcount(b);

// Increase king safety score in case of opposite castling
int d = distance<File>(ksq, pos.square<KING>(Them));
if (d)
score += make_score(mg_value(score) * d / 8, 0);

// Penalty when our king is on a pawnless flank
if (!(pos.pieces(PAWN) & KingFlank[kf]))
if (!(pos.pieces(PAWN) & kingFlank))
score -= PawnlessFlank;

if (DoTrace)
Expand Down

2 comments on commit fa55770

@locutus2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some oddities in your patch:

  1. if the kings are on the same file full king safety is applied, but if one king step a square aside the king safety is only 1/8. that is a big discontinuity.
  2. the maximum possible distance could be 7. So you always reduce king safety expect for distance zero.
  3. you zero the endgame value from the king safety calculation in pawns.cpp

@locutus2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I have overseen the += operator.

Please sign in to comment.