Instead of pawn_attacks(Color c, Square s) define as
pawn_attacks(Square s, Color c) to be more aligned to
the others attack info functions.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
&& (pos.piece_attacks<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
{
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
&& (pos.piece_attacks<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
{
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
- if (pos.pawn_attacks(strongerSide, rsq) & pos.pieces(PAWN, weakerSide))
+ if (pos.pawn_attacks(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
return ScaleFactor(0);
}
return SCALE_FACTOR_NONE;
return ScaleFactor(0);
}
return SCALE_FACTOR_NONE;
// Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece
// Increase bonus if supported by pawn, especially if the opponent has
// no minor piece which can exchange the outpost piece
- if (bonus && (p.pawn_attacks(them, s) & p.pieces(PAWN, us)))
+ if (bonus && (p.pawn_attacks(s, them) & p.pieces(PAWN, us)))
{
if ( p.pieces(KNIGHT, them) == EmptyBoardBB
&& (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB)
{
if ( p.pieces(KNIGHT, them) == EmptyBoardBB
&& (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB)
b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s);
if (b2 & rank_bb(s))
ebonus += Value(r * 20);
b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s);
if (b2 & rank_bb(s))
ebonus += Value(r * 20);
- else if (pos.pawn_attacks(them, s) & b2)
+ else if (pos.pawn_attacks(s, them) & b2)
ebonus += Value(r * 12);
// If the other side has only a king, check whether the pawn is
ebonus += Value(r * 12);
// If the other side has only a king, check whether the pawn is
// Generate captures of the checking piece
// Pawn captures
// Generate captures of the checking piece
// Pawn captures
- b1 = pos.pawn_attacks(them, checksq) & pos.pieces(PAWN, us) & ~pinned;
+ b1 = pos.pawn_attacks(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
while (b1)
{
from = pop_1st_bit(&b1);
while (b1)
{
from = pop_1st_bit(&b1);
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
{
to = pos.ep_square();
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
{
to = pos.ep_square();
- b1 = pos.pawn_attacks(them, to) & pos.pieces(PAWN, us);
+ b1 = pos.pawn_attacks(to, them) & pos.pieces(PAWN, us);
// The checking pawn cannot be a discovered (bishop) check candidate
// otherwise we were in check also before last double push move.
// The checking pawn cannot be a discovered (bishop) check candidate
// otherwise we were in check also before last double push move.
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
- Bitboard b1 = pawns & pos.pawn_attacks(Them, pos.ep_square());
+ Bitboard b1 = pawns & pos.pawn_attacks(pos.ep_square(), Them);
assert(b1 != EmptyBoardBB);
while (b1)
assert(b1 != EmptyBoardBB);
while (b1)
// Direct checks, single pawn pushes
Bitboard empty = pos.empty_squares();
b2 = move_pawns<Us, DELTA_N>(b1) & empty;
// Direct checks, single pawn pushes
Bitboard empty = pos.empty_squares();
b2 = move_pawns<Us, DELTA_N>(b1) & empty;
- b3 = b2 & pos.pawn_attacks(Them, ksq);
+ b3 = b2 & pos.pawn_attacks(ksq, Them);
SERIALIZE_MOVES_D(b3, -TDELTA_N);
// Direct checks, double pawn pushes
SERIALIZE_MOVES_D(b3, -TDELTA_N);
// Direct checks, double pawn pushes
- b3 = move_pawns<Us, DELTA_N>(b2 & TRank3BB) & empty & pos.pawn_attacks(Them, ksq);
+ b3 = move_pawns<Us, DELTA_N>(b2 & TRank3BB) & empty & pos.pawn_attacks(ksq, Them);
SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
return mlist;
}
SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
return mlist;
}
if ( passed
|| isolated
|| chain
if ( passed
|| isolated
|| chain
- || (pos.pawn_attacks(us, s) & theirPawns)
+ || (pos.pawn_attacks(s, us) & theirPawns)
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
backward = false;
else
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
backward = false;
else
// pawn on neighboring files. We now check whether the pawn is
// backward by looking in the forward direction on the neighboring
// files, and seeing whether we meet a friendly or an enemy pawn first.
// pawn on neighboring files. We now check whether the pawn is
// backward by looking in the forward direction on the neighboring
// files, and seeing whether we meet a friendly or an enemy pawn first.
- Bitboard b = pos.pawn_attacks(us, s);
+ Bitboard b = pos.pawn_attacks(s, us);
if (us == WHITE)
{
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
if (us == WHITE)
{
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
Bitboard Position::attacks_to(Square s) const {
Bitboard Position::attacks_to(Square s) const {
- return (pawn_attacks(BLACK, s) & pieces(PAWN, WHITE))
- | (pawn_attacks(WHITE, s) & pieces(PAWN, BLACK))
+ return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE))
+ | (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK))
| (piece_attacks<KNIGHT>(s) & pieces(KNIGHT))
| (piece_attacks<ROOK>(s) & pieces(ROOK, QUEEN))
| (piece_attacks<BISHOP>(s) & pieces(BISHOP, QUEEN))
| (piece_attacks<KNIGHT>(s) & pieces(KNIGHT))
| (piece_attacks<ROOK>(s) & pieces(ROOK, QUEEN))
| (piece_attacks<BISHOP>(s) & pieces(BISHOP, QUEEN))
- case WP: return pawn_attacks_square(WHITE, f, t);
- case BP: return pawn_attacks_square(BLACK, f, t);
+ case WP: return pawn_attacks_square(f, t, WHITE);
+ case BP: return pawn_attacks_square(f, t, BLACK);
case WN: case BN: return piece_attacks_square<KNIGHT>(f, t);
case WB: case BB: return piece_attacks_square<BISHOP>(f, t);
case WR: case BR: return piece_attacks_square<ROOK>(f, t);
case WN: case BN: return piece_attacks_square<KNIGHT>(f, t);
case WB: case BB: return piece_attacks_square<BISHOP>(f, t);
case WR: case BR: return piece_attacks_square<ROOK>(f, t);
- if (bit_is_set(pawn_attacks(them, ksq), to)) // Normal check?
+ if (bit_is_set(pawn_attacks(ksq, them), to)) // Normal check?
return true;
if ( dcCandidates // Discovered check?
return true;
if ( dcCandidates // Discovered check?
else if ( Piece != KING
&& !Slider
else if ( Piece != KING
&& !Slider
- && bit_is_set(Piece == PAWN ? pawn_attacks(opposite_color(sideToMove), ksq) : piece_attacks<Piece>(ksq), to))
+ && bit_is_set(Piece == PAWN ? pawn_attacks(ksq, opposite_color(sideToMove)) : piece_attacks<Piece>(ksq), to))
set_bit(pCheckersBB, to);
// Discovery checks
set_bit(pCheckersBB, to);
// Discovery checks
// Set en passant square, only if moved pawn can be captured
if (abs(int(to) - int(from)) == 16)
{
// Set en passant square, only if moved pawn can be captured
if (abs(int(to) - int(from)) == 16)
{
- if (pawn_attacks(us, from + (us == WHITE ? DELTA_N : DELTA_S)) & pieces(PAWN, them))
+ if (pawn_attacks(from + (us == WHITE ? DELTA_N : DELTA_S), us) & pieces(PAWN, them))
{
st->epSquare = Square((int(from) + int(to)) / 2);
key ^= zobEp[st->epSquare];
{
st->epSquare = Square((int(from) + int(to)) / 2);
key ^= zobEp[st->epSquare];
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
| (piece_attacks<KNIGHT>(to) & pieces(KNIGHT))
| (piece_attacks<KING>(to) & pieces(KING))
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
| (piece_attacks<KNIGHT>(to) & pieces(KNIGHT))
| (piece_attacks<KING>(to) & pieces(KING))
- | (pawn_attacks(WHITE, to) & pieces(PAWN, BLACK))
- | (pawn_attacks(BLACK, to) & pieces(PAWN, WHITE));
+ | (pawn_attacks(to, WHITE) & pieces(PAWN, BLACK))
+ | (pawn_attacks(to, BLACK) & pieces(PAWN, WHITE));
if (from != SQ_NONE)
break;
if (from != SQ_NONE)
break;
// Piece lists
Square piece_list(Color c, PieceType pt, int index) const;
// Piece lists
Square piece_list(Color c, PieceType pt, int index) const;
- // Attack information for a given square
+ // Attack information to a given square
Bitboard attacks_to(Square s) const;
Bitboard attacks_to(Square s, Color c) const;
Bitboard attacks_to(Square s) const;
Bitboard attacks_to(Square s, Color c) const;
- bool pawn_attacks_square(Color c, Square f, Square t) const;
- Bitboard pawn_attacks(Color c, Square s) const;
-
- template<PieceType>
- Bitboard piece_attacks(Square s) const;
-
- template<PieceType>
- Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
+ template<PieceType> Bitboard piece_attacks(Square s) const;
+ Bitboard pawn_attacks(Square s, Color c) const;
+ // Attack information to a given square from another given square
+ template<PieceType> Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
bool piece_attacks_square(Piece p, Square f, Square t) const; // Dispatch at run-time
+ bool pawn_attacks_square(Square f, Square t, Color c) const;
// Properties of moves
bool pl_move_is_legal(Move m) const;
// Properties of moves
bool pl_move_is_legal(Move m) const;
// Position consistency check, for debugging
bool is_ok(int* failedStep = NULL) const;
// Position consistency check, for debugging
bool is_ok(int* failedStep = NULL) const;
- // Static member functions:
+ // Static member functions
static void init_zobrist();
static void init_piece_square_tables();
static void init_zobrist();
static void init_piece_square_tables();
return relative_square(c, make_square(initialQRFile, RANK_1));
}
return relative_square(c, make_square(initialQRFile, RANK_1));
}
-inline Bitboard Position::pawn_attacks(Color c, Square s) const {
+inline Bitboard Position::pawn_attacks(Square s, Color c) const {
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
}
return StepAttackBB[piece_of_color_and_type(c, PAWN)][s];
}
return st->checkersBB != EmptyBoardBB;
}
return st->checkersBB != EmptyBoardBB;
}
-inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
- return bit_is_set(pawn_attacks(c, f), t);
+inline bool Position::pawn_attacks_square(Square f, Square t, Color c) const {
+ return bit_is_set(pawn_attacks(f, c), t);
}
template<PieceType Piece>
}
template<PieceType Piece>