mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Change pawn_attacks() API
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>
This commit is contained in:
parent
62a8f393f1
commit
049139d025
6 changed files with 29 additions and 32 deletions
|
@ -437,7 +437,7 @@ ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
||||||
&& (pos.piece_attacks<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
|
&& (pos.piece_attacks<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
|
||||||
{
|
{
|
||||||
Square rsq = pos.piece_list(weakerSide, ROOK, 0);
|
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 ScaleFactor(0);
|
||||||
}
|
}
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|
|
@ -590,7 +590,7 @@ namespace {
|
||||||
|
|
||||||
// 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 (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
|
if ( p.pieces(KNIGHT, them) == EmptyBoardBB
|
||||||
&& (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB)
|
&& (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB)
|
||||||
|
@ -954,7 +954,7 @@ namespace {
|
||||||
b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s);
|
b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s);
|
||||||
if (b2 & rank_bb(s))
|
if (b2 & rank_bb(s))
|
||||||
ebonus += Value(r * 20);
|
ebonus += Value(r * 20);
|
||||||
else if (pos.pawn_attacks(them, s) & b2)
|
else if (pos.pawn_attacks(s, them) & b2)
|
||||||
ebonus += Value(r * 12);
|
ebonus += Value(r * 12);
|
||||||
|
|
||||||
// If the other side has only a king, check whether the pawn is
|
// If the other side has only a king, check whether the pawn is
|
||||||
|
|
|
@ -275,7 +275,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
// Generate captures of the checking piece
|
// Generate captures of the checking piece
|
||||||
|
|
||||||
// Pawn captures
|
// 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)
|
while (b1)
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b1);
|
from = pop_1st_bit(&b1);
|
||||||
|
@ -326,7 +326,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
|
if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
|
||||||
{
|
{
|
||||||
to = pos.ep_square();
|
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
|
// The checking pawn cannot be a discovered (bishop) check candidate
|
||||||
// otherwise we were in check also before last double push move.
|
// otherwise we were in check also before last double push move.
|
||||||
|
@ -700,7 +700,7 @@ namespace {
|
||||||
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
||||||
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
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);
|
assert(b1 != EmptyBoardBB);
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
|
@ -819,11 +819,11 @@ namespace {
|
||||||
// Direct checks, single pawn pushes
|
// Direct checks, single pawn pushes
|
||||||
Bitboard empty = pos.empty_squares();
|
Bitboard empty = pos.empty_squares();
|
||||||
b2 = move_pawns<Us, DELTA_N>(b1) & empty;
|
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);
|
SERIALIZE_MOVES_D(b3, -TDELTA_N);
|
||||||
|
|
||||||
// Direct checks, double pawn pushes
|
// 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);
|
SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,7 +303,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||||
if ( passed
|
if ( passed
|
||||||
|| isolated
|
|| isolated
|
||||||
|| chain
|
|| chain
|
||||||
|| (pos.pawn_attacks(us, s) & theirPawns)
|
|| (pos.pawn_attacks(s, us) & theirPawns)
|
||||||
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
|| (ourPawns & behind_bb(us, r) & neighboring_files_bb(f)))
|
||||||
backward = false;
|
backward = false;
|
||||||
else
|
else
|
||||||
|
@ -312,7 +312,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||||
// pawn on neighboring files. We now check whether the pawn is
|
// pawn on neighboring files. We now check whether the pawn is
|
||||||
// backward by looking in the forward direction on the neighboring
|
// backward by looking in the forward direction on the neighboring
|
||||||
// files, and seeing whether we meet a friendly or an enemy pawn first.
|
// 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)
|
if (us == WHITE)
|
||||||
{
|
{
|
||||||
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||||
|
|
|
@ -384,8 +384,8 @@ Bitboard Position::discovered_check_candidates(Color c) const {
|
||||||
|
|
||||||
Bitboard Position::attacks_to(Square s) const {
|
Bitboard Position::attacks_to(Square s) const {
|
||||||
|
|
||||||
return (pawn_attacks(BLACK, s) & pieces(PAWN, WHITE))
|
return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE))
|
||||||
| (pawn_attacks(WHITE, s) & pieces(PAWN, BLACK))
|
| (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK))
|
||||||
| (piece_attacks<KNIGHT>(s) & pieces(KNIGHT))
|
| (piece_attacks<KNIGHT>(s) & pieces(KNIGHT))
|
||||||
| (piece_attacks<ROOK>(s) & pieces(ROOK, QUEEN))
|
| (piece_attacks<ROOK>(s) & pieces(ROOK, QUEEN))
|
||||||
| (piece_attacks<BISHOP>(s) & pieces(BISHOP, QUEEN))
|
| (piece_attacks<BISHOP>(s) & pieces(BISHOP, QUEEN))
|
||||||
|
@ -402,8 +402,8 @@ bool Position::piece_attacks_square(Piece p, Square f, Square t) const {
|
||||||
|
|
||||||
switch (p)
|
switch (p)
|
||||||
{
|
{
|
||||||
case WP: return pawn_attacks_square(WHITE, f, t);
|
case WP: return pawn_attacks_square(f, t, WHITE);
|
||||||
case BP: return pawn_attacks_square(BLACK, f, t);
|
case BP: return pawn_attacks_square(f, t, BLACK);
|
||||||
case WN: case BN: return piece_attacks_square<KNIGHT>(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 WB: case BB: return piece_attacks_square<BISHOP>(f, t);
|
||||||
case WR: case BR: return piece_attacks_square<ROOK>(f, t);
|
case WR: case BR: return piece_attacks_square<ROOK>(f, t);
|
||||||
|
@ -548,7 +548,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
|
||||||
{
|
{
|
||||||
case PAWN:
|
case PAWN:
|
||||||
|
|
||||||
if (bit_is_set(pawn_attacks(them, ksq), to)) // Normal check?
|
if (bit_is_set(pawn_attacks(ksq, them), to)) // Normal check?
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( dcCandidates // Discovered check?
|
if ( dcCandidates // Discovered check?
|
||||||
|
@ -667,7 +667,7 @@ inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square
|
||||||
|
|
||||||
else if ( Piece != KING
|
else if ( Piece != KING
|
||||||
&& !Slider
|
&& !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);
|
set_bit(pCheckersBB, to);
|
||||||
|
|
||||||
// Discovery checks
|
// Discovery checks
|
||||||
|
@ -806,7 +806,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
// Set en passant square, only if moved pawn can be captured
|
// Set en passant square, only if moved pawn can be captured
|
||||||
if (abs(int(to) - int(from)) == 16)
|
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);
|
st->epSquare = Square((int(from) + int(to)) / 2);
|
||||||
key ^= zobEp[st->epSquare];
|
key ^= zobEp[st->epSquare];
|
||||||
|
@ -1362,8 +1362,8 @@ int Position::see(Square from, Square to) const {
|
||||||
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
|
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
|
||||||
| (piece_attacks<KNIGHT>(to) & pieces(KNIGHT))
|
| (piece_attacks<KNIGHT>(to) & pieces(KNIGHT))
|
||||||
| (piece_attacks<KING>(to) & pieces(KING))
|
| (piece_attacks<KING>(to) & pieces(KING))
|
||||||
| (pawn_attacks(WHITE, to) & pieces(PAWN, BLACK))
|
| (pawn_attacks(to, WHITE) & pieces(PAWN, BLACK))
|
||||||
| (pawn_attacks(BLACK, to) & pieces(PAWN, WHITE));
|
| (pawn_attacks(to, BLACK) & pieces(PAWN, WHITE));
|
||||||
|
|
||||||
if (from != SQ_NONE)
|
if (from != SQ_NONE)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -195,19 +195,16 @@ public:
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square piece_list(Color c, PieceType pt, int index) const;
|
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) const;
|
||||||
Bitboard attacks_to(Square s, Color c) const;
|
Bitboard attacks_to(Square s, Color c) const;
|
||||||
bool pawn_attacks_square(Color c, Square f, Square t) const;
|
template<PieceType> Bitboard piece_attacks(Square s) const;
|
||||||
Bitboard pawn_attacks(Color c, Square s) const;
|
Bitboard pawn_attacks(Square s, Color c) const;
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks(Square s) const;
|
|
||||||
|
|
||||||
template<PieceType>
|
|
||||||
Bitboard piece_attacks_square(Square f, Square t) const; // Dispatch at compile-time
|
|
||||||
|
|
||||||
|
// 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
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m) const;
|
bool pl_move_is_legal(Move m) const;
|
||||||
|
@ -273,7 +270,7 @@ public:
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok(int* failedStep = NULL) const;
|
bool is_ok(int* failedStep = NULL) const;
|
||||||
|
|
||||||
// Static member functions:
|
// Static member functions
|
||||||
static void init_zobrist();
|
static void init_zobrist();
|
||||||
static void init_piece_square_tables();
|
static void init_piece_square_tables();
|
||||||
|
|
||||||
|
@ -440,7 +437,7 @@ inline Square Position::initial_qr_square(Color c) const {
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,8 +474,8 @@ inline bool Position::is_check() const {
|
||||||
return st->checkersBB != EmptyBoardBB;
|
return st->checkersBB != EmptyBoardBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_attacks_square(Color c, Square f, Square t) const {
|
inline bool Position::pawn_attacks_square(Square f, Square t, Color c) const {
|
||||||
return bit_is_set(pawn_attacks(c, f), t);
|
return bit_is_set(pawn_attacks(f, c), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece>
|
template<PieceType Piece>
|
||||||
|
|
Loading…
Add table
Reference in a new issue