Skip to content

Commit

Permalink
Updated to "Limit the king distance factor when evaluating passed paw…
Browse files Browse the repository at this point in the history
  • Loading branch information
syzygy1 committed Jan 28, 2018
1 parent 5470c0e commit 1f81fe3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ static const Score ThreatByKing[2] = { S(3, 62), S(9, 138) };
// Passed[mg/eg][Rank] contains midgame and endgame bonuses for passed pawns.
// We don't use a Score because we process the two components independently.
static const Value Passed[][8] = {
{ V(5), V( 5), V(31), V(73), V(166), V(252) },
{ V(7), V(14), V(38), V(73), V(166), V(252) }
{ V(0), V(5), V( 5), V(31), V(73), V(166), V(252) },
{ V(0), V(7), V(14), V(38), V(73), V(166), V(252) }
};

// PassedFile[File] contains a bonus according to the file of a passed pawn
Expand All @@ -144,6 +144,9 @@ static const Score PassedFile[8] = {
S(-20,-12), S( 1, -8), S( 2, 10), S( 9, 10)
};

// Rank-dependent factor for a passed-pawn bonus
const int RankFactor[8] = { 0, 0, 0, 2, 6, 11, 16 };

// KingProtector[PieceType-2] contains a bonus according to distance from king
const Score KingProtector[] = { S(-3, -5), S(-4, -3), S(-3, 0), S(-1, 1) };

Expand Down Expand Up @@ -565,6 +568,12 @@ INLINE Score evaluate_threats(const Pos *pos, EvalInfo *ei, const int Us)
}


// Helper function
INLINE int capped_distance(Square s1, Square s2)
{
return min(distance(s1, s2), 5);
}

// evaluate_passed_pawns() evaluates the passed pawns and candidate passed
// pawns of the given color.

Expand All @@ -586,21 +595,21 @@ INLINE Score evaluate_passed_pawns(const Pos *pos, EvalInfo *ei, const int Us)
bb = forward_file_bb(Us, s) & (ei->attackedBy[Them][0] | pieces_c(Them));
score -= HinderPassedPawn * popcount(bb);

int r = relative_rank_s(Us, s) - RANK_2;
int rr = r * (r - 1);
int r = relative_rank_s(Us, s);
int rr = RankFactor[r];

Value mbonus = Passed[MG][r], ebonus = Passed[EG][r];

if (rr) {
Square blockSq = s + Up;

// Adjust bonus based on the king's proximity
ebonus += distance(square_of(Them, KING), blockSq) * 5 * rr
- distance(square_of(Us, KING), blockSq) * 2 * rr;
ebonus += capped_distance(square_of(Them, KING), blockSq) * 5 * rr
- capped_distance(square_of(Us, KING), blockSq) * 2 *rr;

// If blockSq is not the queening square then consider also a second push
if (relative_rank_s(Us, blockSq) != RANK_8)
ebonus -= distance(square_of(Us, KING), blockSq + Up) * rr;
if (r != RANK_7)
ebonus -= capped_distance(square_of(Us, KING), blockSq + Up) * rr;

// If the pawn is free to advance, then increase the bonus
if (is_empty(blockSq)) {
Expand Down

0 comments on commit 1f81fe3

Please sign in to comment.