mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Group common evaluate code
This removes code redundancy but perhaps impact performance due to uninlining. Testing for regression is needed. For now aim to best code readibility. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
7dd0c39714
commit
853ce65f17
1 changed files with 35 additions and 48 deletions
|
@ -571,6 +571,29 @@ void read_weights(Color sideToMove) {
|
|||
|
||||
namespace {
|
||||
|
||||
// evaluate_common() computes terms common to all pieces attack
|
||||
|
||||
int evaluate_common(const Position&p, const Bitboard& b, Color us, EvalInfo& ei,
|
||||
int AttackWeight, const Value* mgBonus, const Value* egBonus) {
|
||||
|
||||
Color them = opposite_color(us);
|
||||
|
||||
// King attack
|
||||
if(b & ei.attackZone[us]) {
|
||||
ei.attackCount[us]++;
|
||||
ei.attackWeight[us] += AttackWeight;
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
if(bb) ei.attacked[us] += count_1s_max_15(bb);
|
||||
}
|
||||
|
||||
// Mobility
|
||||
int mob = count_1s_max_15(b & ~p.pieces_of_color(us));
|
||||
ei.mgMobility += Sign[us] * mgBonus[mob];
|
||||
ei.egMobility += Sign[us] * egBonus[mob];
|
||||
|
||||
return mob;
|
||||
}
|
||||
|
||||
// evaluate_knight() assigns bonuses and penalties to a knight of a given
|
||||
// color on a given square.
|
||||
|
||||
|
@ -580,18 +603,9 @@ namespace {
|
|||
Bitboard b = p.knight_attacks(s);
|
||||
ei.attackedBy[us][KNIGHT] |= b;
|
||||
|
||||
// King attack
|
||||
if(b & ei.attackZone[us]) {
|
||||
ei.attackCount[us]++;
|
||||
ei.attackWeight[us] += KnightAttackWeight;
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
if(bb) ei.attacked[us] += count_1s_max_15(bb);
|
||||
}
|
||||
|
||||
// Mobility
|
||||
int mob = count_1s_max_15(b & ~p.pieces_of_color(us));
|
||||
ei.mgMobility += Sign[us] * MidgameKnightMobilityBonus[mob];
|
||||
ei.egMobility += Sign[us] * EndgameKnightMobilityBonus[mob];
|
||||
// King attack and mobility
|
||||
evaluate_common(p, b, us, ei, KnightAttackWeight,
|
||||
MidgameKnightMobilityBonus, EndgameKnightMobilityBonus);
|
||||
|
||||
// Knight outposts:
|
||||
if(p.square_is_weak(s, them)) {
|
||||
|
@ -628,18 +642,9 @@ namespace {
|
|||
|
||||
ei.attackedBy[us][BISHOP] |= b;
|
||||
|
||||
// King attack
|
||||
if(b & ei.attackZone[us]) {
|
||||
ei.attackCount[us]++;
|
||||
ei.attackWeight[us] += BishopAttackWeight;
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
if(bb) ei.attacked[us] += count_1s_max_15(bb);
|
||||
}
|
||||
|
||||
// Mobility:
|
||||
int mob = count_1s_max_15(b & ~p.pieces_of_color(us));
|
||||
ei.mgMobility += Sign[us] * MidgameBishopMobilityBonus[mob];
|
||||
ei.egMobility += Sign[us] * EndgameBishopMobilityBonus[mob];
|
||||
// King attack and mobility
|
||||
evaluate_common(p, b, us, ei, BishopAttackWeight,
|
||||
MidgameBishopMobilityBonus, EndgameBishopMobilityBonus);
|
||||
|
||||
// Bishop outposts:
|
||||
if(p.square_is_weak(s, them)) {
|
||||
|
@ -697,18 +702,9 @@ namespace {
|
|||
rook_attacks_bb(s, p.occupied_squares() & ~p.rooks_and_queens(us));
|
||||
ei.attackedBy[us][ROOK] |= b;
|
||||
|
||||
// King attack
|
||||
if(b & ei.attackZone[us]) {
|
||||
ei.attackCount[us]++;
|
||||
ei.attackWeight[us] += RookAttackWeight;
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
if(bb) ei.attacked[us] += count_1s_max_15(bb);
|
||||
}
|
||||
|
||||
// Mobility
|
||||
int mob = count_1s_max_15(b & ~p.pieces_of_color(us));
|
||||
ei.mgMobility += Sign[us] * MidgameRookMobilityBonus[mob];
|
||||
ei.egMobility += Sign[us] * EndgameRookMobilityBonus[mob];
|
||||
// King attack and mobility
|
||||
int mob = evaluate_common(p, b, us, ei, RookAttackWeight,
|
||||
MidgameRookMobilityBonus, EndgameRookMobilityBonus);
|
||||
|
||||
// Penalize rooks which are trapped inside a king which has lost the
|
||||
// right to castle:
|
||||
|
@ -756,18 +752,9 @@ namespace {
|
|||
Bitboard b = p.queen_attacks(s);
|
||||
ei.attackedBy[us][QUEEN] |= b;
|
||||
|
||||
// King attack
|
||||
if(b & ei.attackZone[us]) {
|
||||
ei.attackCount[us]++;
|
||||
ei.attackWeight[us] += QueenAttackWeight;
|
||||
Bitboard bb = (b & ei.attackedBy[them][KING]);
|
||||
if(bb) ei.attacked[us] += count_1s_max_15(bb);
|
||||
}
|
||||
|
||||
// Mobility
|
||||
int mob = count_1s(b & ~p.pieces_of_color(us));
|
||||
ei.mgMobility += Sign[us] * MidgameQueenMobilityBonus[mob];
|
||||
ei.egMobility += Sign[us] * EndgameQueenMobilityBonus[mob];
|
||||
// King attack and mobility
|
||||
evaluate_common(p, b, us, ei, QueenAttackWeight,
|
||||
MidgameQueenMobilityBonus, EndgameQueenMobilityBonus);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue