+ // Values modified by Joona Kiiski
+ const Value MidgameLimit = Value(15581);
+ const Value EndgameLimit = Value(3998);
+
+ // 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 } };
+
+ typedef EndgameEvaluationFunctionBase EF;
+ typedef EndgameScalingFunctionBase SF;
+ typedef map<Key, EF*> EFMap;
+ typedef map<Key, SF*> SFMap;
+
+ // Endgame evaluation and scaling functions accessed direcly and not through
+ // the function maps because correspond to more then one material hash key.
+ EvaluationFunction<KmmKm> EvaluateKmmKm[] = { EvaluationFunction<KmmKm>(WHITE), EvaluationFunction<KmmKm>(BLACK) };
+ EvaluationFunction<KXK> EvaluateKXK[] = { EvaluationFunction<KXK>(WHITE), EvaluationFunction<KXK>(BLACK) };
+ ScalingFunction<KBPsK> ScaleKBPsK[] = { ScalingFunction<KBPsK>(WHITE), ScalingFunction<KBPsK>(BLACK) };
+ ScalingFunction<KQKRPs> ScaleKQKRPs[] = { ScalingFunction<KQKRPs>(WHITE), ScalingFunction<KQKRPs>(BLACK) };
+ ScalingFunction<KPsK> ScaleKPsK[] = { ScalingFunction<KPsK>(WHITE), ScalingFunction<KPsK>(BLACK) };
+ ScalingFunction<KPKP> ScaleKPKP[] = { ScalingFunction<KPKP>(WHITE), ScalingFunction<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;
+ }