mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 09:47:46 +00:00
Better naming in endgame code
And small clean-up of magic bitboards code. No functional change. Closes #1138
This commit is contained in:
committed by
Joona Kiiski
parent
f907d5b7d9
commit
27ba611a3d
+20
-20
@@ -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<EndgameType E> using
|
||||
template<EndgameCode E> 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<typename T>
|
||||
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<EndgameType E, typename T = eg_type<E>>
|
||||
template<EndgameCode E, typename T = eg_type<E>>
|
||||
struct Endgame : public EndgameBase<T> {
|
||||
|
||||
explicit Endgame(Color c) : strongSide(c), weakSide(~c) {}
|
||||
Color strong_side() const { return strongSide; }
|
||||
explicit Endgame(Color c) : EndgameBase<T>(c) {}
|
||||
T operator()(const Position&) const;
|
||||
|
||||
private:
|
||||
Color strongSide, weakSide;
|
||||
};
|
||||
|
||||
|
||||
@@ -101,16 +95,22 @@ private:
|
||||
|
||||
class Endgames {
|
||||
|
||||
template<typename T> using Map = std::map<Key, std::unique_ptr<EndgameBase<T>>>;
|
||||
|
||||
template<EndgameType E, typename T = eg_type<E>>
|
||||
void add(const std::string& code);
|
||||
template<typename T> using Ptr = std::unique_ptr<EndgameBase<T>>;
|
||||
template<typename T> using Map = std::map<Key, Ptr<T>>;
|
||||
|
||||
template<typename T>
|
||||
Map<T>& map() {
|
||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||
}
|
||||
|
||||
template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
|
||||
void add(const std::string& code) {
|
||||
|
||||
StateInfo st;
|
||||
map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE));
|
||||
map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
|
||||
}
|
||||
|
||||
std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user