From: Marco Costalba Date: Sun, 14 Aug 2011 10:52:27 +0000 (+0100) Subject: Small simplification of endgame functions API X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=48e39c5c8e671a37f09732d4a55d93d5e2d38550 Small simplification of endgame functions API No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/endgame.cpp b/src/endgame.cpp index f8f4c802..c55013f3 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -101,57 +101,59 @@ namespace { /// Endgames member definitions -template<> const Endgames::EFMap& Endgames::get() const { return maps.first; } -template<> const Endgames::SFMap& Endgames::get() const { return maps.second; } +template<> const Endgames::EFMap& Endgames::map() const { return maps.first; } +template<> const Endgames::SFMap& Endgames::map() const { return maps.second; } Endgames::Endgames() { - add >("KNNK"); - add >("KPK"); - add >("KBNK"); - add >("KRKP"); - add >("KRKB"); - add >("KRKN"); - add >("KQKR"); - add >("KBBKN"); - - add >("KNPK"); - add >("KRPKR"); - add >("KBPKB"); - add >("KBPPKB"); - add >("KBPKN"); - add >("KRPPKRP"); + add("KPK"); + add("KNNK"); + add("KBNK"); + add("KRKP"); + add("KRKB"); + add("KRKN"); + add("KQKR"); + add("KBBKN"); + + add("KNPK"); + add("KRPKR"); + add("KBPKB"); + add("KBPKN"); + add("KBPPKB"); + add("KRPPKRP"); } Endgames::~Endgames() { - for (EFMap::const_iterator it = get().begin(); it != get().end(); ++it) + for (EFMap::const_iterator it = map().begin(); it != map().end(); ++it) delete it->second; - for (SFMap::const_iterator it = get().begin(); it != get().end(); ++it) + for (SFMap::const_iterator it = map().begin(); it != map().end(); ++it) delete it->second; } -template +template void Endgames::add(const string& keyCode) { - typedef typename T::Base F; - typedef std::map M; + typedef Endgame EG; + typedef typename EG::Base B; + typedef std::map M; - const_cast(get()).insert(std::pair(mat_key(keyCode), new T(WHITE))); - const_cast(get()).insert(std::pair(mat_key(swap_colors(keyCode)), new T(BLACK))); + const_cast(map()).insert(std::pair(mat_key(keyCode), new EG(WHITE))); + const_cast(map()).insert(std::pair(mat_key(swap_colors(keyCode)), new EG(BLACK))); } -template -T* Endgames::get(Key key) const { +template +EndgameBase* Endgames::get(Key key) const { - typename std::map::const_iterator it = get().find(key); - return it != get().end() ? it->second : NULL; + typedef EndgameBase E; + typename std::map::const_iterator it = map().find(key); + return it != map().end() ? it->second : NULL; } // Explicit template instantiations -template EF* Endgames::get(Key key) const; -template SF* Endgames::get(Key key) const; +template EF* Endgames::get(Key key) const; +template SF* Endgames::get(Key key) const; /// Mate with KX vs K. This function is used to evaluate positions with diff --git a/src/endgame.h b/src/endgame.h index e35c7b0a..af5da051 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -97,16 +97,16 @@ class Endgames { public: Endgames(); ~Endgames(); - template T* get(Key key) const; + template EndgameBase* get(Key key) const; private: - template void add(const std::string& keyCode); + template void add(const std::string& keyCode); // Here we store two maps, for evaluate and scaling functions... std::pair maps; // ...and here is the accessing template function - template const std::map& get() const; + template const std::map& map() const; }; #endif // !defined(ENDGAME_H_INCLUDED) diff --git a/src/material.cpp b/src/material.cpp index 19a334ba..ce63e8b5 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -117,7 +117,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) const { // Let's look if we have a specialized evaluation function for this // particular material configuration. First we look for a fixed // configuration one, then a generic one if previous search failed. - if ((mi->evaluationFunction = funcs->get >(key)) != NULL) + if ((mi->evaluationFunction = funcs->get(key)) != NULL) return mi; if (is_KXK(pos)) @@ -154,7 +154,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) const { // scaling functions and we need to decide which one to use. EndgameBase* sf; - if ((sf = funcs->get >(key)) != NULL) + if ((sf = funcs->get(key)) != NULL) { mi->scalingFunction[sf->color()] = sf; return mi;