From: Marco Costalba Date: Mon, 2 Apr 2012 06:41:26 +0000 (+0100) Subject: Simplify Endgames::probe() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=7a8429d9f15a45c5a60f98c4aed798d10d511300;ds=sidebyside Simplify Endgames::probe() With this API change we simplify both function and caller site. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/endgame.h b/src/endgame.h index 424a3591..0d7c063f 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -94,7 +94,7 @@ private: /// Endgames class stores in two std::map the pointers to endgame evaluation /// and scaling base objects. Then we use polymorphism to invoke the actual -/// endgame function calling its operator() method that is virtual. +/// endgame function calling its operator() that is virtual. class Endgames { @@ -104,8 +104,8 @@ class Endgames { M1 m1; M2 m2; - M1& map(M1::value_type::second_type) { return m1; } - M2& map(M2::value_type::second_type) { return m2; } + M1& map(M1::mapped_type) { return m1; } + M2& map(M2::mapped_type) { return m2; } template void add(const std::string& code); @@ -113,9 +113,8 @@ public: Endgames(); ~Endgames(); - template EndgameBase* probe(Key key) { - return map((EndgameBase*)0).count(key) ? map((EndgameBase*)0)[key] : NULL; - } + template T probe(Key key, T& eg) + { return eg = map(eg).count(key) ? map(eg)[key] : NULL; } }; #endif // !defined(ENDGAME_H_INCLUDED) diff --git a/src/material.cpp b/src/material.cpp index 0e3ca832..50b3a2aa 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -108,7 +108,7 @@ MaterialEntry* MaterialTable::probe(const Position& pos) { // Let's look if we have a specialized evaluation function for this // particular material configuration. First we look for a fixed // configuration one, then a generic one if previous search failed. - if ((e->evaluationFunction = endgames.probe(key)) != NULL) + if (endgames.probe(key, e->evaluationFunction)) return e; if (is_KXK(pos)) @@ -145,7 +145,7 @@ MaterialEntry* MaterialTable::probe(const Position& pos) { // scaling functions and we need to decide which one to use. EndgameBase* sf; - if ((sf = endgames.probe(key)) != NULL) + if (endgames.probe(key, sf)) { e->scalingFunction[sf->color()] = sf; return e; diff --git a/src/misc.cpp b/src/misc.cpp index 3206a2d1..0f0fca46 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -51,17 +51,15 @@ const string engine_info(bool to_uci) { string month, day, year; stringstream s, date(__DATE__); // From compiler, format is "Sep 21 2008" + s << "Stockfish " << Version; + if (Version.empty()) { date >> month >> day >> year; - s << "Stockfish " << Tag - << setfill('0') << " " << year.substr(2) - << setw(2) << (1 + months.find(month) / 4) - << setw(2) << day; + s << Tag << setfill('0') << " " << year.substr(2) + << setw(2) << (1 + months.find(month) / 4) << setw(2) << day; } - else - s << "Stockfish " << Version; s << cpu64 << popcnt << (to_uci ? "\nid author ": " by ") << "Tord Romstad, Marco Costalba and Joona Kiiski";