mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Remove per thread instances of Endgames. (#2056)
Similar to PSQT we only need one instance of the Endgames resource. The current per thread copies are identical and read only(after initialization) so from a design point of view it doesn't make sense to have them. Tested for no slowdown. http://tests.stockfishchess.org/tests/view/5c94377a0ebc5925cfff43ca LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 17320 W: 3487 L: 3359 D: 10474 No functional change.
This commit is contained in:
parent
44c320a572
commit
4a7b8180ec
5 changed files with 37 additions and 30 deletions
|
@ -82,6 +82,33 @@ namespace {
|
|||
} // namespace
|
||||
|
||||
|
||||
namespace Endgames {
|
||||
|
||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||
|
||||
void init() {
|
||||
|
||||
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<KNNKP>("KNNKP");
|
||||
|
||||
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
|
||||
|
|
|
@ -95,10 +95,12 @@ struct Endgame : public EndgameBase<T> {
|
|||
/// base objects in two std::map. We use polymorphism to invoke the actual
|
||||
/// endgame function by calling its virtual operator().
|
||||
|
||||
class Endgames {
|
||||
namespace Endgames {
|
||||
|
||||
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
||||
|
||||
extern std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||
|
||||
template<typename T>
|
||||
Map<T>& map() {
|
||||
|
@ -113,35 +115,12 @@ class Endgames {
|
|||
map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
|
||||
}
|
||||
|
||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||
|
||||
public:
|
||||
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<KNNKP>("KNNKP");
|
||||
|
||||
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>
|
||||
const EndgameBase<T>* probe(Key key) {
|
||||
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
void init();
|
||||
}
|
||||
|
||||
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "thread.h"
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
#include "endgame.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
namespace PSQT {
|
||||
|
@ -42,6 +43,7 @@ int main(int argc, char* argv[]) {
|
|||
Position::init();
|
||||
Bitbases::init();
|
||||
Search::init();
|
||||
Endgames::init();
|
||||
Threads.set(Options["Threads"]);
|
||||
Search::clear(); // After threads are up
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ Entry* probe(const Position& pos) {
|
|||
// Let's look if we have a specialized evaluation function for this particular
|
||||
// material configuration. Firstly we look for a fixed configuration one, then
|
||||
// for a generic one if the previous search failed.
|
||||
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
||||
if ((e->evaluationFunction = Endgames::probe<Value>(key)) != nullptr)
|
||||
return e;
|
||||
|
||||
for (Color c = WHITE; c <= BLACK; ++c)
|
||||
|
@ -149,7 +149,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?
|
||||
const auto* sf = pos.this_thread()->endgames.probe<ScaleFactor>(key);
|
||||
const auto* sf = Endgames::probe<ScaleFactor>(key);
|
||||
|
||||
if (sf)
|
||||
{
|
||||
|
|
|
@ -59,7 +59,6 @@ public:
|
|||
|
||||
Pawns::Table pawnsTable;
|
||||
Material::Table materialTable;
|
||||
Endgames endgames;
|
||||
size_t pvIdx, pvLast;
|
||||
int selDepth, nmpMinPly;
|
||||
Color nmpColor;
|
||||
|
|
Loading…
Add table
Reference in a new issue