- 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;
- }
- }
+ // Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
+ // for the bishop pair "extended piece", this allow us to be more flexible
+ // in defining bishop pair bonuses.
+ const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
+ { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
+ pos.piece_count(WHITE, BISHOP) , pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
+ { pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
+ pos.piece_count(BLACK, BISHOP) , pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
+
+ e->value = (int16_t)((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
+ return e;
+}