X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.h;h=78b31d82ec2ab0f769327a5370f7e55740fc05ea;hp=70f795cd19782c7a4aec23dd3c0217db51b4efd9;hb=55df3fa2d7631ed67e46f9433aa7f3a71c18e5e7;hpb=d98150dffc69a810b0b842244aec0d29deddabfb diff --git a/src/endgame.h b/src/endgame.h index 70f795cd..78b31d82 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -39,6 +39,7 @@ enum EndgameType { KRKP, // KR vs KP KRKB, // KR vs KB KRKN, // KR vs KN + KQKP, // KQ vs KP KQKR, // KQ vs KR KBBKN, // KBB vs KN KNNK, // KNN vs K @@ -61,11 +62,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 +81,7 @@ struct EndgameBase { }; -template::type> +template SCALE_FUNS)>::type> struct Endgame : public EndgameBase { explicit Endgame(Color c) : strongerSide(c), weakerSide(~c) {} @@ -93,18 +95,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 +114,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)