1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Slight tidy up in endgame machinery

No functional change.
This commit is contained in:
Marco Costalba 2018-07-21 10:30:22 +02:00 committed by Stéphane Nicolet
parent 53c07c34bb
commit 4bd24da161
5 changed files with 29 additions and 34 deletions

View file

@ -86,30 +86,6 @@ namespace {
} // namespace } // namespace
/// Endgames members definitions
Endgames::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<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 /// 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 /// 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 /// attacking side a bonus for driving the defending king towards the edge

View file

@ -64,6 +64,7 @@ enum EndgameCode {
/// 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<EndgameCode E> using template<EndgameCode E> using
eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type; eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
@ -103,21 +104,40 @@ class Endgames {
return std::get<std::is_same<T, ScaleFactor>::value>(maps); return std::get<std::is_same<T, ScaleFactor>::value>(maps);
} }
template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>> template<EndgameCode E, typename T = eg_type<E>>
void add(const std::string& code) { void add(const std::string& code) {
StateInfo st; StateInfo st;
map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE)); map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK)); map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
} }
std::pair<Map<Value>, Map<ScaleFactor>> maps; std::pair<Map<Value>, Map<ScaleFactor>> maps;
public: public:
Endgames(); 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<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> template<typename T>
EndgameBase<T>* probe(Key key) { const EndgameBase<T>* probe(Key key) {
return map<T>().count(key) ? map<T>()[key].get() : nullptr; return map<T>().count(key) ? map<T>()[key].get() : nullptr;
} }
}; };

View file

@ -21,7 +21,6 @@
#ifndef EVALUATE_H_INCLUDED #ifndef EVALUATE_H_INCLUDED
#define EVALUATE_H_INCLUDED #define EVALUATE_H_INCLUDED
#include <atomic>
#include <string> #include <string>
#include "types.h" #include "types.h"

View file

@ -152,7 +152,7 @@ Entry* probe(const Position& pos) {
// OK, we didn't find any special evaluation function for the current material // OK, we didn't find any special evaluation function for the current material
// configuration. Is there a suitable specialized scaling function? // configuration. Is there a suitable specialized scaling function?
EndgameBase<ScaleFactor>* sf; const EndgameBase<ScaleFactor>* sf;
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr) if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
{ {

View file

@ -56,9 +56,9 @@ struct Entry {
} }
Key key; Key key;
EndgameBase<Value>* evaluationFunction; const EndgameBase<Value>* evaluationFunction;
EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
// side (e.g. KPKP, KBPsKs) // side (e.g. KPKP, KBPsKs)
int16_t value; int16_t value;
uint8_t factor[COLOR_NB]; uint8_t factor[COLOR_NB];
Phase gamePhase; Phase gamePhase;