mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Rearrange Endgames
Remove references to EndgameBase and use instead Value and ScaleFactor as template parameters of the endgames maps. No functional change.
This commit is contained in:
parent
96e36a7897
commit
36f8814aa6
2 changed files with 16 additions and 13 deletions
|
@ -128,9 +128,8 @@ Endgames::Endgames() {
|
||||||
|
|
||||||
template<EndgameType E, typename T>
|
template<EndgameType E, typename T>
|
||||||
void Endgames::add(const string& code) {
|
void Endgames::add(const string& code) {
|
||||||
|
map<T>()[key(code, WHITE)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(WHITE));
|
||||||
map<T>()[key(code, WHITE)] = std::unique_ptr<T>(new Endgame<E>(WHITE));
|
map<T>()[key(code, BLACK)] = std::unique_ptr<EndgameBase<T>>(new Endgame<E>(BLACK));
|
||||||
map<T>()[key(code, BLACK)] = std::unique_ptr<T>(new Endgame<E>(BLACK));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,8 @@ enum EndgameType {
|
||||||
|
|
||||||
/// Endgame functions can be of two types depending on whether they return a
|
/// Endgame functions can be of two types depending on whether they return a
|
||||||
/// Value or a ScaleFactor.
|
/// Value or a ScaleFactor.
|
||||||
template<EndgameType E>
|
template<EndgameType E> using
|
||||||
using eg_fun = std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>;
|
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
|
||||||
|
|
||||||
|
|
||||||
/// Base and derived templates for endgame evaluation and scaling functions
|
/// Base and derived templates for endgame evaluation and scaling functions
|
||||||
|
@ -82,7 +82,7 @@ struct EndgameBase {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<EndgameType E, typename T = typename eg_fun<E>::type>
|
template<EndgameType E, typename T = eg_type<E>>
|
||||||
struct Endgame : public EndgameBase<T> {
|
struct Endgame : public EndgameBase<T> {
|
||||||
|
|
||||||
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
||||||
|
@ -100,21 +100,25 @@ private:
|
||||||
|
|
||||||
class Endgames {
|
class Endgames {
|
||||||
|
|
||||||
template<typename T> using Map = std::map<Key, std::unique_ptr<T>>;
|
template<typename T> using Map = std::map<Key, std::unique_ptr<EndgameBase<T>>>;
|
||||||
|
|
||||||
template<EndgameType E, typename T = EndgameBase<typename eg_fun<E>::type>>
|
template<EndgameType E, typename T = eg_type<E>>
|
||||||
void add(const std::string& code);
|
void add(const std::string& code);
|
||||||
|
|
||||||
template<typename T, int I = std::is_same<T, EndgameBase<ScaleFactor>>::value>
|
template<typename T>
|
||||||
Map<T>& map() { return std::get<I>(maps); }
|
Map<T>& map() {
|
||||||
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<Map<EndgameBase<Value>>, Map<EndgameBase<ScaleFactor>>> maps;
|
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Endgames();
|
Endgames();
|
||||||
|
|
||||||
template<typename T, typename E = EndgameBase<T>> E* probe(Key key)
|
template<typename T>
|
||||||
{ return map<E>().count(key) ? map<E>()[key].get() : nullptr; }
|
EndgameBase<T>* probe(Key key) {
|
||||||
|
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef ENDGAME_H_INCLUDED
|
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||||
|
|
Loading…
Add table
Reference in a new issue