Evaluate: rename king attack variables

A better naming IMHO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2008-09-24 20:20:08 +01:00
parent 34ca22486a
commit dfcfed6432
2 changed files with 27 additions and 26 deletions

View File

@@ -328,19 +328,19 @@ Value evaluate(const Position &pos, EvalInfo &ei, int threadID) {
// Initialize king attack bitboards and king attack zones for both sides: // Initialize king attack bitboards and king attack zones for both sides:
ei.attackedBy[WHITE][KING] = pos.king_attacks(pos.king_square(WHITE)); ei.attackedBy[WHITE][KING] = pos.king_attacks(pos.king_square(WHITE));
ei.attackedBy[BLACK][KING] = pos.king_attacks(pos.king_square(BLACK)); ei.attackedBy[BLACK][KING] = pos.king_attacks(pos.king_square(BLACK));
ei.attackZone[WHITE] = ei.kingZone[WHITE] =
ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8); ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8);
ei.attackZone[BLACK] = ei.kingZone[BLACK] =
ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8); ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8);
// Initialize pawn attack bitboards for both sides: // Initialize pawn attack bitboards for both sides:
ei.attackedBy[WHITE][PAWN] = ei.attackedBy[WHITE][PAWN] =
((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB); ((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB);
ei.attackCount[WHITE] += ei.kingAttackersCount[WHITE] +=
count_1s_max_15(ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING])/2; count_1s_max_15(ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING])/2;
ei.attackedBy[BLACK][PAWN] = ei.attackedBy[BLACK][PAWN] =
((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB); ((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB);
ei.attackCount[BLACK] += ei.kingAttackersCount[BLACK] +=
count_1s_max_15(ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING])/2; count_1s_max_15(ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING])/2;
// Evaluate pieces: // Evaluate pieces:
@@ -580,13 +580,13 @@ namespace {
Color them = opposite_color(us); Color them = opposite_color(us);
// King attack // King attack
if (b & ei.attackZone[us]) if (b & ei.kingZone[us])
{ {
ei.attackCount[us]++; ei.kingAttackersCount[us]++;
ei.attackWeight[us] += AttackWeight; ei.kingAttackersWeight[us] += AttackWeight;
Bitboard bb = (b & ei.attackedBy[them][KING]); Bitboard bb = (b & ei.attackedBy[them][KING]);
if (bb) if (bb)
ei.attacked[us] += count_1s_max_15(bb); ei.kingZoneAttacksCount[us] += count_1s_max_15(bb);
} }
// Mobility // Mobility
@@ -690,6 +690,7 @@ namespace {
return; return;
Square ksq = p.king_square(us); Square ksq = p.king_square(us);
if ( square_file(ksq) >= FILE_E if ( square_file(ksq) >= FILE_E
&& square_file(s) > square_file(ksq) && square_file(s) > square_file(ksq)
&& (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s))) && (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
@@ -754,9 +755,9 @@ namespace {
// King safety. This is quite complicated, and is almost certainly far // King safety. This is quite complicated, and is almost certainly far
// from optimally tuned. // from optimally tuned.
Color them = opposite_color(us); Color them = opposite_color(us);
if(p.queen_count(them) >= 1 && ei.attackCount[them] >= 2 if(p.queen_count(them) >= 1 && ei.kingAttackersCount[them] >= 2
&& p.non_pawn_material(them) >= QueenValueMidgame + RookValueMidgame && p.non_pawn_material(them) >= QueenValueMidgame + RookValueMidgame
&& ei.attacked[them]) { && ei.kingZoneAttacksCount[them]) {
// Is it the attackers turn to move? // Is it the attackers turn to move?
bool sente = (them == p.side_to_move()); bool sente = (them == p.side_to_move());
@@ -776,8 +777,8 @@ namespace {
// undefended squares around the king, the square of the king, and the // undefended squares around the king, the square of the king, and the
// quality of the pawn shelter. // quality of the pawn shelter.
int attackUnits = int attackUnits =
Min((ei.attackCount[them] * ei.attackWeight[them]) / 2, 25) Min((ei.kingAttackersCount[them] * ei.kingAttackersWeight[them]) / 2, 25)
+ (ei.attacked[them] + count_1s_max_15(undefended)) * 3 + (ei.kingZoneAttacksCount[them] + count_1s_max_15(undefended)) * 3
+ InitKingDanger[relative_square(us, s)] - shelter / 32; + InitKingDanger[relative_square(us, s)] - shelter / 32;
// Analyse safe queen contact checks: // Analyse safe queen contact checks:

View File

@@ -56,31 +56,31 @@ struct EvalInfo {
Bitboard attackedBy[2][8]; Bitboard attackedBy[2][8];
Bitboard attacked_by(Color c) const { return attackedBy[c][0]; } Bitboard attacked_by(Color c) const { return attackedBy[c][0]; }
Bitboard attacked_by(Color c, PieceType pt) const { return attackedBy[c][pt]; } Bitboard attacked_by(Color c, PieceType pt) const { return attackedBy[c][pt]; }
// attackZone[color] is the zone around the enemy king which is considered
// kingZone[color] is the zone around the enemy king which is considered
// by the king safety evaluation. This consists of the squares directly // by the king safety evaluation. This consists of the squares directly
// adjacent to the king, and the three (or two, for a king on an edge file) // adjacent to the king, and the three (or two, for a king on an edge file)
// squares two ranks in front of the king. For instance, if black's king // squares two ranks in front of the king. For instance, if black's king
// is on g8, attackZone[WHITE] is a bitboard containing the squares f8, h8, // is on g8, kingZone[WHITE] is a bitboard containing the squares f8, h8,
// f7, g7, h7, f6, g6 and h6. // f7, g7, h7, f6, g6 and h6.
Bitboard attackZone[2]; Bitboard kingZone[2];
// attackCount[color] is the number of pieces of the given color which // kingAttackersCount[color] is the number of pieces of the given color which
// attack a square adjacent to the enemy king. // attack a square adjacent to the enemy king.
int attackCount[2]; int kingAttackersCount[2];
// attackWeight[color] is the sum of the "weight" of the pieces of the given // kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
// color which attack a square adjacent to the enemy king. The weights of // given color which attack a square adjacent to the enemy king. The weights
// the individual piece types are given by the variables QueenAttackWeight, // of the individual piece types are given by the variables QueenAttackWeight,
// RookAttackWeight, BishopAttackWeight and KnightAttackWeight in // RookAttackWeight, BishopAttackWeight and KnightAttackWeight in evaluate.cpp
// evaluate.cpp. int kingAttackersWeight[2];
int attackWeight[2];
// attacked[color] is the number of enemy piece attacks to squares directly // kingZoneAttacksCount[color] is the number of attacks to squares directly
// adjacent to the king of the given color. Pieces which attack more // adjacent to the king of the given color. Pieces which attack more
// than one square are counted multiple times. For instance, if black's // than one square are counted multiple times. For instance, if black's
// king is on g8 and there's a white knight on g5, this knight adds // king is on g8 and there's a white knight on g5, this knight adds
// 2 to attacked[BLACK]. // 2 to kingZoneAttacksCount[BLACK].
int attacked[2]; int kingZoneAttacksCount[2];
// mateThreat[color] is a move for the given side which gives a direct mate. // mateThreat[color] is a move for the given side which gives a direct mate.
Move mateThreat[2]; Move mateThreat[2];