X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.h;h=0d7c063fbb1c37af9a20f87b2a52b7f7c0db4441;hp=70f795cd19782c7a4aec23dd3c0217db51b4efd9;hb=c1f4000426dd799cfac97298c539e618909c057f;hpb=d98150dffc69a810b0b842244aec0d29deddabfb diff --git a/src/endgame.h b/src/endgame.h index 70f795cd..0d7c063f 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -61,11 +61,12 @@ enum EndgameType { }; -/// Some magic to detect family type of endgame from its enum value +/// Endgame functions can be of two types according if return a Value or a +/// ScaleFactor. Type eg_fun::type equals to either ScaleFactor or Value +/// depending if the template parameter is 0 or 1. -template struct bool_to_type { typedef Value type; }; -template<> struct bool_to_type { typedef ScaleFactor type; }; -template struct eg_family : public bool_to_type<(E > SCALE_FUNS)> {}; +template struct eg_fun { typedef Value type; }; +template<> struct eg_fun<1> { typedef ScaleFactor type; }; /// Base and derived templates for endgame evaluation and scaling functions @@ -79,7 +80,7 @@ struct EndgameBase { }; -template::type> +template SCALE_FUNS)>::type> struct Endgame : public EndgameBase { explicit Endgame(Color c) : strongerSide(c), weakerSide(~c) {} @@ -93,18 +94,18 @@ 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 operator() method that is virtual. +/// endgame function calling its operator() that is virtual. class Endgames { - typedef std::map*> M1; - typedef std::map*> M2; + typedef std::map::type>*> M1; + typedef std::map::type>*> M2; M1 m1; M2 m2; - M1& map(Value*) { return m1; } - M2& map(ScaleFactor*) { return m2; } + M1& map(M1::mapped_type) { return m1; } + M2& map(M2::mapped_type) { return m2; } template void add(const std::string& code); @@ -112,9 +113,8 @@ public: Endgames(); ~Endgames(); - template EndgameBase* get(Key key) { - return map((T*)0).count(key) ? map((T*)0)[key] : NULL; - } + template T probe(Key key, T& eg) + { return eg = map(eg).count(key) ? map(eg)[key] : NULL; } }; #endif // !defined(ENDGAME_H_INCLUDED)