Skip to content

Commit

Permalink
Other check mod
Browse files Browse the repository at this point in the history
Bench: 6227893
  • Loading branch information
jhellis3 committed Jun 15, 2017
1 parent 659990b commit 140476f
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/evaluate.cpp
Expand Up @@ -393,12 +393,11 @@ namespace {
Score evaluate_king(const Position& pos, const EvalInfo& ei) {

const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? NORTH : SOUTH);
const Bitboard Camp = (Us == WHITE ? ~Bitboard(0) ^ Rank6BB ^ Rank7BB ^ Rank8BB
: ~Bitboard(0) ^ Rank1BB ^ Rank2BB ^ Rank3BB);

const Square ksq = pos.square<KING>(Us);
Bitboard undefended, b, b1, b2, safe, other;
Bitboard undefended, b, b1, b2, safe, other, otherThreats;
int kingDanger;

// King shelter and enemy pawns storm
Expand Down Expand Up @@ -449,30 +448,21 @@ namespace {
// Some other potential checks are also analysed, even from squares
// currently occupied by the opponent own pieces, as long as the square
// is not attacked by our pawns, and is not occupied by a blocked pawn.
other = ~( ei.attackedBy[Us][PAWN]
| (pos.pieces(Them, PAWN) & shift<Up>(pos.pieces(PAWN))));
other = ~(ei.attackedBy[Us][PAWN] | pos.pieces(Them, ALL_PIECES));

// Enemy rooks safe and other checks
if (b1 & ei.attackedBy[Them][ROOK] & safe)
kingDanger += RookCheck;

else if (b1 & ei.attackedBy[Them][ROOK] & other)
score -= OtherCheck;
b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT];

// Enemy bishops safe and other checks
if (b2 & ei.attackedBy[Them][BISHOP] & safe)
kingDanger += BishopCheck;
bool rcb = b1 & ei.attackedBy[Them][ROOK] & safe;
bool bcb = b2 & ei.attackedBy[Them][BISHOP] & safe;
bool kcb = b & safe;

else if (b2 & ei.attackedBy[Them][BISHOP] & other)
score -= OtherCheck;
kingDanger += rcb * RookCheck;
kingDanger += bcb * BishopCheck;
kingDanger += kcb * KnightCheck;

// Enemy knights safe and other checks
b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT];
if (b & safe)
kingDanger += KnightCheck;
otherThreats = (b1 & ei.attackedBy[Them][ROOK]) | (b2 & ei.attackedBy[Them][BISHOP]) | b;

else if (b & other)
score -= OtherCheck;
score -= OtherCheck * popcount(otherThreats & other);

// Transform the kingDanger units into a Score, and substract it from the evaluation
if (kingDanger > 0)
Expand Down

2 comments on commit 140476f

@ElbertoOne
Copy link

Choose a reason for hiding this comment

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

To me it looks that [0,4] bounds are more appropriate here. Anyway, looks good! Good luck.

@MichaelB7
Copy link

Choose a reason for hiding this comment

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

Good luck Joe!

Please sign in to comment.