- const int QueenContactCheckBonus = 3;
- const int QueenCheckBonus = 2;
- const int RookCheckBonus = 1;
- const int BishopCheckBonus = 1;
- const int KnightCheckBonus = 1;
-
- // InitKingDanger[Square] contains penalties based on the position of the
- // defending king, indexed by king's square (from white's point of view).
- const int InitKingDanger[] = {
- 2, 0, 2, 5, 5, 2, 0, 2,
- 2, 2, 4, 8, 8, 4, 2, 2,
- 7, 10, 12, 12, 12, 12, 10, 7,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15
- };
-
- // KingDangerTable[Color][attackUnits] contains the actual king danger
- // weighted scores, indexed by color and by a calculated integer number.
- Score KingDangerTable[2][128];
-
- // Pawn and material hash tables, indexed by the current thread id.
- // Note that they will be initialized at 0 being global variables.
- MaterialInfoTable* MaterialTable[MAX_THREADS];
- PawnInfoTable* PawnTable[MAX_THREADS];
-
- // Function prototypes
- template<bool HasPopCnt>
- Value do_evaluate(const Position& pos, Value margins[]);
-
- template<Color Us, bool HasPopCnt>
- void init_attack_tables(const Position& pos, EvalInfo& ei);
-
- template<Color Us, bool HasPopCnt>
- Score evaluate_pieces_of_color(const Position& pos, EvalInfo& ei);
-
- template<Color Us, bool HasPopCnt>
- void evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]);
-
- template<Color Us>
- void evaluate_threats(const Position& pos, EvalInfo& ei);
-
- template<Color Us, bool HasPopCnt>
- int evaluate_space(const Position& pos, EvalInfo& ei);
-
- template<Color Us>
- void evaluate_passed_pawns(const Position& pos, EvalInfo& ei);
-
- inline Score apply_weight(Score v, Score weight);
- Value scale_by_game_phase(const Score& v, Phase ph, const ScaleFactor sf[]);
- Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight);
- void init_safety();
-}
-
-
-////
-//// Functions
-////
-
-
-/// Prefetches in pawn hash tables
-
-void prefetchPawn(Key key, int threadID) {
-
- PawnTable[threadID]->prefetch(key);
-}
-
-/// evaluate() is the main evaluation function. It always computes two
-/// values, an endgame score and a middle game score, and interpolates
-/// between them based on the remaining material.
-Value evaluate(const Position& pos, Value margins[]) {
-
- return CpuHasPOPCNT ? do_evaluate<true>(pos, margins)
- : do_evaluate<false>(pos, margins);
-}
-
-namespace {
-
-template<bool HasPopCnt>
-Value do_evaluate(const Position& pos, Value margins[]) {
-
- EvalInfo ei;
- ScaleFactor factor[2];
- Score mobility;
-
- assert(pos.is_ok());
- assert(pos.thread() >= 0 && pos.thread() < MAX_THREADS);
- assert(!pos.is_check());