From: Marco Costalba Date: Sat, 21 Jul 2018 08:30:22 +0000 (+0200) Subject: Slight tidy up in endgame machinery X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4bd24da161fa7fdac4283438e86e9fd923c3493a Slight tidy up in endgame machinery No functional change. --- diff --git a/src/endgame.cpp b/src/endgame.cpp index 3e01259c..5a114d70 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -86,30 +86,6 @@ namespace { } // namespace -/// Endgames members definitions - -Endgames::Endgames() { - - add("KPK"); - add("KNNK"); - add("KBNK"); - add("KRKP"); - add("KRKB"); - add("KRKN"); - add("KQKP"); - add("KQKR"); - - add("KNPK"); - add("KNPKB"); - add("KRPKR"); - add("KRPKB"); - add("KBPKB"); - add("KBPKN"); - add("KBPPKB"); - add("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 diff --git a/src/endgame.h b/src/endgame.h index b5255a2f..69a9f179 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -64,6 +64,7 @@ enum EndgameCode { /// Endgame functions can be of two types depending on whether they return a /// Value or a ScaleFactor. + template using eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type; @@ -103,21 +104,40 @@ class Endgames { return std::get::value>(maps); } - template, typename P = Ptr> + template> 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)); + map()[Position().set(code, WHITE, &st).material_key()] = Ptr(new Endgame(WHITE)); + map()[Position().set(code, BLACK, &st).material_key()] = Ptr(new Endgame(BLACK)); } std::pair, Map> maps; public: - Endgames(); + Endgames() { + + add("KPK"); + add("KNNK"); + add("KBNK"); + add("KRKP"); + add("KRKB"); + add("KRKN"); + add("KQKP"); + add("KQKR"); + + add("KNPK"); + add("KNPKB"); + add("KRPKR"); + add("KRPKB"); + add("KBPKB"); + add("KBPKN"); + add("KBPPKB"); + add("KRPPKRP"); + } template - EndgameBase* probe(Key key) { + const EndgameBase* probe(Key key) { return map().count(key) ? map()[key].get() : nullptr; } }; diff --git a/src/evaluate.h b/src/evaluate.h index ccc6d5fa..d5a7e731 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -21,7 +21,6 @@ #ifndef EVALUATE_H_INCLUDED #define EVALUATE_H_INCLUDED -#include #include #include "types.h" diff --git a/src/material.cpp b/src/material.cpp index b18d29d0..64a5bff0 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -152,7 +152,7 @@ Entry* probe(const Position& pos) { // OK, we didn't find any special evaluation function for the current material // configuration. Is there a suitable specialized scaling function? - EndgameBase* sf; + const EndgameBase* sf; if ((sf = pos.this_thread()->endgames.probe(key)) != nullptr) { diff --git a/src/material.h b/src/material.h index 7fea5e7d..5e641945 100644 --- a/src/material.h +++ b/src/material.h @@ -56,9 +56,9 @@ struct Entry { } Key key; - EndgameBase* evaluationFunction; - EndgameBase* scalingFunction[COLOR_NB]; // Could be one for each - // side (e.g. KPKP, KBPsKs) + const EndgameBase* evaluationFunction; + const EndgameBase* scalingFunction[COLOR_NB]; // Could be one for each + // side (e.g. KPKP, KBPsKs) int16_t value; uint8_t factor[COLOR_NB]; Phase gamePhase;