From 1a2768705ad389d1c4a234bf71354d05e56fcc1f Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 12 Sep 2010 14:02:33 +0100 Subject: [PATCH] Do not update king tables when we skip king safety No functional change. Signed-off-by: Marco Costalba --- src/evaluate.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 72dc73a1..d791ed36 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -45,6 +45,11 @@ namespace { // Pointer to pawn hash table entry PawnInfo* pi; + // updateKingTables[color] is set to true if we have enough material + // to trigger the opponent's king safety calculation. When is false we + // skip the time consuming update of the king attackers tables. + bool updateKingTables[2]; + // attackedBy[color][piece type] is a bitboard representing all squares // attacked by a given color and piece type, attackedBy[color][0] contains // all squares attacked by the given color. @@ -451,9 +456,13 @@ namespace { Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from(pos.king_square(Them)); ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8)); ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us); - b &= ei.attackedBy[Us][PAWN]; - ei.kingAttackersCount[Us] = b ? count_1s_max_15(b) / 2 : EmptyBoardBB; - ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB; + ei.updateKingTables[Us] = pos.piece_count(Us, QUEEN) && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame; + if (ei.updateKingTables[Us]) + { + b &= ei.attackedBy[Us][PAWN]; + ei.kingAttackersCount[Us] = b ? count_1s_max_15(b) / 2 : EmptyBoardBB; + ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB; + } } @@ -515,7 +524,7 @@ namespace { ei.attackedBy[Us][Piece] |= b; // King attacks - if (b & ei.kingZone[Us]) + if (ei.updateKingTables[Us] && (b & ei.kingZone[Us])) { ei.kingAttackersCount[Us]++; ei.kingAttackersWeight[Us] += KingAttackWeights[Piece]; @@ -666,9 +675,8 @@ namespace { // King safety. This is quite complicated, and is almost certainly far // from optimally tuned. - if ( ei.kingAttackersCount[Them] >= 2 - && pos.non_pawn_material(Them) >= QueenValueMidgame + RookValueMidgame - && pos.piece_count(Them, QUEEN) >= 1 + if ( ei.updateKingTables[Them] + && ei.kingAttackersCount[Them] >= 2 && ei.kingAdjacentZoneAttacksCount[Them]) { // Find the attacked squares around the king which has no defenders -- 2.39.2