Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bonus for pawn supporters #113

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions Bit-Genie/src/attacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,42 @@

namespace Attacks
{
// Initializes magic bitboard arrays. Should be called before
// using Attacks::bishop / Attacks::rook
inline void init()
{
initmagicmoves();
}

// Return a bitboard of the knight attacks for a
// knight situated on the given square
inline uint64_t pawn(uint64_t pawns, Color side)
{
uint64_t forward = side == White ? shift<Direction::north>(pawns) : shift<Direction::south>(pawns);
return shift<Direction::west>(forward) | shift<Direction::east>(forward);
}

inline uint64_t knight(Square sq)
{
return BitMask::knight_attacks[sq];
}

// Return a bitboard of the king attacks for a
// king situated on the given square
inline uint64_t king(Square sq)
{
return BitMask::king_attacks[sq];
}

// Return a bitboard of the bishop attacks for a
// bishop situated on the given square
// Diagonal and anti-diagonal attacks with respect to the current occupancy
inline uint64_t bishop(Square sq, uint64_t occ)
{
return Bmagic(sq, occ);
}

// Return a bitboard of the rook attacks for a
// rook situated on the given square
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
inline uint64_t rook(Square sq, uint64_t occ)
{
return Rmagic(sq, occ);
}

// Return a bitboard of the queen attacks for a
// queen situated on the given square

// Diagonal and anti-diagonal attacks with respect to the current occupancy
// Vertical (file) and horizontal(rank) attacks with respect to the current occupancy
inline uint64_t queen(Square sq, uint64_t occ)
{
return Qmagic(sq, occ);
}

// Check whether the given square is directly attacked by any of the given color's
//pieces in the position.
inline bool square_attacked(Position const &position, Square sq, Color enemy, uint64_t occupancy)
{
assert(is_ok(sq));
Expand All @@ -86,8 +73,6 @@ namespace Attacks
return (BitMask::pawn_attacks[!enemy][sq] & pawns) || (bishop(sq, occupancy) & bishops) || (rook(sq, occupancy) & rooks) || (knight(sq) & knights) || (king(sq) & kings);
}

// Return a bitboard of all the attackers to the given square, both black and white pieces
// are included.
inline uint64_t attackers_to_sq(Position const &position, Square sq)
{
uint64_t occ = position.total_occupancy();
Expand All @@ -105,7 +90,6 @@ namespace Attacks
return square_attacked(position, sq, enemy, position.total_occupancy());
}

// Check for the piece and generate (no pawns)
inline uint64_t generate(PieceType piece, Square sq, uint64_t occ)
{
switch (piece)
Expand Down
19 changes: 18 additions & 1 deletion Bit-Genie/src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,20 @@ static inline int is_ocb(Position const& position)
&& popcount64(bishops & dark_squares) == 1;
}

template<Color us>
static int evaluate_pawn_structure(Position const& position)
{
int score = 0;

uint64_t pawns = position.pieces.get_piece_bb<Pawn>(us);

int supported = popcount64(pawns & Attacks::pawn(pawns, !us));
score += supported * PawnEval::support;
TRACE_COUNT(support, supported);

return score;
}

int scale_factor(Position const& position, int eval)
{
if (is_ocb(position))
Expand Down Expand Up @@ -450,7 +464,10 @@ int eval_position(Position const &position)
score += evaluate_piece<King >(position, data, evaluate_king);

score += evaluate_control<White>(data);
score -= evaluate_control<Black>(data);
score -= evaluate_control<Black>(data);

score += evaluate_pawn_structure<White>(position);
score -= evaluate_pawn_structure<Black>(position);

TRACE_VAL(eval, score);

Expand Down
Loading