+class Endgames {
+
+ template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
+ template<typename T> using Map = std::map<Key, Ptr<T>>;
+
+ template<typename T>
+ Map<T>& map() {
+ return std::get<std::is_same<T, ScaleFactor>::value>(maps);
+ }
+
+ template<EndgameCode E, typename T = eg_type<E>>
+ void add(const std::string& code) {
+
+ StateInfo st;
+ map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
+ map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
+ }
+
+ std::pair<Map<Value>, Map<ScaleFactor>> maps;
+
+public:
+ Endgames() {
+
+ add<KPK>("KPK");
+ add<KNNK>("KNNK");
+ add<KBNK>("KBNK");
+ add<KRKP>("KRKP");
+ add<KRKB>("KRKB");
+ add<KRKN>("KRKN");
+ add<KQKP>("KQKP");
+ add<KQKR>("KQKR");
+
+ add<KNPK>("KNPK");
+ add<KNPKB>("KNPKB");
+ add<KRPKR>("KRPKR");
+ add<KRPKB>("KRPKB");
+ add<KBPKB>("KBPKB");
+ add<KBPKN>("KBPKN");
+ add<KBPPKB>("KBPPKB");
+ add<KRPPKRP>("KRPPKRP");
+ }
+
+ template<typename T>
+ const EndgameBase<T>* probe(Key key) {
+ return map<T>().count(key) ? map<T>()[key].get() : nullptr;
+ }
+};