mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Split evaluate_outposts from evaluate_common
This is an old patch, was part of a series, but is good also alone as a cleanup. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
2f760cdf8d
commit
48c95706c8
1 changed files with 43 additions and 39 deletions
|
@ -538,22 +538,19 @@ void read_weights(Color us) {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// evaluate_common() computes terms common to all pieces attack
|
// evaluate_mobility() computes mobility and attacks for every piece
|
||||||
|
|
||||||
template<PieceType Piece, bool HasPopCnt>
|
template<PieceType Piece, bool HasPopCnt>
|
||||||
int evaluate_common(const Position& p, const Bitboard& b, Color us, EvalInfo& ei, Square s = SQ_NONE) {
|
int evaluate_mobility(const Position& p, const Bitboard& b, Color us, Color them, EvalInfo& ei) {
|
||||||
|
|
||||||
static const int AttackWeight[] = { 0, 0, KnightAttackWeight, BishopAttackWeight, RookAttackWeight, QueenAttackWeight };
|
static const int AttackWeight[] = { 0, 0, KnightAttackWeight, BishopAttackWeight, RookAttackWeight, QueenAttackWeight };
|
||||||
static const Value* MgBonus[] = { 0, 0, MidgameKnightMobilityBonus, MidgameBishopMobilityBonus, MidgameRookMobilityBonus, MidgameQueenMobilityBonus };
|
static const Value* MgBonus[] = { 0, 0, MidgameKnightMobilityBonus, MidgameBishopMobilityBonus, MidgameRookMobilityBonus, MidgameQueenMobilityBonus };
|
||||||
static const Value* EgBonus[] = { 0, 0, EndgameKnightMobilityBonus, EndgameBishopMobilityBonus, EndgameRookMobilityBonus, EndgameQueenMobilityBonus };
|
static const Value* EgBonus[] = { 0, 0, EndgameKnightMobilityBonus, EndgameBishopMobilityBonus, EndgameRookMobilityBonus, EndgameQueenMobilityBonus };
|
||||||
static const Value* OutpostBonus[] = { 0, 0, KnightOutpostBonus, BishopOutpostBonus, 0, 0 };
|
|
||||||
|
|
||||||
Color them = opposite_color(us);
|
|
||||||
|
|
||||||
// Update attack info
|
// Update attack info
|
||||||
ei.attackedBy[us][Piece] |= b;
|
ei.attackedBy[us][Piece] |= b;
|
||||||
|
|
||||||
// King attack
|
// King attacks
|
||||||
if (b & ei.kingZone[us])
|
if (b & ei.kingZone[us])
|
||||||
{
|
{
|
||||||
ei.kingAttackersCount[us]++;
|
ei.kingAttackersCount[us]++;
|
||||||
|
@ -572,29 +569,32 @@ namespace {
|
||||||
|
|
||||||
ei.mgMobility += Sign[us] * MgBonus[Piece][mob];
|
ei.mgMobility += Sign[us] * MgBonus[Piece][mob];
|
||||||
ei.egMobility += Sign[us] * EgBonus[Piece][mob];
|
ei.egMobility += Sign[us] * EgBonus[Piece][mob];
|
||||||
|
return mob;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// evaluate_outposts() evaluates bishop and knight outposts squares
|
||||||
|
|
||||||
|
template<PieceType Piece>
|
||||||
|
void evaluate_outposts(const Position& p, Color us, Color them, EvalInfo& ei, Square s) {
|
||||||
|
|
||||||
// Bishop and Knight outposts
|
|
||||||
if ( (Piece == BISHOP || Piece == KNIGHT) // compile time condition
|
|
||||||
&& p.square_is_weak(s, them))
|
|
||||||
{
|
|
||||||
// Initial bonus based on square
|
// Initial bonus based on square
|
||||||
Value v, bonus;
|
Value bonus = (Piece == BISHOP ? BishopOutpostBonus[relative_square(us, s)]
|
||||||
v = bonus = OutpostBonus[Piece][relative_square(us, s)];
|
: KnightOutpostBonus[relative_square(us, s)]);
|
||||||
|
|
||||||
// Increase bonus if supported by pawn, especially if the opponent has
|
// Increase bonus if supported by pawn, especially if the opponent has
|
||||||
// no minor piece which can exchange the outpost piece
|
// no minor piece which can exchange the outpost piece
|
||||||
if (v && (p.pawn_attacks(them, s) & p.pawns(us)))
|
if (bonus && (p.pawn_attacks(them, s) & p.pawns(us)))
|
||||||
{
|
{
|
||||||
bonus += v / 2;
|
if ( p.knights(them) == EmptyBoardBB
|
||||||
if ( p.piece_count(them, KNIGHT) == 0
|
|
||||||
&& (SquaresByColorBB[square_color(s)] & p.bishops(them)) == EmptyBoardBB)
|
&& (SquaresByColorBB[square_color(s)] & p.bishops(them)) == EmptyBoardBB)
|
||||||
bonus += v;
|
bonus += bonus + bonus / 2;
|
||||||
|
else
|
||||||
|
bonus += bonus / 2;
|
||||||
}
|
}
|
||||||
ei.mgValue += Sign[us] * bonus;
|
ei.mgValue += Sign[us] * bonus;
|
||||||
ei.egValue += Sign[us] * bonus;
|
ei.egValue += Sign[us] * bonus;
|
||||||
}
|
}
|
||||||
return mob;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// evaluate_pieces<>() assigns bonuses and penalties to the pieces of a given
|
// evaluate_pieces<>() assigns bonuses and penalties to the pieces of a given
|
||||||
|
@ -605,9 +605,9 @@ namespace {
|
||||||
|
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
Square s, ksq;
|
Square s, ksq;
|
||||||
Color them;
|
|
||||||
int mob;
|
int mob;
|
||||||
File f;
|
File f;
|
||||||
|
Color them = opposite_color(us);
|
||||||
|
|
||||||
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
||||||
{
|
{
|
||||||
|
@ -619,9 +619,15 @@ namespace {
|
||||||
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.queens(us));
|
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.queens(us));
|
||||||
else if (Piece == ROOK)
|
else if (Piece == ROOK)
|
||||||
b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.rooks_and_queens(us));
|
b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.rooks_and_queens(us));
|
||||||
|
else
|
||||||
|
assert(false);
|
||||||
|
|
||||||
// Attacks, mobility and outposts
|
// Attacks and mobility
|
||||||
mob = evaluate_common<Piece, HasPopCnt>(pos, b, us, ei, s);
|
mob = evaluate_mobility<Piece, HasPopCnt>(pos, b, us, them, ei);
|
||||||
|
|
||||||
|
// Bishop and knight outposts squares
|
||||||
|
if ((Piece == BISHOP || Piece == KNIGHT) && pos.square_is_weak(s, them))
|
||||||
|
evaluate_outposts<Piece>(pos, us, them, ei, s);
|
||||||
|
|
||||||
// Special patterns: trapped bishops on a7/h7/a2/h2
|
// Special patterns: trapped bishops on a7/h7/a2/h2
|
||||||
// and trapped bishops on a1/h1/a8/h8 in Chess960.
|
// and trapped bishops on a1/h1/a8/h8 in Chess960.
|
||||||
|
@ -637,8 +643,6 @@ namespace {
|
||||||
if (Piece == ROOK || Piece == QUEEN)
|
if (Piece == ROOK || Piece == QUEEN)
|
||||||
{
|
{
|
||||||
// Queen or rook on 7th rank
|
// Queen or rook on 7th rank
|
||||||
them = opposite_color(us);
|
|
||||||
|
|
||||||
if ( relative_rank(us, s) == RANK_7
|
if ( relative_rank(us, s) == RANK_7
|
||||||
&& relative_rank(us, pos.king_square(them)) == RANK_8)
|
&& relative_rank(us, pos.king_square(them)) == RANK_8)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue