Skip to content

Commit

Permalink
Faster and simplified threat eval
Browse files Browse the repository at this point in the history
Add a bonus according if the attacking
pieces are minor or major.

Passed both short TC
LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 13142 W: 2625 L: 2483 D: 8034

And long TC
LLR: 2.95 (-2.94,2.94) [0.00,6.00]
Total: 18059 W: 3031 L: 2844 D: 12184

bench: 7425809
  • Loading branch information
glinscott authored and mcostalba committed Dec 19, 2013
1 parent f196c1b commit 26689d8
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ namespace {
// Threat[attacking][attacked] contains bonuses according to which piece
// type attacks which one.
const Score Threat[][PIECE_TYPE_NB] = {
{}, {},
{ S(0, 0), S( 7, 39), S( 0, 0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT
{ S(0, 0), S( 7, 39), S(24, 49), S( 0, 0), S(41,100), S(41,100) }, // BISHOP
{ S(0, 0), S( 0, 22), S(15, 49), S(15, 49), S( 0, 0), S(24, 49) }, // ROOK
{ S(0, 0), S(15, 39), S(15, 39), S(15, 39), S(15, 39), S( 0, 0) } // QUEEN
{ S(0, 0), S( 7, 39), S(24, 49), S(24, 49), S(41,100), S(41,100) }, // Minor
{ S(0, 0), S(15, 39), S(15, 45), S(15, 45), S(15, 45), S(24, 49) }, // Major
};

// ThreatenedByPawn[PieceType] contains a penalty according to which piece
Expand Down Expand Up @@ -762,18 +759,17 @@ Value do_evaluate(const Position& pos) {
& ~ei.attackedBy[Them][PAWN]
& ei.attackedBy[Us][ALL_PIECES];

// Add bonus according to type of attacked enemy piece and to the
// type of attacking piece, from knights to queens. Kings are not
// considered because they are already handled in king evaluation.
// Add a bonus according if the attacking pieces are minor or major
if (weakEnemies)
for (PieceType pt1 = KNIGHT; pt1 < KING; ++pt1)
{
b = ei.attackedBy[Us][pt1] & weakEnemies;
if (b)
for (PieceType pt2 = PAWN; pt2 < KING; ++pt2)
if (b & pos.pieces(pt2))
score += Threat[pt1][pt2];
}
{
b = weakEnemies & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]);
if (b)
score += Threat[0][type_of(pos.piece_on(lsb(b)))];

b = weakEnemies & (ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]);
if (b)
score += Threat[1][type_of(pos.piece_on(lsb(b)))];
}

if (Trace)
Tracing::scores[Us][THREAT] = score;
Expand Down

0 comments on commit 26689d8

Please sign in to comment.