- 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
-////
-
-
-/// See header for a class description. It is declared here to avoid
-/// to include <map> in the header file.
-
-class EndgameFunctions {
-
- typedef EndgameEvaluationFunctionBase EF;
- typedef EndgameScalingFunctionBase SF;
-
-public:
- EndgameFunctions();
- ~EndgameFunctions();
- EF* getEEF(Key key) const;
- SF* getESF(Key key, Color* c) const;
-
-private:
- Key buildKey(const string& keyCode);
- const string swapColors(const string& keyCode);
- template<EndgameType> void add_ef(const string& keyCode);
- template<EndgameType> void add_sf(const string& keyCode);
-
- struct ScalingInfo
- {
- Color col;
- SF* fun;
- };
-
- std::map<Key, EF*> EEFmap;
- std::map<Key, ScalingInfo> ESFmap;
-};
-
-
-////
-//// Functions
-////
-
-
-/// Constructor for the MaterialInfoTable class
+ 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[][8] = {
+ { 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[][8] = {
+ { 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<Value, KmmKm> EvaluateKmmKm[] = { Endgame<Value, KmmKm>(WHITE), Endgame<Value, KmmKm>(BLACK) };
+ Endgame<Value, KXK> EvaluateKXK[] = { Endgame<Value, KXK>(WHITE), Endgame<Value, KXK>(BLACK) };
+
+ Endgame<ScaleFactor, KBPsK> ScaleKBPsK[] = { Endgame<ScaleFactor, KBPsK>(WHITE), Endgame<ScaleFactor, KBPsK>(BLACK) };
+ Endgame<ScaleFactor, KQKRPs> ScaleKQKRPs[] = { Endgame<ScaleFactor, KQKRPs>(WHITE), Endgame<ScaleFactor, KQKRPs>(BLACK) };
+ Endgame<ScaleFactor, KPsK> ScaleKPsK[] = { Endgame<ScaleFactor, KPsK>(WHITE), Endgame<ScaleFactor, KPsK>(BLACK) };
+ Endgame<ScaleFactor, KPKP> ScaleKPKP[] = { Endgame<ScaleFactor, KPKP>(WHITE), Endgame<ScaleFactor, 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) >= RookValueMidgame;
+ }