search: fixed a bug in NULL move pruning
[owl.git] / attacks.h
blobf571bc704ddec217d44d5aa603cd4eca1e66c5d6
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 extern uint64_t rook_mult[64];
18 extern int rook_shift[64];
19 extern int rook_index[64];
20 extern uint64_t rook_mask[64];
21 extern uint64_t rook_attacks[0x19000];
23 extern uint64_t bishop_mult[64];
24 extern int bishop_shift[64];
25 extern int bishop_index[64];
26 extern uint64_t bishop_mask[64];
27 extern uint64_t bishop_attacks[0x1480];
29 /* bitboard of attacked squares by rook on square s */
30 #define ROOK_ATTACKS(s, blockers) (rook_attacks[rook_index[s] + \
31 ((((blockers) & rook_mask[s]) * rook_mult[s]) >> rook_shift[s])])
33 /* bitboard of attacked squares by bishop on square s */
34 #define BISHOP_ATTACKS(s, blockers) (bishop_attacks[bishop_index[s] + \
35 ((((blockers) & bishop_mask[s]) * bishop_mult[s]) >> bishop_shift[s])])
37 /* bitboard of attacked squares by queen on square s */
38 #define QUEEN_ATTACKS(s, blockers) (ROOK_ATTACKS((s), (blockers)) | \
39 BISHOP_ATTACKS((s), (blockers)))
41 /* is side checked? */
42 #define IS_CHECKED(side) (IS_ATTACKED(brd.kings[side], 1 ^ (side)))
44 /* is square attacked by side */
45 #define IS_ATTACKED(square, side) ((KNIGHTS(side) & piece_moves[KNIGHT][square]) || \
46 (BISHOP_ATTACKS(square, complete) & (BISHOPS(side) | QUEENS(side))) || \
47 (ROOK_ATTACKS(square, complete) & (ROOKS(side) | QUEENS(side))) || \
48 (KING(side) & piece_moves[KING][square]) || \
49 (PAWNS(side) & pawn_moves[1 ^ (side)][square]))
51 /* returns bitboard of pieces attacking specified square */
52 #define ATTACK_TO(square, side, occ) ( \
53 (KNIGHTS(side) & piece_moves[KNIGHT][square]) | \
54 (KING(side) & piece_moves[KING][square]) | \
55 (PAWNS(side) & pawn_moves[1 ^ (side)][square]) | \
56 (((BISHOP_ATTACKS(square, occ)) & (BISHOPS(side) | QUEENS(side))) | \
57 ((ROOK_ATTACKS(square, occ)) & (ROOKS(side) | QUEENS(side)))))