public:
EndgameFunctions();
- EndgameEvaluationFunction* getEEF(Key key) const;
- ScalingFunction* getESF(Key key, Color* c) const;
+ EndgameEvaluationFunctionBase* getEEF(Key key) const;
+ EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
private:
- void add(Key k, EndgameEvaluationFunction* f);
- void add(Key k, Color c, ScalingFunction* f);
+ void add(Key k, EndgameEvaluationFunctionBase* f);
+ void add(Key k, Color c, EndgameScalingFunctionBase* f);
struct ScalingInfo
{
Color col;
- ScalingFunction* fun;
+ EndgameScalingFunctionBase* fun;
};
- std::map<Key, EndgameEvaluationFunction*> EEFmap;
+ std::map<Key, EndgameEvaluationFunctionBase*> EEFmap;
std::map<Key, ScalingInfo> ESFmap;
};
}
// Let's look if we have a specialized evaluation function for this
- // particular material configuration.
+ // particular material configuration. First we look for a fixed
+ // configuration one, then a generic one if previous search failed.
if ((mi->evaluationFunction = funcs->getEEF(key)) != NULL)
return mi;
mi->evaluationFunction = &EvaluateKKX;
return mi;
}
+ else if ( pos.pawns() == EmptyBoardBB
+ && pos.rooks() == EmptyBoardBB
+ && pos.queens() == EmptyBoardBB)
+ {
+ // Minor piece endgame with at least one minor piece per side,
+ // and no pawns.
+ assert(pos.knights(WHITE) | pos.bishops(WHITE));
+ assert(pos.knights(BLACK) | pos.bishops(BLACK));
+
+ if ( pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
+ && pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
+ {
+ mi->evaluationFunction = &EvaluateKmmKm;
+ return mi;
+ }
+ }
// OK, we didn't find any special evaluation function for the current
// material configuration. Is there a suitable scaling function?
// are several conflicting applicable scaling functions and we need to
// decide which one to use.
Color c;
- ScalingFunction* sf;
+ EndgameScalingFunctionBase* sf;
if ((sf = funcs->getESF(key, &c)) != NULL)
{
}
}
+ // Compute the space weight
+ if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >=
+ 2*QueenValueMidgame + 4*RookValueMidgame + 2*KnightValueMidgame)
+ {
+ int minorPieceCount = pos.piece_count(WHITE, KNIGHT)
+ + pos.piece_count(BLACK, KNIGHT)
+ + pos.piece_count(WHITE, BISHOP)
+ + pos.piece_count(BLACK, BISHOP);
+
+ mi->spaceWeight = minorPieceCount * minorPieceCount;
+ }
+
// Evaluate the material balance
int sign;
/// EndgameFunctions member definitions. This class is used to store the maps
-/// of end game and scaling functions that MaterialInfoTable will query for
+/// of end game and scaling functions that MaterialInfoTable will query for
/// each key. The maps are constant and are populated only at construction,
/// but are per-thread instead of globals to avoid expensive locks.
add(z[W][KNIGHT][1] ^ z[B][ROOK][1], &EvaluateKNKR);
add(z[W][QUEEN][1] ^ z[B][ROOK][1], &EvaluateKQKR);
add(z[W][ROOK][1] ^ z[B][QUEEN][1], &EvaluateKRKQ);
+ add(z[W][BISHOP][2] ^ z[B][KNIGHT][1], &EvaluateKBBKN);
+ add(z[W][KNIGHT][1] ^ z[B][BISHOP][2], &EvaluateKNKBB);
add(z[W][KNIGHT][1] ^ z[W][PAWN][1], W, &ScaleKNPK);
add(z[B][KNIGHT][1] ^ z[B][PAWN][1], B, &ScaleKKNP);
add(z[W][ROOK][1] ^ z[W][PAWN][1] ^ z[B][ROOK][1] ^ z[B][PAWN][1] ^ z[B][PAWN][2], B, &ScaleKRPKRPP);
}
-void EndgameFunctions::add(Key k, EndgameEvaluationFunction* f) {
+void EndgameFunctions::add(Key k, EndgameEvaluationFunctionBase* f) {
- EEFmap.insert(std::pair<Key, EndgameEvaluationFunction*>(k, f));
+ EEFmap.insert(std::pair<Key, EndgameEvaluationFunctionBase*>(k, f));
}
-void EndgameFunctions::add(Key k, Color c, ScalingFunction* f) {
+void EndgameFunctions::add(Key k, Color c, EndgameScalingFunctionBase* f) {
ScalingInfo s = {c, f};
ESFmap.insert(std::pair<Key, ScalingInfo>(k, s));
}
-EndgameEvaluationFunction* EndgameFunctions::getEEF(Key key) const {
+EndgameEvaluationFunctionBase* EndgameFunctions::getEEF(Key key) const {
- std::map<Key, EndgameEvaluationFunction*>::const_iterator it(EEFmap.find(key));
+ std::map<Key, EndgameEvaluationFunctionBase*>::const_iterator it(EEFmap.find(key));
return (it != EEFmap.end() ? it->second : NULL);
}
-ScalingFunction* EndgameFunctions::getESF(Key key, Color* c) const {
+EndgameScalingFunctionBase* EndgameFunctions::getESF(Key key, Color* c) const {
std::map<Key, ScalingInfo>::const_iterator it(ESFmap.find(key));
if (it == ESFmap.end())