Skip to content
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
21 changes: 21 additions & 0 deletions src/core/attack_generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,25 @@ constexpr uint64_t getAllAttacks(const BitBoard& board)
return attacks;
}

/* computes discovered attacks based on the given position
* NOTE: queen attacks are not included - it's only rook and bishops */
template<Player player>
constexpr uint64_t getDiscoveredAttacks(const BitBoard& board, BoardPosition pos)
{
constexpr Player opponent = nextPlayer(player);
constexpr Piece opponentRook = opponent == PlayerWhite ? WhiteRook : BlackRook;
constexpr Piece opponentBishop = opponent == PlayerWhite ? WhiteBishop : BlackBishop;

const uint64_t occupancy = board.occupation[Both];

const uint64_t rookAttacks = movegen::getRookMoves(pos, occupancy);
const uint64_t bishopAttacks = movegen::getBishopMoves(pos, occupancy);

const uint64_t rooks = board.pieces[opponentRook] & ~rookAttacks;
const uint64_t bishops = board.pieces[opponentBishop] & ~bishopAttacks;

return (rooks & movegen::getRookMoves(pos, occupancy & ~rookAttacks))
| (bishops & movegen::getBishopMoves(pos, occupancy & ~bishopAttacks));
}

}
Loading
Loading