- 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?
- //
- // The code below is rather messy, and it could easily get worse later,
- // if we decide to add more special cases. We face problems when there
- // are several conflicting applicable scaling functions and we need to
- // decide which one to use.
- SF* sf;
-
- if ((sf = funcs->get<SF>(key)) != NULL)
- {
- mi->scalingFunction[sf->color()] = sf;
- return mi;
- }
-
- if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
- && pos.piece_count(WHITE, BISHOP) == 1
- && pos.piece_count(WHITE, PAWN) >= 1)
- mi->scalingFunction[WHITE] = &ScaleKBPK;
-
- if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
- && pos.piece_count(BLACK, BISHOP) == 1
- && pos.piece_count(BLACK, PAWN) >= 1)
- mi->scalingFunction[BLACK] = &ScaleKKBP;
-
- if ( pos.piece_count(WHITE, PAWN) == 0
- && pos.non_pawn_material(WHITE) == QueenValueMidgame
- && pos.piece_count(WHITE, QUEEN) == 1
- && pos.piece_count(BLACK, ROOK) == 1
- && pos.piece_count(BLACK, PAWN) >= 1)
- mi->scalingFunction[WHITE] = &ScaleKQKRP;
-
- else if ( pos.piece_count(BLACK, PAWN) == 0
- && pos.non_pawn_material(BLACK) == QueenValueMidgame
- && pos.piece_count(BLACK, QUEEN) == 1
- && pos.piece_count(WHITE, ROOK) == 1
- && pos.piece_count(WHITE, PAWN) >= 1)
- mi->scalingFunction[BLACK] = &ScaleKRPKQ;
-
- if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
- {
- if (pos.piece_count(BLACK, PAWN) == 0)
- {
- assert(pos.piece_count(WHITE, PAWN) >= 2);
- mi->scalingFunction[WHITE] = &ScaleKPsK;
- }
- else if (pos.piece_count(WHITE, PAWN) == 0)
- {
- assert(pos.piece_count(BLACK, PAWN) >= 2);
- mi->scalingFunction[BLACK] = &ScaleKKPs;
- }
- else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
- {
- mi->scalingFunction[WHITE] = &ScaleKPKPw;
- mi->scalingFunction[BLACK] = &ScaleKPKPb;
- }