- const Value BishopPairMidgameBonus = Value(109);
- const Value BishopPairEndgameBonus = Value(97);
-
- Key KNNKMaterialKey, KKNNMaterialKey;
-
- // Unmapped endgame evaluation and scaling functions, these
- // are accessed direcly and not through the function maps.
- EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
- EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
- ScalingFunction<KBPK> ScaleKBPK(WHITE), ScaleKKBP(BLACK);
- ScalingFunction<KQKRP> ScaleKQKRP(WHITE), ScaleKRPKQ(BLACK);
- ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK);
- ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK);
-}
-
-
-////
-//// Classes
-////
-
-typedef EndgameEvaluationFunctionBase EF;
-typedef EndgameScalingFunctionBase SF;
-
-/// See header for a class description. It is declared here to avoid
-/// to include <map> in the header file.
-
-class EndgameFunctions {
-public:
- EndgameFunctions();
- ~EndgameFunctions();
- template<class T> T* get(Key key) const;
-
-private:
- template<class T> void add(const string& keyCode);
+ const Value MidgameLimit = Value(15581);
+ const Value EndgameLimit = Value(3998);
+
+ // Scale factors used when one side has no more pawns
+ const int NoPawnsSF[4] = { 6, 12, 32 };
+
+ // Polynomial material balance parameters
+ const Value RedundantQueenPenalty = Value(320);
+ const Value RedundantRookPenalty = Value(554);
+
+ const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
+
+ const int QuadraticCoefficientsSameColor[][PIECE_TYPE_NB] = {
+ { 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
+ { 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
+
+ const int QuadraticCoefficientsOppositeColor[][PIECE_TYPE_NB] = {
+ { 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
+ { 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
+
+ // Endgame evaluation and scaling functions accessed direcly and not through
+ // the function maps because correspond to more then one material hash key.
+ Endgame<KmmKm> EvaluateKmmKm[] = { Endgame<KmmKm>(WHITE), Endgame<KmmKm>(BLACK) };
+ Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };
+
+ Endgame<KBPsK> ScaleKBPsK[] = { Endgame<KBPsK>(WHITE), Endgame<KBPsK>(BLACK) };
+ Endgame<KQKRPs> ScaleKQKRPs[] = { Endgame<KQKRPs>(WHITE), Endgame<KQKRPs>(BLACK) };
+ Endgame<KPsK> ScaleKPsK[] = { Endgame<KPsK>(WHITE), Endgame<KPsK>(BLACK) };
+ Endgame<KPKP> ScaleKPKP[] = { Endgame<KPKP>(WHITE), Endgame<KPKP>(BLACK) };
+
+ // Helper templates used to detect a given material distribution
+ template<Color Us> bool is_KXK(const Position& pos) {
+ const Color Them = (Us == WHITE ? BLACK : WHITE);
+ return pos.non_pawn_material(Them) == VALUE_ZERO
+ && pos.piece_count(Them, PAWN) == 0
+ && pos.non_pawn_material(Us) >= RookValueMg;
+ }