]> git.sesse.net Git - stockfish/blobdiff - src/endgame.h
Small simplification of endgame functions API
[stockfish] / src / endgame.h
index e40b4050756fee4b2fb8489b1a599ae6004aba43..af5da0519ec8bb0bc624ea03459c9eff8dac2c79 100644 (file)
@@ -32,6 +32,7 @@
 enum EndgameType {
 
   // Evaluation functions
+
   KXK,   // Generic "mate lone king" eval
   KBNK,  // KBN vs K
   KPK,   // KP vs K
@@ -43,7 +44,9 @@ enum EndgameType {
   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
@@ -57,28 +60,28 @@ enum EndgameType {
 };
 
 
-/// Base and derived template class for endgame evaluation and scaling functions
+/// Base and derived templates for endgame evaluation and scaling functions
 
 template<typename T>
 struct EndgameBase {
 
   typedef EndgameBase<T> Base;
 
-  EndgameBase(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
   virtual ~EndgameBase() {}
+  virtual Color color() const = 0;
   virtual T apply(const Position&) const = 0;
-  Color color() const { return strongerSide; }
-
-protected:
-  Color strongerSide, weakerSide;
 };
 
 
 template<typename T, EndgameType>
 struct Endgame : public EndgameBase<T> {
 
-  explicit Endgame(Color c): EndgameBase<T>(c) {}
+  explicit Endgame(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
+  Color color() const { return strongerSide; }
   T apply(const Position&) const;
+
+private:
+  Color strongerSide, weakerSide;
 };
 
 
@@ -88,22 +91,22 @@ struct Endgame : public EndgameBase<T> {
 
 class Endgames {
 
-  typedef std::map<Key, EndgameBase<Value>*> EFMap;
-  typedef std::map<Key, EndgameBase<ScaleFactor>*> SFMap;
+  typedef std::map<Key, EndgameBase<Value>* > EFMap;
+  typedef std::map<Key, EndgameBase<ScaleFactor>* > SFMap;
 
 public:
   Endgames();
   ~Endgames();
-  template<class T> T* get(Key key) const;
+  template<typename T> EndgameBase<T>* get(Key key) const;
 
 private:
-  template<class T> void add(const std::string& keyCode);
+  template<typename T, EndgameType E> void add(const std::string& keyCode);
 
   // Here we store two maps, for evaluate and scaling functions...
   std::pair<EFMap, SFMap> maps;
 
   // ...and here is the accessing template function
-  template<typename T> const std::map<Key, T*>& get() const;
+  template<typename T> const std::map<Key, T*>& map() const;
 };
 
 #endif // !defined(ENDGAME_H_INCLUDED)