- const Value BishopPairMidgameBonus = Value(109);
- const Value BishopPairEndgameBonus = Value(97);
-
- Key KNNKMaterialKey, KKNNMaterialKey;
-
-}
-
-////
-//// Classes
-////
-
-
-/// See header for a class description. It is declared here to avoid
-/// to include <map> in the header file.
-
-class EndgameFunctions {
-
-public:
- EndgameFunctions();
- EndgameEvaluationFunctionBase* getEEF(Key key) const;
- EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
-
-private:
- void add(const string& keyCode, EndgameEvaluationFunctionBase* f);
- void add(const string& keyCode, Color c, EndgameScalingFunctionBase* f);
- Key buildKey(const string& keyCode);
-
- struct ScalingInfo
- {
- Color col;
- EndgameScalingFunctionBase* fun;
- };
-
- std::map<Key, EndgameEvaluationFunctionBase*> EEFmap;
- std::map<Key, ScalingInfo> ESFmap;
-};
-
-
-////
-//// Functions
-////
-
-
-/// Constructor for the MaterialInfoTable class
-
-MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
-
- size = numOfEntries;
- entries = new MaterialInfo[size];
- funcs = new EndgameFunctions();
- if (!entries || !funcs)
- {
- std::cerr << "Failed to allocate " << (numOfEntries * sizeof(MaterialInfo))
- << " bytes for material hash table." << std::endl;
- Application::exit_with_failure();
+ 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<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) >= RookValueMidgame;