-/// Abstract base class for all special endgame evaluation functions:
-
-class EndgameEvaluationFunction {
-public:
- EndgameEvaluationFunction(Color c);
- virtual ~EndgameEvaluationFunction() { }
-
- virtual Value apply(const Position &pos) =0;
-
-protected:
- Color strongerSide, weakerSide;
-};
-
-
-/// Subclasses for various concrete endgames:
-
-// Generic "mate lone king" eval:
-class KXKEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KXKEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KBN vs K:
-class KBNKEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KBNKEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KP vs K:
-class KPKEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KPKEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KR vs KP:
-class KRKPEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KRKPEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KR vs KB:
-class KRKBEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KRKBEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KR vs KN:
-class KRKNEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KRKNEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KQ vs KR:
-class KQKREvaluationFunction : public EndgameEvaluationFunction {
-public:
- KQKREvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-// KBB vs KN:
-class KBBKNEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KBBKNEvaluationFunction(Color C);
- Value apply(const Position &pos);
-};
-
-// K and two minors vs K and one or two minors:
-class KmmKmEvaluationFunction : public EndgameEvaluationFunction {
-public:
- KmmKmEvaluationFunction(Color c);
- Value apply(const Position &pos);
-};
-
-
-/// Abstract base class for all evaluation scaling functions:
-
-class ScalingFunction {
-public:
- ScalingFunction(Color c);
- virtual ~ScalingFunction() { }
-
- virtual ScaleFactor apply(const Position &pos) =0;
+enum EndgameType {
+
+ // Evaluation functions
+ KXK, // Generic "mate lone king" eval
+ KBNK, // KBN vs K
+ KPK, // KP vs K
+ KRKP, // KR vs KP
+ KRKB, // KR vs KB
+ KRKN, // KR vs KN
+ KQKR, // KQ vs KR
+ KBBKN, // KBB vs KN
+ KNNK, // KNN vs K
+ KmmKm, // K and two minors vs K and one or two minors
+
+ // Scaling functions
+ KBPsK, // KB+pawns vs K
+ KQKRPs, // KQ vs KR+pawns
+ KRPKR, // KRP vs KR
+ KRPPKRP, // KRPP vs KRP
+ KPsK, // King and pawns vs king
+ KBPKB, // KBP vs KB
+ KBPPKB, // KBPP vs KB
+ KBPKN, // KBP vs KN
+ KNPK, // KNP vs K
+ KPKP // KP vs KP
+};
+
+/// Template abstract base class for all special endgame functions
+
+template<typename T>
+class EndgameFunctionBase {
+public:
+ EndgameFunctionBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
+ virtual ~EndgameFunctionBase() {}
+ virtual T apply(const Position&) const = 0;
+ Color color() const { return strongerSide; }