Scid  4.6.5
attacks.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 //
3 // FILE: attacks.h
4 // Lists of attack squares
5 //
6 // Part of: Scid (Shane's Chess Information Database)
7 // Version: 1.0
8 //
9 // Notice: Copyright (c) 1999 Shane Hudson. All rights reserved.
10 //
11 // Author: Shane Hudson (sgh@users.sourceforge.net)
12 //
13 //////////////////////////////////////////////////////////////////////
14 
15 #ifndef SCID_ATTACKS_H
16 #define SCID_ATTACKS_H
17 
18 #ifndef SCID_COMMON_H
19 #include "common.h"
20 #endif
21 
22 
23 // NOTE: These arrays have been automatically generated. Don't change
24 // them unless the square or piece representations change!
25 
26 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 // Knight Moves:
28 // knightAttacks[sq] is an array of the squares a knight on sq
29 // could move to. There are 9 target squares even though a knight
30 // can only have at most 8 legal moves, so we can end the list with
31 // an "NS" (null square).
32 //
33 // Example code to iterate through the knight moves for a square:
34 //
35 // squareT *dest = knightAttacks[fromSquare];
36 // while (*dest != NULL_SQUARE) {
37 // /* do desired action.... */
38 // dest++;
39 // }
40 //
41 
42  const squareT
43 knightAttacks[66][9] = {
44  { /* A1 */ C2, B3, NS, NS, NS, NS, NS, NS, NS },
45  { /* B1 */ D2, A3, C3, NS, NS, NS, NS, NS, NS },
46  { /* C1 */ A2, E2, B3, D3, NS, NS, NS, NS, NS },
47  { /* D1 */ B2, F2, C3, E3, NS, NS, NS, NS, NS },
48  { /* E1 */ C2, G2, D3, F3, NS, NS, NS, NS, NS },
49  { /* F1 */ D2, H2, E3, G3, NS, NS, NS, NS, NS },
50  { /* G1 */ E2, F3, H3, NS, NS, NS, NS, NS, NS },
51  { /* H1 */ F2, G3, NS, NS, NS, NS, NS, NS, NS },
52  { /* A2 */ C1, C3, B4, NS, NS, NS, NS, NS, NS },
53  { /* B2 */ D1, D3, A4, C4, NS, NS, NS, NS, NS },
54  { /* C2 */ A1, E1, A3, E3, B4, D4, NS, NS, NS },
55  { /* D2 */ B1, F1, B3, F3, C4, E4, NS, NS, NS },
56  { /* E2 */ C1, G1, C3, G3, D4, F4, NS, NS, NS },
57  { /* F2 */ D1, H1, D3, H3, E4, G4, NS, NS, NS },
58  { /* G2 */ E1, E3, F4, H4, NS, NS, NS, NS, NS },
59  { /* H2 */ F1, F3, G4, NS, NS, NS, NS, NS, NS },
60  { /* A3 */ B1, C2, C4, B5, NS, NS, NS, NS, NS },
61  { /* B3 */ A1, C1, D2, D4, A5, C5, NS, NS, NS },
62  { /* C3 */ B1, D1, A2, E2, A4, E4, B5, D5, NS },
63  { /* D3 */ C1, E1, B2, F2, B4, F4, C5, E5, NS },
64  { /* E3 */ D1, F1, C2, G2, C4, G4, D5, F5, NS },
65  { /* F3 */ E1, G1, D2, H2, D4, H4, E5, G5, NS },
66  { /* G3 */ F1, H1, E2, E4, F5, H5, NS, NS, NS },
67  { /* H3 */ G1, F2, F4, G5, NS, NS, NS, NS, NS },
68  { /* A4 */ B2, C3, C5, B6, NS, NS, NS, NS, NS },
69  { /* B4 */ A2, C2, D3, D5, A6, C6, NS, NS, NS },
70  { /* C4 */ B2, D2, A3, E3, A5, E5, B6, D6, NS },
71  { /* D4 */ C2, E2, B3, F3, B5, F5, C6, E6, NS },
72  { /* E4 */ D2, F2, C3, G3, C5, G5, D6, F6, NS },
73  { /* F4 */ E2, G2, D3, H3, D5, H5, E6, G6, NS },
74  { /* G4 */ F2, H2, E3, E5, F6, H6, NS, NS, NS },
75  { /* H4 */ G2, F3, F5, G6, NS, NS, NS, NS, NS },
76  { /* A5 */ B3, C4, C6, B7, NS, NS, NS, NS, NS },
77  { /* B5 */ A3, C3, D4, D6, A7, C7, NS, NS, NS },
78  { /* C5 */ B3, D3, A4, E4, A6, E6, B7, D7, NS },
79  { /* D5 */ C3, E3, B4, F4, B6, F6, C7, E7, NS },
80  { /* E5 */ D3, F3, C4, G4, C6, G6, D7, F7, NS },
81  { /* F5 */ E3, G3, D4, H4, D6, H6, E7, G7, NS },
82  { /* G5 */ F3, H3, E4, E6, F7, H7, NS, NS, NS },
83  { /* H5 */ G3, F4, F6, G7, NS, NS, NS, NS, NS },
84  { /* A6 */ B4, C5, C7, B8, NS, NS, NS, NS, NS },
85  { /* B6 */ A4, C4, D5, D7, A8, C8, NS, NS, NS },
86  { /* C6 */ B4, D4, A5, E5, A7, E7, B8, D8, NS },
87  { /* D6 */ C4, E4, B5, F5, B7, F7, C8, E8, NS },
88  { /* E6 */ D4, F4, C5, G5, C7, G7, D8, F8, NS },
89  { /* F6 */ E4, G4, D5, H5, D7, H7, E8, G8, NS },
90  { /* G6 */ F4, H4, E5, E7, F8, H8, NS, NS, NS },
91  { /* H6 */ G4, F5, F7, G8, NS, NS, NS, NS, NS },
92  { /* A7 */ B5, C6, C8, NS, NS, NS, NS, NS, NS },
93  { /* B7 */ A5, C5, D6, D8, NS, NS, NS, NS, NS },
94  { /* C7 */ B5, D5, A6, E6, A8, E8, NS, NS, NS },
95  { /* D7 */ C5, E5, B6, F6, B8, F8, NS, NS, NS },
96  { /* E7 */ D5, F5, C6, G6, C8, G8, NS, NS, NS },
97  { /* F7 */ E5, G5, D6, H6, D8, H8, NS, NS, NS },
98  { /* G7 */ F5, H5, E6, E8, NS, NS, NS, NS, NS },
99  { /* H7 */ G5, F6, F8, NS, NS, NS, NS, NS, NS },
100  { /* A8 */ B6, C7, NS, NS, NS, NS, NS, NS, NS },
101  { /* B8 */ A6, C6, D7, NS, NS, NS, NS, NS, NS },
102  { /* C8 */ B6, D6, A7, E7, NS, NS, NS, NS, NS },
103  { /* D8 */ C6, E6, B7, F7, NS, NS, NS, NS, NS },
104  { /* E8 */ D6, F6, C7, G7, NS, NS, NS, NS, NS },
105  { /* F8 */ E6, G6, D7, H7, NS, NS, NS, NS, NS },
106  { /* G8 */ F6, H6, E7, NS, NS, NS, NS, NS, NS },
107  { /* H8 */ G6, F7, NS, NS, NS, NS, NS, NS, NS },
108  { /* COL*/ NS, NS, NS, NS, NS, NS, NS, NS, NS },
109  { /* NS */ NS, NS, NS, NS, NS, NS, NS, NS, NS }
110 };
111 
112 
113 
114 // King moves:
115 // As for the knight moves, the secondary array size is 9 even
116 // though there are only 8 possible king moves, so there can
117 // always be a NULL_SQUARE terminating the list of moves for each
118 // square. Castling moves are not included here.
119 
120  const squareT
121 kingAttacks[66][9] = {
122  { /* A1 */ B1, A2, B2, NS, NS, NS, NS, NS, NS },
123  { /* B1 */ A1, C1, A2, B2, C2, NS, NS, NS, NS },
124  { /* C1 */ B1, D1, B2, C2, D2, NS, NS, NS, NS },
125  { /* D1 */ C1, E1, C2, D2, E2, NS, NS, NS, NS },
126  { /* E1 */ D1, F1, D2, E2, F2, NS, NS, NS, NS },
127  { /* F1 */ E1, G1, E2, F2, G2, NS, NS, NS, NS },
128  { /* G1 */ F1, H1, F2, G2, H2, NS, NS, NS, NS },
129  { /* H1 */ G1, G2, H2, NS, NS, NS, NS, NS, NS },
130  { /* A2 */ A1, B1, B2, A3, B3, NS, NS, NS, NS },
131  { /* B2 */ A1, B1, C1, A2, C2, A3, B3, C3, NS },
132  { /* C2 */ B1, C1, D1, B2, D2, B3, C3, D3, NS },
133  { /* D2 */ C1, D1, E1, C2, E2, C3, D3, E3, NS },
134  { /* E2 */ D1, E1, F1, D2, F2, D3, E3, F3, NS },
135  { /* F2 */ E1, F1, G1, E2, G2, E3, F3, G3, NS },
136  { /* G2 */ F1, G1, H1, F2, H2, F3, G3, H3, NS },
137  { /* H2 */ G1, H1, G2, G3, H3, NS, NS, NS, NS },
138  { /* A3 */ A2, B2, B3, A4, B4, NS, NS, NS, NS },
139  { /* B3 */ A2, B2, C2, A3, C3, A4, B4, C4, NS },
140  { /* C3 */ B2, C2, D2, B3, D3, B4, C4, D4, NS },
141  { /* D3 */ C2, D2, E2, C3, E3, C4, D4, E4, NS },
142  { /* E3 */ D2, E2, F2, D3, F3, D4, E4, F4, NS },
143  { /* F3 */ E2, F2, G2, E3, G3, E4, F4, G4, NS },
144  { /* G3 */ F2, G2, H2, F3, H3, F4, G4, H4, NS },
145  { /* H3 */ G2, H2, G3, G4, H4, NS, NS, NS, NS },
146  { /* A4 */ A3, B3, B4, A5, B5, NS, NS, NS, NS },
147  { /* B4 */ A3, B3, C3, A4, C4, A5, B5, C5, NS },
148  { /* C4 */ B3, C3, D3, B4, D4, B5, C5, D5, NS },
149  { /* D4 */ C3, D3, E3, C4, E4, C5, D5, E5, NS },
150  { /* E4 */ D3, E3, F3, D4, F4, D5, E5, F5, NS },
151  { /* F4 */ E3, F3, G3, E4, G4, E5, F5, G5, NS },
152  { /* G4 */ F3, G3, H3, F4, H4, F5, G5, H5, NS },
153  { /* H4 */ G3, H3, G4, G5, H5, NS, NS, NS, NS },
154  { /* A5 */ A4, B4, B5, A6, B6, NS, NS, NS, NS },
155  { /* B5 */ A4, B4, C4, A5, C5, A6, B6, C6, NS },
156  { /* C5 */ B4, C4, D4, B5, D5, B6, C6, D6, NS },
157  { /* D5 */ C4, D4, E4, C5, E5, C6, D6, E6, NS },
158  { /* E5 */ D4, E4, F4, D5, F5, D6, E6, F6, NS },
159  { /* F5 */ E4, F4, G4, E5, G5, E6, F6, G6, NS },
160  { /* G5 */ F4, G4, H4, F5, H5, F6, G6, H6, NS },
161  { /* H5 */ G4, H4, G5, G6, H6, NS, NS, NS, NS },
162  { /* A6 */ A5, B5, B6, A7, B7, NS, NS, NS, NS },
163  { /* B6 */ A5, B5, C5, A6, C6, A7, B7, C7, NS },
164  { /* C6 */ B5, C5, D5, B6, D6, B7, C7, D7, NS },
165  { /* D6 */ C5, D5, E5, C6, E6, C7, D7, E7, NS },
166  { /* E6 */ D5, E5, F5, D6, F6, D7, E7, F7, NS },
167  { /* F6 */ E5, F5, G5, E6, G6, E7, F7, G7, NS },
168  { /* G6 */ F5, G5, H5, F6, H6, F7, G7, H7, NS },
169  { /* H6 */ G5, H5, G6, G7, H7, NS, NS, NS, NS },
170  { /* A7 */ A6, B6, B7, A8, B8, NS, NS, NS, NS },
171  { /* B7 */ A6, B6, C6, A7, C7, A8, B8, C8, NS },
172  { /* C7 */ B6, C6, D6, B7, D7, B8, C8, D8, NS },
173  { /* D7 */ C6, D6, E6, C7, E7, C8, D8, E8, NS },
174  { /* E7 */ D6, E6, F6, D7, F7, D8, E8, F8, NS },
175  { /* F7 */ E6, F6, G6, E7, G7, E8, F8, G8, NS },
176  { /* G7 */ F6, G6, H6, F7, H7, F8, G8, H8, NS },
177  { /* H7 */ G6, H6, G7, G8, H8, NS, NS, NS, NS },
178  { /* A8 */ A7, B7, B8, NS, NS, NS, NS, NS, NS },
179  { /* B8 */ A7, B7, C7, A8, C8, NS, NS, NS, NS },
180  { /* C8 */ B7, C7, D7, B8, D8, NS, NS, NS, NS },
181  { /* D8 */ C7, D7, E7, C8, E8, NS, NS, NS, NS },
182  { /* E8 */ D7, E7, F7, D8, F8, NS, NS, NS, NS },
183  { /* F8 */ E7, F7, G7, E8, G8, NS, NS, NS, NS },
184  { /* G8 */ F7, G7, H7, F8, H8, NS, NS, NS, NS },
185  { /* H8 */ G7, H7, G8, NS, NS, NS, NS, NS, NS },
186  { /* COL*/ NS, NS, NS, NS, NS, NS, NS, NS, NS },
187  { /* NS */ NS, NS, NS, NS, NS, NS, NS, NS, NS }
188 };
189 
190 #endif // #ifndef SCID_ATTACKS_H
191 
192 //////////////////////////////////////////////////////////////////////
193 // EOF: attacks.h
194 //////////////////////////////////////////////////////////////////////
195 
const squareT F5
Definition: common.h:347
const squareT F2
Definition: common.h:344
const squareT C5
Definition: common.h:347
const squareT C4
Definition: common.h:346
const squareT C8
Definition: common.h:350
const squareT B3
Definition: common.h:345
const squareT F4
Definition: common.h:346
const squareT F8
Definition: common.h:350
const squareT H1
Definition: common.h:343
const squareT A4
Definition: common.h:346
const squareT D2
Definition: common.h:344
const squareT G6
Definition: common.h:348
const squareT H7
Definition: common.h:349
const squareT C1
Definition: common.h:343
const squareT kingAttacks[66][9]
Definition: attacks.h:121
const squareT H4
Definition: common.h:346
const squareT B5
Definition: common.h:347
const squareT E7
Definition: common.h:349
const squareT G5
Definition: common.h:347
const squareT D7
Definition: common.h:349
const squareT A8
Definition: common.h:350
const squareT E6
Definition: common.h:348
const squareT H6
Definition: common.h:348
const squareT A1
Definition: common.h:343
const squareT A7
Definition: common.h:349
const squareT B4
Definition: common.h:346
const squareT A6
Definition: common.h:348
const squareT F6
Definition: common.h:348
const squareT G1
Definition: common.h:343
const squareT F7
Definition: common.h:349
const squareT H3
Definition: common.h:345
const squareT H2
Definition: common.h:344
const squareT B2
Definition: common.h:344
const squareT C2
Definition: common.h:344
const squareT H5
Definition: common.h:347
const squareT H8
Definition: common.h:350
const squareT A3
Definition: common.h:345
const squareT B1
Definition: common.h:343
const squareT G8
Definition: common.h:350
const squareT G7
Definition: common.h:349
const squareT D1
Definition: common.h:343
const squareT B8
Definition: common.h:350
const squareT B7
Definition: common.h:349
const squareT E5
Definition: common.h:347
const squareT C6
Definition: common.h:348
const squareT D6
Definition: common.h:348
const squareT G3
Definition: common.h:345
const squareT knightAttacks[66][9]
Definition: attacks.h:43
const squareT E2
Definition: common.h:344
const squareT A2
Definition: common.h:344
const squareT E8
Definition: common.h:350
const squareT D3
Definition: common.h:345
const squareT D4
Definition: common.h:346
const squareT E3
Definition: common.h:345
const squareT B6
Definition: common.h:348
const squareT F3
Definition: common.h:345
const squareT E1
Definition: common.h:343
const squareT D5
Definition: common.h:347
const squareT G4
Definition: common.h:346
const squareT E4
Definition: common.h:346
const squareT G2
Definition: common.h:344
const squareT A5
Definition: common.h:347
const squareT C3
Definition: common.h:345
const squareT NS
Definition: common.h:352
const squareT F1
Definition: common.h:343
const squareT C7
Definition: common.h:349
byte squareT
Definition: common.h:113
const squareT D8
Definition: common.h:350