+
+ // Generic scaling functions that refer to more then one material
+ // distribution. Should be probed after the specialized ones.
+ // Note that these ones don't return after setting the function.
+ if ( pos.non_pawn_material(WHITE) == BishopValueMidgame
+ && pos.piece_count(WHITE, BISHOP) == 1
+ && pos.piece_count(WHITE, PAWN) >= 1)
+ mi->scalingFunction[WHITE] = &ScaleKBPsK;
+
+ if ( pos.non_pawn_material(BLACK) == BishopValueMidgame
+ && pos.piece_count(BLACK, BISHOP) == 1
+ && pos.piece_count(BLACK, PAWN) >= 1)
+ mi->scalingFunction[BLACK] = &ScaleKKBPs;
+
+ 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] = &ScaleKQKRPs;
+
+ 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] = &ScaleKRPsKQ;
+
+ 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)
+ {
+ // This is a special case because we set scaling functions
+ // for both colors instead of only one.
+ mi->scalingFunction[WHITE] = &ScaleKPKPw;
+ mi->scalingFunction[BLACK] = &ScaleKPKPb;
+ }