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))
switch (p)
{
- 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);
// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if (type_of_piece_on(from) == KING)
- return !(square_is_attacked(move_to(m), opposite_color(us)));
+ return !attacks_to(move_to(m), opposite_color(us));
// A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king.
{
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;
if ( dcCandidates // Discovered check?
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
struct ReducedStateInfo {
Key key, pawnKey, materialKey;
int castleRights, rule50;
- Square epSquare;
+ Square kingSquare[2], epSquare;
Value mgValue, egValue;
Value npMaterial[2];
};
// If the moving piece was a king, update the king square
if (pt == KING)
- kingSquare[us] = to;
+ st->kingSquare[us] = to;
// Update piece lists, note that index[from] is not updated and
// becomes stale. This works as long as index[] is accessed just
// 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];
// Update hash key
key ^= zobrist[them][capture][capsq];
- // If the captured piece was a pawn, update pawn hash key
- if (capture == PAWN)
- st->pawnKey ^= zobrist[them][PAWN][capsq];
-
// Update incremental scores
st->mgValue -= pst<MidGame>(them, capture, capsq);
st->egValue -= pst<EndGame>(them, capture, capsq);
- // Update material
- if (capture != PAWN)
+ // If the captured piece was a pawn, update pawn hash key,
+ // otherwise update non-pawn material.
+ if (capture == PAWN)
+ st->pawnKey ^= zobrist[them][PAWN][capsq];
+ else
st->npMaterial[them] -= piece_value_midgame(capture);
// Update material hash key
board[rto] = rook;
// Update king square
- kingSquare[us] = kto;
+ st->kingSquare[us] = kto;
// Update piece lists
pieceList[us][KING][index[kfrom]] = kto;
board[from] = piece_of_color_and_type(us, pt);
board[to] = EMPTY;
- // If the moving piece was a king, update the king square
- if (pt == KING)
- kingSquare[us] = from;
-
// Update piece list
index[from] = index[to];
pieceList[us][pt][index[from]] = from;
board[rfrom] = piece_of_color_and_type(us, ROOK);
board[kfrom] = piece_of_color_and_type(us, KING);
- // Update king square
- kingSquare[us] = kfrom;
-
// Update piece lists
pieceList[us][KING][index[kto]] = kfrom;
pieceList[us][ROOK][index[rto]] = rfrom;
| (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;
pieceCount[c][pt]++;
if (pt == KING)
- kingSquare[c] = s;
+ st->kingSquare[c] = s;
}
Color us = side_to_move();
Color them = opposite_color(us);
Square ksq = king_square(them);
- if (square_is_attacked(ksq, us))
+ if (attacks_to(ksq, us))
return false;
}