X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.h;h=a5e4efecafea8831c0bc4ee032ddc5c5aa5af6c8;hp=efc527a7f98f30980fd8677e3ab35568a4a78a36;hb=4554d8b2ac1ad260c3f7123b2a7d3a3385fa8306;hpb=35018fa3076a01a62bd4433771c5832d0ddc52e8 diff --git a/src/endgame.h b/src/endgame.h index efc527a7..a5e4efec 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -20,8 +20,8 @@ #if !defined(ENDGAME_H_INCLUDED) #define ENDGAME_H_INCLUDED -#include #include +#include #include "position.h" #include "types.h" @@ -75,16 +75,16 @@ struct EndgameBase { virtual ~EndgameBase() {} virtual Color color() const = 0; - virtual T apply(const Position&) const = 0; + virtual T operator()(const Position&) const = 0; }; template::type> struct Endgame : public EndgameBase { - explicit Endgame(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {} + explicit Endgame(Color c) : strongerSide(c), weakerSide(flip(c)) {} Color color() const { return strongerSide; } - T apply(const Position&) const; + T operator()(const Position&) const; private: Color strongerSide, weakerSide; @@ -93,33 +93,28 @@ private: /// Endgames class stores in two std::map the pointers to endgame evaluation /// and scaling base objects. Then we use polymorphism to invoke the actual -/// endgame function calling its apply() method that is virtual. +/// endgame function calling its operator() method that is virtual. + +class Endgames { -struct Endgames { + typedef std::map*> M1; + typedef std::map*> M2; + + M1 m1; + M2 m2; - template - struct Map { typedef std::map*> type; }; + M1& map(Value*) { return m1; } + M2& map(ScaleFactor*) { return m2; } - typedef Map::type M1; - typedef Map::type M2; + template void add(const std::string& code); +public: Endgames(); ~Endgames(); - template - EndgameBase* get(Key key) const { - - typedef typename Map::type M; - typename M::const_iterator it = map().find(key); - return it != map().end() ? it->second : NULL; + template EndgameBase* get(Key key) { + return map((T*)0).count(key) ? map((T*)0)[key] : NULL; } - -private: - template void add(const std::string& keyCode); - template const M& map() const; - - M1 m1; - M2 m2; }; #endif // !defined(ENDGAME_H_INCLUDED)