1 
2 // attack.h
3 
4 #ifndef ATTACK_H
5 #define ATTACK_H
6 
7 // includes
8 
9 #include "board.h"
10 #include "util.h"
11 #include "vector.h"
12 
13 // macros
14 
15 #define IS_IN_CHECK(board,colour)         (is_attacked((board),KING_POS((board),(colour)),COLOUR_OPP((colour))))
16 
17 #define DELTA_INC_LINE(delta)             (DeltaIncLine[DeltaOffset+(delta)])
18 #define DELTA_INC_ALL(delta)              (DeltaIncAll[DeltaOffset+(delta)])
19 #define DELTA_MASK(delta)                 (DeltaMask[DeltaOffset+(delta)])
20 
21 #define INC_MASK(inc)                     (IncMask[IncOffset+(inc)])
22 
23 #define PIECE_ATTACK(board,piece,from,to) (PSEUDO_ATTACK((piece),(to)-(from))&&line_is_empty((board),(from),(to)))
24 #define PSEUDO_ATTACK(piece,delta)        (((piece)&DELTA_MASK(delta))!=0)
25 #define SLIDER_ATTACK(piece,inc)          (((piece)&INC_MASK(inc))!=0)
26 
27 #define ATTACK_IN_CHECK(attack)           ((attack)->dn!=0)
28 
29 // types
30 
31 struct attack_t {
32    int dn;
33    int ds[2+1];
34    int di[2+1];
35 };
36 
37 // variables
38 
39 extern int DeltaIncLine[DeltaNb];
40 extern int DeltaIncAll[DeltaNb];
41 
42 extern int DeltaMask[DeltaNb];
43 extern int IncMask[IncNb];
44 
45 // functions
46 
47 extern void attack_init   ();
48 
49 extern bool is_attacked   (const board_t * board, int to, int colour);
50 
51 extern bool line_is_empty (const board_t * board, int from, int to);
52 
53 extern bool is_pinned     (const board_t * board, int square, int colour);
54 
55 extern bool attack_is_ok  (const attack_t * attack);
56 extern void attack_set    (attack_t * attack, const board_t * board);
57 
58 extern bool piece_attack_king (const board_t * board, int piece, int from, int king);
59 
60 #endif // !defined ATTACK_H
61 
62 // end of attack.h
63 
64