} // namespace
-/// Endgames members definitions
-
-Endgames::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");
-}
-
-
/// Mate with KX vs K. This function is used to evaluate positions with
/// king and plenty of material vs a lone king. It simply gives the
/// attacking side a bonus for driving the defending king towards the edge
/// Endgame functions can be of two types depending on whether they return a
/// Value or a ScaleFactor.
+
template<EndgameCode E> using
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
}
- template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
+ 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()] = P(new Endgame<E>(WHITE));
- map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
+ 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();
+ 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>
- EndgameBase<T>* probe(Key key) {
+ const EndgameBase<T>* probe(Key key) {
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
}
};
// OK, we didn't find any special evaluation function for the current material
// configuration. Is there a suitable specialized scaling function?
- EndgameBase<ScaleFactor>* sf;
+ const EndgameBase<ScaleFactor>* sf;
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
{
}
Key key;
- EndgameBase<Value>* evaluationFunction;
- EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
- // side (e.g. KPKP, KBPsKs)
+ const EndgameBase<Value>* evaluationFunction;
+ const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
+ // side (e.g. KPKP, KBPsKs)
int16_t value;
uint8_t factor[COLOR_NB];
Phase gamePhase;