1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 00:33:09 +00:00

Add also outposts evaluation in common code

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-24 10:12:18 +02:00
parent 853ce65f17
commit 3263ee8557

View file

@ -574,16 +574,19 @@ namespace {
// evaluate_common() computes terms common to all pieces attack // evaluate_common() computes terms common to all pieces attack
int evaluate_common(const Position&p, const Bitboard& b, Color us, EvalInfo& ei, int evaluate_common(const Position&p, const Bitboard& b, Color us, EvalInfo& ei,
int AttackWeight, const Value* mgBonus, const Value* egBonus) { int AttackWeight, const Value* mgBonus, const Value* egBonus,
Square s = SQ_NONE, const Value* OutpostBonus = NULL) {
Color them = opposite_color(us); Color them = opposite_color(us);
// King attack // King attack
if(b & ei.attackZone[us]) { if (b & ei.attackZone[us])
{
ei.attackCount[us]++; ei.attackCount[us]++;
ei.attackWeight[us] += AttackWeight; ei.attackWeight[us] += AttackWeight;
Bitboard bb = (b & ei.attackedBy[them][KING]); Bitboard bb = (b & ei.attackedBy[them][KING]);
if(bb) ei.attacked[us] += count_1s_max_15(bb); if (bb)
ei.attacked[us] += count_1s_max_15(bb);
} }
// Mobility // Mobility
@ -591,43 +594,40 @@ namespace {
ei.mgMobility += Sign[us] * mgBonus[mob]; ei.mgMobility += Sign[us] * mgBonus[mob];
ei.egMobility += Sign[us] * egBonus[mob]; ei.egMobility += Sign[us] * egBonus[mob];
// Bishop and Knight outposts
if (!OutpostBonus || !p.square_is_weak(s, them))
return mob;
// Initial bonus based on square
Value v, bonus;
v = bonus = OutpostBonus[relative_square(us, s)];
// Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece
if (v && (p.pawn_attacks(them, s) & p.pawns(us)))
{
bonus += v / 2;
if ( p.knight_count(them) == 0
&& (SquaresByColorBB[square_color(s)] & p.bishops(them)) == EmptyBoardBB)
bonus += v;
}
ei.mgValue += Sign[us] * bonus;
ei.egValue += Sign[us] * bonus;
return mob; return mob;
} }
// evaluate_knight() assigns bonuses and penalties to a knight of a given // evaluate_knight() assigns bonuses and penalties to a knight of a given
// color on a given square. // color on a given square.
void evaluate_knight(const Position &p, Square s, Color us, EvalInfo &ei) { void evaluate_knight(const Position &p, Square s, Color us, EvalInfo &ei) {
Color them = opposite_color(us);
Bitboard b = p.knight_attacks(s); Bitboard b = p.knight_attacks(s);
ei.attackedBy[us][KNIGHT] |= b; ei.attackedBy[us][KNIGHT] |= b;
// King attack and mobility // King attack, mobility and outposts
evaluate_common(p, b, us, ei, KnightAttackWeight, evaluate_common(p, b, us, ei, KnightAttackWeight, MidgameKnightMobilityBonus,
MidgameKnightMobilityBonus, EndgameKnightMobilityBonus); EndgameKnightMobilityBonus, s, KnightOutpostBonus);
// Knight outposts:
if(p.square_is_weak(s, them)) {
Value v, bonus;
// Initial bonus based on square:
v = bonus = KnightOutpostBonus[relative_square(us, s)];
// Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece:
if(v && p.pawn_attacks(them, s) & p.pawns(us)) {
bonus += v/2;
if(p.knight_count(them) == 0 &&
(SquaresByColorBB[square_color(s)] &
p.bishops(them)) == EmptyBoardBB) {
bonus += v;
}
}
ei.mgValue += Sign[us] * bonus;
ei.egValue += Sign[us] * bonus;
}
} }
@ -636,37 +636,12 @@ namespace {
void evaluate_bishop(const Position &p, Square s, Color us, EvalInfo &ei) { void evaluate_bishop(const Position &p, Square s, Color us, EvalInfo &ei) {
Color them = opposite_color(us); Bitboard b = bishop_attacks_bb(s, p.occupied_squares() & ~p.queens(us));
Bitboard b =
bishop_attacks_bb(s, p.occupied_squares() & ~p.queens(us));
ei.attackedBy[us][BISHOP] |= b; ei.attackedBy[us][BISHOP] |= b;
// King attack and mobility // King attack, mobility and outposts
evaluate_common(p, b, us, ei, BishopAttackWeight, evaluate_common(p, b, us, ei, BishopAttackWeight, MidgameBishopMobilityBonus,
MidgameBishopMobilityBonus, EndgameBishopMobilityBonus); EndgameBishopMobilityBonus, s, BishopOutpostBonus);
// Bishop outposts:
if(p.square_is_weak(s, them)) {
Value v, bonus;
// Initial bonus based on square:
v = bonus = BishopOutpostBonus[relative_square(us, s)];
// Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece:
if(v && p.pawn_attacks(them, s) & p.pawns(us)) {
bonus += v/2;
if(p.knight_count(them) == 0 &&
(SquaresByColorBB[square_color(s)] &
p.bishops(them)) == EmptyBoardBB) {
bonus += v;
}
}
ei.mgValue += Sign[us] * bonus;
ei.egValue += Sign[us] * bonus;
}
} }
@ -698,13 +673,12 @@ namespace {
} }
//Bitboard b = p.rook_attacks(s); //Bitboard b = p.rook_attacks(s);
Bitboard b = Bitboard b = rook_attacks_bb(s, p.occupied_squares() & ~p.rooks_and_queens(us));
rook_attacks_bb(s, p.occupied_squares() & ~p.rooks_and_queens(us));
ei.attackedBy[us][ROOK] |= b; ei.attackedBy[us][ROOK] |= b;
// King attack and mobility // King attack and mobility
int mob = evaluate_common(p, b, us, ei, RookAttackWeight, int mob = evaluate_common(p, b, us, ei, RookAttackWeight, MidgameRookMobilityBonus,
MidgameRookMobilityBonus, EndgameRookMobilityBonus); EndgameRookMobilityBonus);
// Penalize rooks which are trapped inside a king which has lost the // Penalize rooks which are trapped inside a king which has lost the
// right to castle: // right to castle:
@ -753,8 +727,8 @@ namespace {
ei.attackedBy[us][QUEEN] |= b; ei.attackedBy[us][QUEEN] |= b;
// King attack and mobility // King attack and mobility
evaluate_common(p, b, us, ei, QueenAttackWeight, evaluate_common(p, b, us, ei, QueenAttackWeight, MidgameQueenMobilityBonus,
MidgameQueenMobilityBonus, EndgameQueenMobilityBonus); EndgameQueenMobilityBonus);
} }