mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Rename piece_attacks() in piece_attacks_from()
It is a bit longer but much easier to understand especially for people new to the sources. I remember it was not trivial for me to understand the returned attack bitboard refers to attacks launched from the given square and not attacking the given square. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
f74f42b298
commit
6845397c5c
7 changed files with 80 additions and 79 deletions
|
@ -343,7 +343,7 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
|
||||||
result += Value(square_distance(bksq, nsq) * 32);
|
result += Value(square_distance(bksq, nsq) * 32);
|
||||||
|
|
||||||
// Bonus for restricting the knight's mobility
|
// Bonus for restricting the knight's mobility
|
||||||
result += Value((8 - count_1s_max_15(pos.piece_attacks<KNIGHT>(nsq))) * 8);
|
result += Value((8 - count_1s_max_15(pos.piece_attacks_from<KNIGHT>(nsq))) * 8);
|
||||||
|
|
||||||
return (strongerSide == pos.side_to_move() ? result : -result);
|
return (strongerSide == pos.side_to_move() ? result : -result);
|
||||||
}
|
}
|
||||||
|
@ -434,10 +434,10 @@ ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
|
||||||
&& relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
|
&& relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
|
||||||
&& (pos.pieces(ROOK, weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
&& (pos.pieces(ROOK, weakerSide) & relative_rank_bb(weakerSide, RANK_3))
|
||||||
&& (pos.pieces(PAWN, weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
&& (pos.pieces(PAWN, weakerSide) & relative_rank_bb(weakerSide, RANK_2))
|
||||||
&& (pos.piece_attacks<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
|
&& (pos.piece_attacks_from<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(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
|
if (pos.pawn_attacks_from(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
}
|
}
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
@ -696,7 +696,7 @@ ScaleFactor ScalingFunction<KBPKB>::apply(const Position &pos) {
|
||||||
Bitboard ray = ray_bb(pawnSq, (strongerSide == WHITE)? SIGNED_DIR_N : SIGNED_DIR_S);
|
Bitboard ray = ray_bb(pawnSq, (strongerSide == WHITE)? SIGNED_DIR_N : SIGNED_DIR_S);
|
||||||
if (ray & pos.pieces(KING, weakerSide))
|
if (ray & pos.pieces(KING, weakerSide))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
if( (pos.piece_attacks<BISHOP>(weakerBishopSq) & ray)
|
if( (pos.piece_attacks_from<BISHOP>(weakerBishopSq) & ray)
|
||||||
&& square_distance(weakerBishopSq, pawnSq) >= 3)
|
&& square_distance(weakerBishopSq, pawnSq) >= 3)
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
}
|
}
|
||||||
|
@ -761,13 +761,13 @@ ScaleFactor ScalingFunction<KBPPKB>::apply(const Position& pos) {
|
||||||
if ( ksq == blockSq1
|
if ( ksq == blockSq1
|
||||||
&& square_color(ksq) != square_color(wbsq)
|
&& square_color(ksq) != square_color(wbsq)
|
||||||
&& ( bbsq == blockSq2
|
&& ( bbsq == blockSq2
|
||||||
|| (pos.piece_attacks<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|
|| (pos.piece_attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|
||||||
|| rank_distance(r1, r2) >= 2))
|
|| rank_distance(r1, r2) >= 2))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
else if ( ksq == blockSq2
|
else if ( ksq == blockSq2
|
||||||
&& square_color(ksq) != square_color(wbsq)
|
&& square_color(ksq) != square_color(wbsq)
|
||||||
&& ( bbsq == blockSq1
|
&& ( bbsq == blockSq1
|
||||||
|| (pos.piece_attacks<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
|
|| (pos.piece_attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
|
||||||
return ScaleFactor(0);
|
return ScaleFactor(0);
|
||||||
else
|
else
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|
|
@ -342,8 +342,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
ei.egValue += apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame);
|
ei.egValue += apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame);
|
||||||
|
|
||||||
// Initialize king attack bitboards and king attack zones for both sides
|
// Initialize king attack bitboards and king attack zones for both sides
|
||||||
ei.attackedBy[WHITE][KING] = pos.piece_attacks<KING>(pos.king_square(WHITE));
|
ei.attackedBy[WHITE][KING] = pos.piece_attacks_from<KING>(pos.king_square(WHITE));
|
||||||
ei.attackedBy[BLACK][KING] = pos.piece_attacks<KING>(pos.king_square(BLACK));
|
ei.attackedBy[BLACK][KING] = pos.piece_attacks_from<KING>(pos.king_square(BLACK));
|
||||||
ei.kingZone[WHITE] = ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8);
|
ei.kingZone[WHITE] = ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8);
|
||||||
ei.kingZone[BLACK] = ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8);
|
ei.kingZone[BLACK] = ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8);
|
||||||
|
|
||||||
|
@ -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(s, them) & p.pieces(PAWN, us)))
|
if (bonus && (p.pawn_attacks_from(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)
|
||||||
|
@ -620,7 +620,7 @@ namespace {
|
||||||
s = pos.piece_list(us, Piece, i);
|
s = pos.piece_list(us, Piece, i);
|
||||||
|
|
||||||
if (Piece == KNIGHT || Piece == QUEEN)
|
if (Piece == KNIGHT || Piece == QUEEN)
|
||||||
b = pos.piece_attacks<Piece>(s);
|
b = pos.piece_attacks_from<Piece>(s);
|
||||||
else if (Piece == BISHOP)
|
else if (Piece == BISHOP)
|
||||||
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, us));
|
b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, us));
|
||||||
else if (Piece == ROOK)
|
else if (Piece == ROOK)
|
||||||
|
@ -773,7 +773,7 @@ namespace {
|
||||||
if (QueenContactMates && !p.is_check())
|
if (QueenContactMates && !p.is_check())
|
||||||
{
|
{
|
||||||
Bitboard escapeSquares =
|
Bitboard escapeSquares =
|
||||||
p.piece_attacks<KING>(s) & ~p.pieces_of_color(us) & ~attackedByOthers;
|
p.piece_attacks_from<KING>(s) & ~p.pieces_of_color(us) & ~attackedByOthers;
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
|
@ -785,7 +785,7 @@ namespace {
|
||||||
for (int i = 0; i < p.piece_count(them, QUEEN); i++)
|
for (int i = 0; i < p.piece_count(them, QUEEN); i++)
|
||||||
{
|
{
|
||||||
from = p.piece_list(them, QUEEN, i);
|
from = p.piece_list(them, QUEEN, i);
|
||||||
if ( bit_is_set(p.piece_attacks<QUEEN>(from), to)
|
if ( bit_is_set(p.piece_attacks_from<QUEEN>(from), to)
|
||||||
&& !bit_is_set(p.pinned_pieces(them), from)
|
&& !bit_is_set(p.pinned_pieces(them), from)
|
||||||
&& !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(ROOK, QUEEN, us))
|
&& !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(ROOK, QUEEN, us))
|
||||||
&& !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(BISHOP, QUEEN, us)))
|
&& !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(BISHOP, QUEEN, us)))
|
||||||
|
@ -801,7 +801,7 @@ namespace {
|
||||||
// Analyse safe distance checks
|
// Analyse safe distance checks
|
||||||
if (QueenCheckBonus > 0 || RookCheckBonus > 0)
|
if (QueenCheckBonus > 0 || RookCheckBonus > 0)
|
||||||
{
|
{
|
||||||
b = p.piece_attacks<ROOK>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
b = p.piece_attacks_from<ROOK>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||||
|
|
||||||
// Queen checks
|
// Queen checks
|
||||||
b2 = b & ei.attacked_by(them, QUEEN);
|
b2 = b & ei.attacked_by(them, QUEEN);
|
||||||
|
@ -815,7 +815,7 @@ namespace {
|
||||||
}
|
}
|
||||||
if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
|
if (QueenCheckBonus > 0 || BishopCheckBonus > 0)
|
||||||
{
|
{
|
||||||
b = p.piece_attacks<BISHOP>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
b = p.piece_attacks_from<BISHOP>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||||
|
|
||||||
// Queen checks
|
// Queen checks
|
||||||
b2 = b & ei.attacked_by(them, QUEEN);
|
b2 = b & ei.attacked_by(them, QUEEN);
|
||||||
|
@ -829,7 +829,7 @@ namespace {
|
||||||
}
|
}
|
||||||
if (KnightCheckBonus > 0)
|
if (KnightCheckBonus > 0)
|
||||||
{
|
{
|
||||||
b = p.piece_attacks<KNIGHT>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
b = p.piece_attacks_from<KNIGHT>(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us);
|
||||||
|
|
||||||
// Knight checks
|
// Knight checks
|
||||||
b2 = b & ei.attacked_by(them, KNIGHT);
|
b2 = b & ei.attacked_by(them, KNIGHT);
|
||||||
|
@ -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(s, them) & b2)
|
else if (pos.pawn_attacks_from(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
|
||||||
|
|
|
@ -253,7 +253,7 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate evasions for king
|
// Generate evasions for king
|
||||||
Bitboard b1 = pos.piece_attacks<KING>(ksq) & ~pos.pieces_of_color(us) & ~checkersAttacks;
|
Bitboard b1 = pos.piece_attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~checkersAttacks;
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
to = pop_1st_bit(&b1);
|
to = pop_1st_bit(&b1);
|
||||||
|
@ -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(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
|
b1 = pos.pawn_attacks_from(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b1);
|
from = pop_1st_bit(&b1);
|
||||||
|
@ -290,9 +290,9 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pieces captures
|
// Pieces captures
|
||||||
b1 = ( (pos.piece_attacks<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
|
b1 = ( (pos.piece_attacks_from<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
|
||||||
| (pos.piece_attacks<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
|
| (pos.piece_attacks_from<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
|
||||||
| (pos.piece_attacks<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
|
| (pos.piece_attacks_from<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
|
||||||
|
|
||||||
while (b1)
|
while (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(to, them) & pos.pieces(PAWN, us);
|
b1 = pos.pawn_attacks_from(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.
|
||||||
|
@ -557,7 +557,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Luckly we can handle all the other pieces in one go
|
// Luckly we can handle all the other pieces in one go
|
||||||
return ( bit_is_set(pos.piece_attacks(pc, from), to)
|
return ( bit_is_set(pos.piece_attacks_from(pc, from), to)
|
||||||
&& pos.pl_move_is_legal(m, pinned)
|
&& pos.pl_move_is_legal(m, pinned)
|
||||||
&& !move_is_promotion(m));
|
&& !move_is_promotion(m));
|
||||||
}
|
}
|
||||||
|
@ -598,7 +598,7 @@ namespace {
|
||||||
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
||||||
{
|
{
|
||||||
from = pos.piece_list(us, Piece, i);
|
from = pos.piece_list(us, Piece, i);
|
||||||
b = pos.piece_attacks<Piece>(from) & target;
|
b = pos.piece_attacks_from<Piece>(from) & target;
|
||||||
SERIALIZE_MOVES(b);
|
SERIALIZE_MOVES(b);
|
||||||
}
|
}
|
||||||
return mlist;
|
return mlist;
|
||||||
|
@ -616,7 +616,7 @@ namespace {
|
||||||
if (pinned && bit_is_set(pinned, from))
|
if (pinned && bit_is_set(pinned, from))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
b = pos.piece_attacks<Piece>(from) & target;
|
b = pos.piece_attacks_from<Piece>(from) & target;
|
||||||
SERIALIZE_MOVES(b);
|
SERIALIZE_MOVES(b);
|
||||||
}
|
}
|
||||||
return mlist;
|
return mlist;
|
||||||
|
@ -628,7 +628,7 @@ namespace {
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
Square from = pos.king_square(us);
|
Square from = pos.king_square(us);
|
||||||
|
|
||||||
b = pos.piece_attacks<KING>(from) & target;
|
b = pos.piece_attacks_from<KING>(from) & target;
|
||||||
SERIALIZE_MOVES(b);
|
SERIALIZE_MOVES(b);
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
@ -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(pos.ep_square(), Them);
|
Bitboard b1 = pawns & pos.pawn_attacks_from(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(ksq, Them);
|
b3 = b2 & pos.pawn_attacks_from(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(ksq, Them);
|
b3 = move_pawns<Us, DELTA_N>(b2 & TRank3BB) & empty & pos.pawn_attacks_from(ksq, Them);
|
||||||
SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
|
SERIALIZE_MOVES_D(b3, -TDELTA_N -TDELTA_N);
|
||||||
return mlist;
|
return mlist;
|
||||||
}
|
}
|
||||||
|
@ -839,7 +839,7 @@ namespace {
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
Square from = pop_1st_bit(&b);
|
Square from = pop_1st_bit(&b);
|
||||||
Bitboard bb = pos.piece_attacks<Piece>(from) & pos.empty_squares();
|
Bitboard bb = pos.piece_attacks_from<Piece>(from) & pos.empty_squares();
|
||||||
if (Piece == KING)
|
if (Piece == KING)
|
||||||
bb &= ~QueenPseudoAttacks[ksq];
|
bb &= ~QueenPseudoAttacks[ksq];
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ namespace {
|
||||||
b = target & ~dc;
|
b = target & ~dc;
|
||||||
if (Piece != KING || b)
|
if (Piece != KING || b)
|
||||||
{
|
{
|
||||||
Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
|
Bitboard checkSqs = pos.piece_attacks_from<Piece>(ksq) & pos.empty_squares();
|
||||||
if (!checkSqs)
|
if (!checkSqs)
|
||||||
return mlist;
|
return mlist;
|
||||||
|
|
||||||
|
@ -862,7 +862,7 @@ namespace {
|
||||||
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
|| (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
|
Bitboard bb = pos.piece_attacks_from<Piece>(from) & checkSqs;
|
||||||
SERIALIZE_MOVES(bb);
|
SERIALIZE_MOVES(bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,7 +303,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) {
|
||||||
if ( passed
|
if ( passed
|
||||||
|| isolated
|
|| isolated
|
||||||
|| chain
|
|| chain
|
||||||
|| (pos.pawn_attacks(s, us) & theirPawns)
|
|| (pos.pawn_attacks_from(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(s, us);
|
Bitboard b = pos.pawn_attacks_from(s, us);
|
||||||
if (us == WHITE)
|
if (us == WHITE)
|
||||||
{
|
{
|
||||||
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
for ( ; !(b & (ourPawns | theirPawns)); b <<= 8);
|
||||||
|
|
|
@ -384,30 +384,30 @@ Bitboard Position::discovered_check_candidates(Color c) const {
|
||||||
|
|
||||||
Bitboard Position::attackers_to(Square s) const {
|
Bitboard Position::attackers_to(Square s) const {
|
||||||
|
|
||||||
return (pawn_attacks(s, BLACK) & pieces(PAWN, WHITE))
|
return (pawn_attacks_from(s, BLACK) & pieces(PAWN, WHITE))
|
||||||
| (pawn_attacks(s, WHITE) & pieces(PAWN, BLACK))
|
| (pawn_attacks_from(s, WHITE) & pieces(PAWN, BLACK))
|
||||||
| (piece_attacks<KNIGHT>(s) & pieces(KNIGHT))
|
| (piece_attacks_from<KNIGHT>(s) & pieces(KNIGHT))
|
||||||
| (piece_attacks<ROOK>(s) & pieces(ROOK, QUEEN))
|
| (piece_attacks_from<ROOK>(s) & pieces(ROOK, QUEEN))
|
||||||
| (piece_attacks<BISHOP>(s) & pieces(BISHOP, QUEEN))
|
| (piece_attacks_from<BISHOP>(s) & pieces(BISHOP, QUEEN))
|
||||||
| (piece_attacks<KING>(s) & pieces(KING));
|
| (piece_attacks_from<KING>(s) & pieces(KING));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Position::piece_attacks() computes a bitboard of all attacks
|
/// Position::piece_attacks_from() computes a bitboard of all attacks
|
||||||
/// of a given piece put in a given square.
|
/// of a given piece put in a given square.
|
||||||
|
|
||||||
Bitboard Position::piece_attacks(Piece p, Square s) const {
|
Bitboard Position::piece_attacks_from(Piece p, Square s) const {
|
||||||
|
|
||||||
assert(square_is_ok(s));
|
assert(square_is_ok(s));
|
||||||
|
|
||||||
switch (p)
|
switch (p)
|
||||||
{
|
{
|
||||||
case WP: return pawn_attacks(s, WHITE);
|
case WP: return pawn_attacks_from(s, WHITE);
|
||||||
case BP: return pawn_attacks(s, BLACK);
|
case BP: return pawn_attacks_from(s, BLACK);
|
||||||
case WN: case BN: return piece_attacks<KNIGHT>(s);
|
case WN: case BN: return piece_attacks_from<KNIGHT>(s);
|
||||||
case WB: case BB: return piece_attacks<BISHOP>(s);
|
case WB: case BB: return piece_attacks_from<BISHOP>(s);
|
||||||
case WR: case BR: return piece_attacks<ROOK>(s);
|
case WR: case BR: return piece_attacks_from<ROOK>(s);
|
||||||
case WQ: case BQ: return piece_attacks<QUEEN>(s);
|
case WQ: case BQ: return piece_attacks_from<QUEEN>(s);
|
||||||
case WK: case BK: return piece_attacks<KING>(s);
|
case WK: case BK: return piece_attacks_from<KING>(s);
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -426,7 +426,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
||||||
|
|
||||||
assert(square_is_occupied(f));
|
assert(square_is_occupied(f));
|
||||||
|
|
||||||
if (bit_is_set(piece_attacks(piece_on(f), t), s))
|
if (bit_is_set(piece_attacks_from(piece_on(f), t), s))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Move the piece and scan for X-ray attacks behind it
|
// Move the piece and scan for X-ray attacks behind it
|
||||||
|
@ -439,7 +439,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
||||||
|
|
||||||
// If we have attacks we need to verify that are caused by our move
|
// If we have attacks we need to verify that are caused by our move
|
||||||
// and are not already existent ones.
|
// and are not already existent ones.
|
||||||
return xray && (xray ^ (xray & piece_attacks<QUEEN>(s)));
|
return xray && (xray ^ (xray & piece_attacks_from<QUEEN>(s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
|
||||||
{
|
{
|
||||||
case PAWN:
|
case PAWN:
|
||||||
|
|
||||||
if (bit_is_set(pawn_attacks(ksq, them), to)) // Normal check?
|
if (bit_is_set(pawn_attacks_from(ksq, them), to)) // Normal check?
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( dcCandidates // Discovered check?
|
if ( dcCandidates // Discovered check?
|
||||||
|
@ -563,7 +563,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
|
||||||
switch (move_promotion_piece(m))
|
switch (move_promotion_piece(m))
|
||||||
{
|
{
|
||||||
case KNIGHT:
|
case KNIGHT:
|
||||||
return bit_is_set(piece_attacks<KNIGHT>(to), ksq);
|
return bit_is_set(piece_attacks_from<KNIGHT>(to), ksq);
|
||||||
case BISHOP:
|
case BISHOP:
|
||||||
return bit_is_set(bishop_attacks_bb(to, b), ksq);
|
return bit_is_set(bishop_attacks_bb(to, b), ksq);
|
||||||
case ROOK:
|
case ROOK:
|
||||||
|
@ -593,21 +593,21 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
|
||||||
// Test discovered check and normal check according to piece type
|
// Test discovered check and normal check according to piece type
|
||||||
case KNIGHT:
|
case KNIGHT:
|
||||||
return (dcCandidates && bit_is_set(dcCandidates, from))
|
return (dcCandidates && bit_is_set(dcCandidates, from))
|
||||||
|| bit_is_set(piece_attacks<KNIGHT>(ksq), to);
|
|| bit_is_set(piece_attacks_from<KNIGHT>(ksq), to);
|
||||||
|
|
||||||
case BISHOP:
|
case BISHOP:
|
||||||
return (dcCandidates && bit_is_set(dcCandidates, from))
|
return (dcCandidates && bit_is_set(dcCandidates, from))
|
||||||
|| (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks<BISHOP>(ksq), to));
|
|| (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks_from<BISHOP>(ksq), to));
|
||||||
|
|
||||||
case ROOK:
|
case ROOK:
|
||||||
return (dcCandidates && bit_is_set(dcCandidates, from))
|
return (dcCandidates && bit_is_set(dcCandidates, from))
|
||||||
|| (direction_is_straight(ksq, to) && bit_is_set(piece_attacks<ROOK>(ksq), to));
|
|| (direction_is_straight(ksq, to) && bit_is_set(piece_attacks_from<ROOK>(ksq), to));
|
||||||
|
|
||||||
case QUEEN:
|
case QUEEN:
|
||||||
// Discovered checks are impossible!
|
// Discovered checks are impossible!
|
||||||
assert(!bit_is_set(dcCandidates, from));
|
assert(!bit_is_set(dcCandidates, from));
|
||||||
return ( (direction_is_straight(ksq, to) && bit_is_set(piece_attacks<ROOK>(ksq), to))
|
return ( (direction_is_straight(ksq, to) && bit_is_set(piece_attacks_from<ROOK>(ksq), to))
|
||||||
|| (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks<BISHOP>(ksq), to)));
|
|| (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks_from<BISHOP>(ksq), to)));
|
||||||
|
|
||||||
case KING:
|
case KING:
|
||||||
// Discovered check?
|
// Discovered check?
|
||||||
|
@ -661,22 +661,23 @@ inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square
|
||||||
// Direct checks
|
// Direct checks
|
||||||
if ( ( (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to))
|
if ( ( (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to))
|
||||||
|| (Rook && bit_is_set(RookPseudoAttacks[ksq], to)))
|
|| (Rook && bit_is_set(RookPseudoAttacks[ksq], to)))
|
||||||
&& bit_is_set(piece_attacks<Piece>(ksq), to)) // slow, try to early skip
|
&& bit_is_set(piece_attacks_from<Piece>(ksq), to)) // slow, try to early skip
|
||||||
set_bit(pCheckersBB, to);
|
set_bit(pCheckersBB, to);
|
||||||
|
|
||||||
else if ( Piece != KING
|
else if ( Piece != KING
|
||||||
&& !Slider
|
&& !Slider
|
||||||
&& bit_is_set(Piece == PAWN ? pawn_attacks(ksq, opposite_color(sideToMove)) : piece_attacks<Piece>(ksq), to))
|
&& bit_is_set(Piece == PAWN ? pawn_attacks_from(ksq, opposite_color(sideToMove))
|
||||||
|
: piece_attacks_from<Piece>(ksq), to))
|
||||||
set_bit(pCheckersBB, to);
|
set_bit(pCheckersBB, to);
|
||||||
|
|
||||||
// Discovery checks
|
// Discovery checks
|
||||||
if (Piece != QUEEN && bit_is_set(dcCandidates, from))
|
if (Piece != QUEEN && bit_is_set(dcCandidates, from))
|
||||||
{
|
{
|
||||||
if (Piece != ROOK)
|
if (Piece != ROOK)
|
||||||
(*pCheckersBB) |= (piece_attacks<ROOK>(ksq) & pieces(ROOK, QUEEN, side_to_move()));
|
(*pCheckersBB) |= (piece_attacks_from<ROOK>(ksq) & pieces(ROOK, QUEEN, side_to_move()));
|
||||||
|
|
||||||
if (Piece != BISHOP)
|
if (Piece != BISHOP)
|
||||||
(*pCheckersBB) |= (piece_attacks<BISHOP>(ksq) & pieces(BISHOP, QUEEN, side_to_move()));
|
(*pCheckersBB) |= (piece_attacks_from<BISHOP>(ksq) & pieces(BISHOP, QUEEN, side_to_move()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -805,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(from + (us == WHITE ? DELTA_N : DELTA_S), us) & pieces(PAWN, them))
|
if (pawn_attacks_from(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];
|
||||||
|
@ -1359,10 +1360,10 @@ int Position::see(Square from, Square to) const {
|
||||||
clear_bit(&occ, from);
|
clear_bit(&occ, from);
|
||||||
attackers = (rook_attacks_bb(to, occ) & pieces(ROOK, QUEEN))
|
attackers = (rook_attacks_bb(to, occ) & pieces(ROOK, QUEEN))
|
||||||
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
|
| (bishop_attacks_bb(to, occ) & pieces(BISHOP, QUEEN))
|
||||||
| (piece_attacks<KNIGHT>(to) & pieces(KNIGHT))
|
| (piece_attacks_from<KNIGHT>(to) & pieces(KNIGHT))
|
||||||
| (piece_attacks<KING>(to) & pieces(KING))
|
| (piece_attacks_from<KING>(to) & pieces(KING))
|
||||||
| (pawn_attacks(to, WHITE) & pieces(PAWN, BLACK))
|
| (pawn_attacks_from(to, WHITE) & pieces(PAWN, BLACK))
|
||||||
| (pawn_attacks(to, BLACK) & pieces(PAWN, WHITE));
|
| (pawn_attacks_from(to, BLACK) & pieces(PAWN, WHITE));
|
||||||
|
|
||||||
if (from != SQ_NONE)
|
if (from != SQ_NONE)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -195,12 +195,12 @@ 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 to a given square
|
// Information about attacks to or from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
Bitboard attackers_to(Square s, Color c) const;
|
Bitboard attackers_to(Square s, Color c) const;
|
||||||
Bitboard piece_attacks(Piece p, Square s) const;
|
Bitboard piece_attacks_from(Piece p, Square s) const;
|
||||||
Bitboard pawn_attacks(Square s, Color c) const;
|
Bitboard pawn_attacks_from(Square s, Color c) const;
|
||||||
template<PieceType> Bitboard piece_attacks(Square s) const;
|
template<PieceType> Bitboard piece_attacks_from(Square s) const;
|
||||||
|
|
||||||
// Properties of moves
|
// Properties of moves
|
||||||
bool pl_move_is_legal(Move m) const;
|
bool pl_move_is_legal(Move m) const;
|
||||||
|
@ -433,33 +433,33 @@ 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(Square s, Color c) const {
|
inline Bitboard Position::pawn_attacks_from(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];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<PieceType Piece> // Knight and King
|
template<PieceType Piece> // Knight and King
|
||||||
inline Bitboard Position::piece_attacks(Square s) const {
|
inline Bitboard Position::piece_attacks_from(Square s) const {
|
||||||
return StepAttackBB[Piece][s];
|
return StepAttackBB[Piece][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
|
inline Bitboard Position::piece_attacks_from<PAWN>(Square s) const {
|
||||||
return StepAttackBB[WP][s] | StepAttackBB[BP][s];
|
return StepAttackBB[WP][s] | StepAttackBB[BP][s];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
|
inline Bitboard Position::piece_attacks_from<BISHOP>(Square s) const {
|
||||||
return bishop_attacks_bb(s, occupied_squares());
|
return bishop_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
|
inline Bitboard Position::piece_attacks_from<ROOK>(Square s) const {
|
||||||
return rook_attacks_bb(s, occupied_squares());
|
return rook_attacks_bb(s, occupied_squares());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
|
inline Bitboard Position::piece_attacks_from<QUEEN>(Square s) const {
|
||||||
return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
|
return piece_attacks_from<ROOK>(s) | piece_attacks_from<BISHOP>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard Position::checkers() const {
|
inline Bitboard Position::checkers() const {
|
||||||
|
|
|
@ -2182,7 +2182,7 @@ namespace {
|
||||||
|
|
||||||
// Case 4: The destination square for m2 is attacked by the moving piece in m1
|
// Case 4: The destination square for m2 is attacked by the moving piece in m1
|
||||||
p = pos.piece_on(t1);
|
p = pos.piece_on(t1);
|
||||||
if (bit_is_set(pos.piece_attacks(p, t1), t2))
|
if (bit_is_set(pos.piece_attacks_from(p, t1), t2))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Case 5: Discovered check, checking piece is the piece moved in m1
|
// Case 5: Discovered check, checking piece is the piece moved in m1
|
||||||
|
|
Loading…
Add table
Reference in a new issue