X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.h;h=5e181526201da79f4863db34f25b223b0ef94765;hp=509e8d4caac7fabc8589836d9c97fc89c7015027;hb=27ba611a3da37423a3502e49beeebe11c9a11d8e;hpb=f907d5b7d93a161bc88aeaec403631de9de092f9 diff --git a/src/endgame.h b/src/endgame.h index 509e8d4c..5e181526 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -31,12 +31,11 @@ #include "types.h" -/// EndgameType lists all supported endgames +/// EndgameCode lists all supported endgame functions by corresponding codes -enum EndgameType { - - // Evaluation functions +enum EndgameCode { + EVALUATION_FUNCTIONS, KNNK, // KNN vs K KXK, // Generic "mate lone king" eval KBNK, // KBN vs K @@ -47,10 +46,7 @@ enum EndgameType { KQKP, // KQ vs KP KQKR, // KQ vs KR - - // Scaling functions SCALING_FUNCTIONS, - KBPsK, // KB and pawns vs K KQKRPs, // KQ vs KR and pawns KRPKR, // KRP vs KR @@ -68,30 +64,28 @@ enum EndgameType { /// Endgame functions can be of two types depending on whether they return a /// Value or a ScaleFactor. -template using +template using eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type; -/// Base and derived templates for endgame evaluation and scaling functions +/// Base and derived functors for endgame evaluation and scaling functions template struct EndgameBase { + explicit EndgameBase(Color c) : strongSide(c), weakSide(~c) {} virtual ~EndgameBase() = default; - virtual Color strong_side() const = 0; virtual T operator()(const Position&) const = 0; + + const Color strongSide, weakSide; }; -template> +template> struct Endgame : public EndgameBase { - explicit Endgame(Color c) : strongSide(c), weakSide(~c) {} - Color strong_side() const { return strongSide; } + explicit Endgame(Color c) : EndgameBase(c) {} T operator()(const Position&) const; - -private: - Color strongSide, weakSide; }; @@ -101,16 +95,22 @@ private: class Endgames { - template using Map = std::map>>; - - template> - void add(const std::string& code); + template using Ptr = std::unique_ptr>; + template using Map = std::map>; template Map& map() { return std::get::value>(maps); } + template, typename P = Ptr> + void add(const std::string& code) { + + StateInfo st; + map()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame(WHITE)); + map()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame(BLACK)); + } + std::pair, Map> maps; public: