Rewrite some bitboard init code
And move the static function Position::attacks_from() to bitboard code renaming it attacks_bb() No functional change.pull/358/head
parent
6ea5dc294c
commit
034a2b04f2
|
@ -212,24 +212,23 @@ void Bitboards::init() {
|
|||
init_magics(RTable, RAttacks, RMagics, RMasks, RShifts, RDeltas, magic_index<ROOK>);
|
||||
init_magics(BTable, BAttacks, BMagics, BMasks, BShifts, BDeltas, magic_index<BISHOP>);
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
PseudoAttacks[QUEEN][s] = PseudoAttacks[BISHOP][s] = attacks_bb<BISHOP>(s, 0);
|
||||
PseudoAttacks[QUEEN][s] |= PseudoAttacks[ ROOK][s] = attacks_bb< ROOK>(s, 0);
|
||||
}
|
||||
|
||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||
{
|
||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||
|
||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||
if (PseudoAttacks[QUEEN][s1] & s2)
|
||||
{
|
||||
Square delta = (s2 - s1) / square_distance(s1, s2);
|
||||
{
|
||||
Piece pc = (PseudoAttacks[BISHOP][s1] & s2) ? W_BISHOP :
|
||||
(PseudoAttacks[ROOK][s1] & s2) ? W_ROOK : NO_PIECE;
|
||||
|
||||
for (Square s = s1 + delta; s != s2; s += delta)
|
||||
BetweenBB[s1][s2] |= s;
|
||||
if (pc == NO_PIECE)
|
||||
continue;
|
||||
|
||||
PieceType pt = (PseudoAttacks[BISHOP][s1] & s2) ? BISHOP : ROOK;
|
||||
LineBB[s1][s2] = (PseudoAttacks[pt][s1] & PseudoAttacks[pt][s2]) | s1 | s2;
|
||||
}
|
||||
LineBB[s1][s2] = (attacks_bb(pc, s1, 0) & attacks_bb(pc, s2, 0)) | s1 | s2;
|
||||
BetweenBB[s1][s2] = attacks_bb(pc, s1, SquareBB[s2]) & attacks_bb(pc, s2, SquareBB[s1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -254,6 +254,16 @@ inline Bitboard attacks_bb(Square s, Bitboard occ) {
|
|||
return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index<Pt>(s, occ)];
|
||||
}
|
||||
|
||||
inline Bitboard attacks_bb(Piece p, Square s, Bitboard occ) {
|
||||
|
||||
switch (type_of(p))
|
||||
{
|
||||
case BISHOP: return attacks_bb<BISHOP>(s, occ);
|
||||
case ROOK : return attacks_bb<ROOK>(s, occ);
|
||||
case QUEEN : return attacks_bb<BISHOP>(s, occ) | attacks_bb<ROOK>(s, occ);
|
||||
default : return StepAttacksBB[p][s];
|
||||
}
|
||||
}
|
||||
|
||||
/// lsb()/msb() finds the least/most significant bit in a nonzero bitboard.
|
||||
/// pop_lsb() finds and clears the least significant bit in a nonzero bitboard.
|
||||
|
|
|
@ -455,23 +455,6 @@ Bitboard Position::attackers_to(Square s, Bitboard occ) const {
|
|||
}
|
||||
|
||||
|
||||
/// Position::attacks_from() computes a bitboard of all attacks of a given piece
|
||||
/// put in a given square. Slider attacks use occ bitboard as occupancy.
|
||||
|
||||
Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
|
||||
|
||||
assert(is_ok(s));
|
||||
|
||||
switch (type_of(p))
|
||||
{
|
||||
case BISHOP: return attacks_bb<BISHOP>(s, occ);
|
||||
case ROOK : return attacks_bb<ROOK>(s, occ);
|
||||
case QUEEN : return attacks_bb<BISHOP>(s, occ) | attacks_bb<ROOK>(s, occ);
|
||||
default : return StepAttacksBB[p][s];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Position::legal() tests whether a pseudo-legal move is legal
|
||||
|
||||
bool Position::legal(Move m, Bitboard pinned) const {
|
||||
|
@ -672,7 +655,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
|
|||
switch (type_of(m))
|
||||
{
|
||||
case PROMOTION:
|
||||
return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
|
||||
return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
|
||||
|
||||
// En passant capture with check ? We have already handled the case
|
||||
// of direct checks and ordinary discovered check, the only case we
|
||||
|
|
|
@ -114,7 +114,6 @@ public:
|
|||
Bitboard attackers_to(Square s) const;
|
||||
Bitboard attackers_to(Square s, Bitboard occ) const;
|
||||
Bitboard attacks_from(Piece p, Square s) const;
|
||||
static Bitboard attacks_from(Piece p, Square s, Bitboard occ);
|
||||
template<PieceType> Bitboard attacks_from(Square s) const;
|
||||
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
|
||||
|
||||
|
@ -304,7 +303,7 @@ inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
|
|||
}
|
||||
|
||||
inline Bitboard Position::attacks_from(Piece p, Square s) const {
|
||||
return attacks_from(p, s, byTypeBB[ALL_PIECES]);
|
||||
return attacks_bb(p, s, byTypeBB[ALL_PIECES]);
|
||||
}
|
||||
|
||||
inline Bitboard Position::attackers_to(Square s) const {
|
||||
|
|
|
@ -1351,7 +1351,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
|||
return true;
|
||||
|
||||
// Second's destination is defended by the first move's piece
|
||||
Bitboard m1att = pos.attacks_from(pos.piece_on(m1to), m1to, pos.pieces() ^ m2from);
|
||||
Bitboard m1att = attacks_bb(pos.piece_on(m1to), m1to, pos.pieces() ^ m2from);
|
||||
if (m1att & m2to)
|
||||
return true;
|
||||
|
||||
|
@ -1395,7 +1395,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
|||
Piece pc = pos.piece_on(m1from);
|
||||
|
||||
// The moved piece attacks the square 'tto' ?
|
||||
if (pos.attacks_from(pc, m1to, occ) & m2to)
|
||||
if (attacks_bb(pc, m1to, occ) & m2to)
|
||||
return true;
|
||||
|
||||
// Scan for possible X-ray attackers behind the moved piece
|
||||
|
|
Loading…
Reference in New Issue