mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 01:03:09 +00:00
Speed up polynomial material imbalance loop
Access pos.piece_count() only once and avoid some branches in the inner loop. Profiling with VTune shows a 20% speed improvement in get_material_info(), and it is also a bit more cleaned up this way ;-) No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
aa925a0e29
commit
339bb8a524
1 changed files with 11 additions and 12 deletions
|
@ -263,8 +263,10 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate the material balance
|
// Evaluate the material balance
|
||||||
|
const int pieceCount[2][6] = { { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
|
||||||
const int bishopsPair_count[2] = { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(BLACK, BISHOP) > 1 };
|
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) } };
|
||||||
Color c, them;
|
Color c, them;
|
||||||
int sign;
|
int sign;
|
||||||
int matValue = 0;
|
int matValue = 0;
|
||||||
|
@ -297,29 +299,26 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||||
// Redundancy of major pieces, formula based on Kaufman's paper
|
// Redundancy of major pieces, formula based on Kaufman's paper
|
||||||
// "The Evaluation of Material Imbalances in Chess"
|
// "The Evaluation of Material Imbalances in Chess"
|
||||||
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
|
||||||
if (pos.piece_count(c, ROOK) >= 1)
|
if (pieceCount[c][ROOK] >= 1)
|
||||||
matValue -= sign * ((pos.piece_count(c, ROOK) - 1) * RedundantRookPenalty + pos.piece_count(c, QUEEN) * RedundantQueenPenalty);
|
matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);
|
||||||
|
|
||||||
// Second-degree polynomial material imbalance by Tord Romstad
|
// Second-degree polynomial material imbalance by Tord Romstad
|
||||||
//
|
//
|
||||||
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
// We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",
|
||||||
// this allow us to be more flexible in defining bishop pair bonuses.
|
// this allow us to be more flexible in defining bishop pair bonuses.
|
||||||
them = opposite_color(c);
|
them = opposite_color(c);
|
||||||
for (PieceType pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)
|
||||||
{
|
{
|
||||||
int c1, c2, c3;
|
int c1 = sign * pieceCount[c][pt1];
|
||||||
c1 = sign * (pt1 != NO_PIECE_TYPE ? pos.piece_count(c, pt1) : bishopsPair_count[c]);
|
|
||||||
if (!c1)
|
if (!c1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
matValue += c1 * LinearCoefficients[pt1];
|
matValue += c1 * LinearCoefficients[pt1];
|
||||||
|
|
||||||
for (PieceType pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
|
||||||
{
|
{
|
||||||
c2 = (pt2 != NO_PIECE_TYPE ? pos.piece_count(c, pt2) : bishopsPair_count[c]);
|
matValue += c1 * pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2];
|
||||||
c3 = (pt2 != NO_PIECE_TYPE ? pos.piece_count(them, pt2) : bishopsPair_count[them]);
|
matValue += c1 * pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
||||||
matValue += c1 * c2 * QuadraticCoefficientsSameColor[pt1][pt2];
|
|
||||||
matValue += c1 * c3 * QuadraticCoefficientsOppositeColor[pt1][pt2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue