Skip to content

Commit

Permalink
Change definition of "weak" in threats calculation
Browse files Browse the repository at this point in the history
By defining "strongly protected" as "protected by a pawn, or protected
by two pieces and not attacked by two enemy pieces".

Passed STC:
LLR: 2.97 (-2.94,2.94) [0.00,5.00]
Total: 17050 W: 3128 L: 2931 D: 10991

Passed LTC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 120995 W: 15852 L: 15343 D: 89800

Bench : 6269229

Closes official-stockfish#1016
  • Loading branch information
snicolet authored and zamar committed Feb 26, 2017
1 parent f1e3dfe commit 8f7e032
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ namespace {
S(-20,-12), S( 1, -8), S( 2, 10), S( 9, 10)
};

// Protector[PieceType][distance] contains a protecting bonus for our king,
// Protector[PieceType][distance] contains a protecting bonus for our king,
// indexed by piece type and distance between the piece and the king.
const Score Protector[PIECE_TYPE_NB][8] = {
{}, {},
{}, {},
{ S(0, 0), S( 7, 9), S( 7, 1), S( 1, 5), S(-10,-4), S( -1,-4), S( -7,-3), S(-16,-10) }, // Knight
{ S(0, 0), S(11, 8), S(-7,-1), S(-1,-2), S( -1,-7), S(-11,-3), S( -9,-1), S(-16, -1) }, // Bishop
{ S(0, 0), S(10, 0), S(-2, 2), S(-5, 4), S( -6, 2), S(-14,-3), S( -2,-9), S(-12, -7) }, // Rook
Expand Down Expand Up @@ -525,7 +525,7 @@ namespace {
const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB);
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);

Bitboard b, weak, defended, safeThreats;
Bitboard b, weak, defended, stronglyProtected, safeThreats;
Score score = SCORE_ZERO;

// Non-pawn enemies attacked by a pawn
Expand All @@ -545,12 +545,18 @@ namespace {
score += ThreatBySafePawn[type_of(pos.piece_on(pop_lsb(&safeThreats)))];
}

// Non-pawn enemies defended by a pawn
defended = (pos.pieces(Them) ^ pos.pieces(Them, PAWN)) & ei.attackedBy[Them][PAWN];
// Squares strongly protected by the opponent, either because they attack the
// square with a pawn, or because they attack the square twice and we don't.
stronglyProtected = ei.attackedBy[Them][PAWN]
| (ei.attackedBy2[Them] & ~ei.attackedBy2[Us]);

// Non-pawn enemies, strongly protected
defended = (pos.pieces(Them) ^ pos.pieces(Them, PAWN))
& stronglyProtected;

// Enemies not defended by a pawn and under our attack
// Enemies not strongly protected and under our attack
weak = pos.pieces(Them)
& ~ei.attackedBy[Them][PAWN]
& ~stronglyProtected
& ei.attackedBy[Us][ALL_PIECES];

// Add a bonus according to the kind of attacking pieces
Expand Down Expand Up @@ -675,8 +681,8 @@ namespace {
mbonus += rr + r * 2, ebonus += rr + r * 2;
} // rr != 0

// Scale down bonus for candidate passers which need more than one pawn
// push to become passed.
// Scale down bonus for candidate passers which need more than one
// pawn push to become passed.
if (!pos.pawn_passed(Us, s + pawn_push(Us)))
mbonus /= 2, ebonus /= 2;

Expand All @@ -686,7 +692,6 @@ namespace {
if (DoTrace)
Trace::add(PASSED, Us, score);

// Add the scores to the middlegame and endgame eval
return score;
}

Expand Down

0 comments on commit 8f7e032

Please sign in to comment.