- const int pieceCount[2][8] = {
- { 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) } };
-
- mi->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
- return mi;
-}
-
-
-/// MaterialInfoTable::imbalance() calculates imbalance comparing piece count of each
-/// piece type for both colors.
-
-template<Color Us>
-int MaterialInfoTable::imbalance(const int pieceCount[][8]) {
-
- const Color Them = (Us == WHITE ? BLACK : WHITE);
-
- int pt1, pt2, pc, v;
- int value = 0;
-
- // Redundancy of major pieces, formula based on Kaufman's paper
- // "The Evaluation of Material Imbalances in Chess"
- if (pieceCount[Us][ROOK] > 0)
- value -= RedundantRookPenalty * (pieceCount[Us][ROOK] - 1)
- + RedundantQueenPenalty * pieceCount[Us][QUEEN];
-
- // Second-degree polynomial material imbalance by Tord Romstad
- for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
- {
- pc = pieceCount[Us][pt1];
- if (!pc)
- continue;
-
- v = LinearCoefficients[pt1];
-
- for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
- v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2]
- + QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2];
-
- value += pc * v;
- }
- return value;
+ const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
+ { pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
+ pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
+ { pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
+ pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
+
+ e->value = (int16_t)((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
+ return e;