- Color c, them;
- int sign, pt1, pt2, pc;
- int v, vv, matValue = 0;
-
- for (c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign)
- {
- // No pawns makes it difficult to win, even with a material advantage
- if ( pos.piece_count(c, PAWN) == 0
- && pos.non_pawn_material(c) - pos.non_pawn_material(opposite_color(c)) <= BishopValueMidgame)
- {
- if ( pos.non_pawn_material(c) == pos.non_pawn_material(opposite_color(c))
- || pos.non_pawn_material(c) < RookValueMidgame)
- mi->factor[c] = 0;
- else
- {
- switch (pos.piece_count(c, BISHOP)) {
- case 2:
- mi->factor[c] = 32;
- break;
- case 1:
- mi->factor[c] = 12;
- break;
- case 0:
- mi->factor[c] = 6;
- break;
- }
- }
- }
-
- // Redundancy of major pieces, formula based on Kaufman's paper
- // "The Evaluation of Material Imbalances in Chess"
- // http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
- if (pieceCount[c][ROOK] >= 1)
- matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
-
- them = opposite_color(c);
- v = 0;
-
- // Second-degree polynomial material imbalance by Tord Romstad
- //
- // 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.
- for (pt1 = PIECE_TYPE_NONE; pt1 <= QUEEN; pt1++)
- {
- pc = pieceCount[c][pt1];
- if (!pc)
- continue;
-
- vv = LinearCoefficients[pt1];
-
- for (pt2 = PIECE_TYPE_NONE; pt2 <= pt1; pt2++)
- vv += pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2]
- + pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
-
- v += pc * vv;
- }
- matValue += sign * v;
- }
- mi->value = (int16_t)(matValue / 16);