// evaluate_threats() assigns bonuses according to the types of the attacking
// and the attacked pieces.
+ const Bitboard WhiteCamp = Rank1BB | Rank2BB | Rank3BB | Rank4BB | Rank5BB;
+ const Bitboard BlackCamp = Rank8BB | Rank7BB | Rank6BB | Rank5BB | Rank4BB;
+ const Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
+ const Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
+ const Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
+
+ const Bitboard KingFlank[COLOR_NB][FILE_NB] = {
+ { QueenSide & WhiteCamp, QueenSide & WhiteCamp, QueenSide & WhiteCamp, CenterFiles & WhiteCamp,
+ CenterFiles & WhiteCamp, KingSide & WhiteCamp, KingSide & WhiteCamp, KingSide & WhiteCamp },
+ { QueenSide & BlackCamp, QueenSide & BlackCamp, QueenSide & BlackCamp, CenterFiles & BlackCamp,
+ CenterFiles & BlackCamp, KingSide & BlackCamp, KingSide & BlackCamp, KingSide & BlackCamp },
+ };
+
template<Color Us, bool DoTrace>
Score evaluate_threats(const Position& pos, const EvalInfo& ei) {
const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB);
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
- const Bitboard TheirCamp = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB
- : Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB);
-
- const Bitboard QueenSide = TheirCamp & (FileABB | FileBBB | FileCBB | FileDBB);
- const Bitboard CenterFiles = TheirCamp & (FileCBB | FileDBB | FileEBB | FileFBB);
- const Bitboard KingSide = TheirCamp & (FileEBB | FileFBB | FileGBB | FileHBB);
-
- const Bitboard KingFlank[FILE_NB] = {
- QueenSide, QueenSide, QueenSide, CenterFiles,
- CenterFiles, KingSide, KingSide, KingSide
- };
-
enum { Minor, Rook };
Bitboard b, weak, defended, safeThreats;
score += ThreatByPawnPush * popcount(b);
// King tropism: firstly, find squares that we attack in the enemy king flank
- b = ei.attackedBy[Us][ALL_PIECES] & KingFlank[file_of(pos.square<KING>(Them))];
+ b = ei.attackedBy[Us][ALL_PIECES] & KingFlank[Them][file_of(pos.square<KING>(Them))];
// Secondly, add to the bitboard the squares which we attack twice in that flank
// but which are not protected by a enemy pawn. Note the trick to shift away the
// ...count safe + (behind & safe) with a single popcount
int bonus = popcount((Us == WHITE ? safe << 32 : safe >> 32) | (behind & safe));
- int weight = pos.count<KNIGHT>(Us) + pos.count<BISHOP>(Us)
- + pos.count<KNIGHT>(Them) + pos.count<BISHOP>(Them);
+ bonus = std::min(16, bonus);
+ int weight = pos.count<ALL_PIECES>(Us);
- return make_score(bonus * weight * weight * 2 / 11, 0);
+ return make_score(bonus * weight * weight / 22, 0);
}
// Endings where weaker side can place his king in front of the opponent's
// pawns are drawish.
else if ( abs(eg) <= BishopValueEg
- && ei.pi->pawn_span(strongSide) <= 1
+ && pos.count<PAWN>(strongSide) <= 2
&& !pos.pawn_passed(~strongSide, pos.square<KING>(~strongSide)))
- sf = ei.pi->pawn_span(strongSide) ? ScaleFactor(51) : ScaleFactor(37);
+ sf = ScaleFactor(37 + 7 * pos.count<PAWN>(strongSide));
}
return sf;