Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
112 | pmbaty | 1 | /* |
2 | Protector -- a UCI chess engine |
||
3 | |||
4 | Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com) |
||
5 | |||
6 | This program is free software: you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation, either version 3 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | */ |
||
20 | |||
21 | #ifndef _protector_h_ |
||
22 | #define _protector_h_ |
||
23 | |||
24 | #include "tools.h" |
||
25 | |||
26 | /* #define USE_BOOK 1 */ |
||
27 | |||
28 | /* |
||
29 | * Constants |
||
30 | */ |
||
31 | |||
32 | #define MAX_THREADS 32 |
||
33 | #define DEPTH_RESOLUTION 2 |
||
34 | |||
35 | #define _64_ 64 |
||
36 | #define FALSE 0 |
||
37 | #define TRUE 1 |
||
38 | |||
39 | #define VALUE_MATED (-30000) |
||
40 | #define VALUE_ALMOST_MATED (-29900) |
||
41 | #define MAX_MOVES_PER_POSITION (250) |
||
42 | |||
43 | /* #define SEND_HASH_ENTRIES 1 */ |
||
44 | |||
45 | extern int _distance[_64_][_64_]; |
||
46 | extern int _horizontalDistance[_64_][_64_]; |
||
47 | extern int _verticalDistance[_64_][_64_]; |
||
48 | extern int _taxiDistance[_64_][_64_]; |
||
49 | extern const int colorSign[2]; |
||
50 | extern int pieceIndex[16]; |
||
51 | extern int debugOutput; |
||
52 | extern int numPvs; /* for multi pv mode; default is 1 */ |
||
53 | |||
54 | #define MAX_NUM_PV 8 |
||
55 | |||
56 | /** |
||
57 | * Types |
||
58 | */ |
||
59 | typedef unsigned char BYTE; |
||
60 | typedef char INT8; |
||
61 | typedef unsigned char UINT8; |
||
62 | typedef short INT16; |
||
63 | typedef unsigned short UINT16; |
||
64 | typedef int INT32; |
||
65 | typedef unsigned int UINT32; |
||
66 | |||
67 | #define ULONG_ZERO 0 |
||
68 | /* #define ICC */ |
||
69 | #define wV(x,w) (((x)*(w))/256) |
||
70 | typedef long long INT64; |
||
71 | typedef unsigned long long UINT64; |
||
72 | typedef unsigned char bool; |
||
73 | extern UINT64 statCount1, statCount2; |
||
74 | extern const char *programVersionNumber; |
||
75 | |||
76 | typedef enum |
||
77 | { |
||
78 | WHITE, BLACK |
||
79 | } |
||
80 | Color; |
||
81 | |||
82 | typedef enum |
||
83 | { |
||
84 | DARK, LIGHT, ALL |
||
85 | } |
||
86 | SquareColor; |
||
87 | |||
88 | typedef enum |
||
89 | { |
||
90 | RESULT_UNKNOWN, RESULT_WHITE_WINS, RESULT_DRAW, RESULT_BLACK_WINS |
||
91 | } |
||
92 | GameResult; |
||
93 | |||
94 | typedef enum |
||
95 | { |
||
96 | TS_FALSE = 0, TS_UNKNOWN = 1, TS_TRUE = 2 |
||
97 | } |
||
98 | TriStateType; |
||
99 | |||
100 | /* Gameresult values */ |
||
101 | #define GAMERESULT_UNKNOWN "*" |
||
102 | #define GAMERESULT_WHITE_WINS "1-0" |
||
103 | #define GAMERESULT_DRAW "1/2-1/2" |
||
104 | #define GAMERESULT_BLACK_WINS "0-1" |
||
105 | |||
106 | /* Game termination reasons */ |
||
107 | #define GAMERESULT_WHITE_MATES "White mates" |
||
108 | #define GAMERESULT_BLACK_MATES "Black mates" |
||
109 | #define GAMERESULT_WHITE_RESIGNS "White resigns" |
||
110 | #define GAMERESULT_BLACK_RESIGNS "Black resigns" |
||
111 | #define GAMERESULT_WHITE_TIME_FORFEIT "White forfeits on time" |
||
112 | #define GAMERESULT_BLACK_TIME_FORFEIT "Black forfeits on time" |
||
113 | #define GAMERESULT_DRAW_AGREED "Draw agreed" |
||
114 | #define GAMERESULT_STALEMATE "Stalemate" |
||
115 | #define GAMERESULT_REPETITION "Draw by repetion" |
||
116 | #define GAMERESULT_50_MOVE_RULE "Draw by 50 move rule" |
||
117 | #define GAMERESULT_INSUFFICIENT_MATERIAL "Insufficient material" |
||
118 | |||
119 | typedef struct |
||
120 | { |
||
121 | char result[10]; |
||
122 | char reason[128]; |
||
123 | } |
||
124 | Gameresult; |
||
125 | |||
126 | #define PP_BLACK_PIECE 0x01 |
||
127 | #define PP_SLIDING_PIECE 0x02 |
||
128 | #define PP_ORTHOPIECE 0x04 |
||
129 | #define PP_SPECIALPIECE 0x04 |
||
130 | #define PP_DIAPIECE 0x08 |
||
131 | #define PP_NONKINGPIECE 0x08 |
||
132 | |||
133 | typedef enum |
||
134 | { |
||
135 | NO_PIECETYPE = 0x00, |
||
136 | KING = PP_SPECIALPIECE, |
||
137 | QUEEN = PP_SLIDING_PIECE | PP_ORTHOPIECE | PP_DIAPIECE, |
||
138 | ROOK = PP_SLIDING_PIECE | PP_ORTHOPIECE, |
||
139 | BISHOP = PP_SLIDING_PIECE | PP_DIAPIECE, |
||
140 | KNIGHT = PP_NONKINGPIECE, |
||
141 | PAWN = PP_SPECIALPIECE | PP_NONKINGPIECE |
||
142 | } |
||
143 | PieceType; |
||
144 | |||
145 | typedef enum |
||
146 | { |
||
147 | NO_PIECE = 0x00, |
||
148 | WHITE_KING = KING, |
||
149 | WHITE_QUEEN = QUEEN, |
||
150 | WHITE_ROOK = ROOK, |
||
151 | WHITE_BISHOP = BISHOP, |
||
152 | WHITE_KNIGHT = KNIGHT, |
||
153 | WHITE_PAWN = PAWN, |
||
154 | BLACK_KING = BLACK | KING, |
||
155 | BLACK_QUEEN = BLACK | QUEEN, |
||
156 | BLACK_ROOK = BLACK | ROOK, |
||
157 | BLACK_BISHOP = BLACK | BISHOP, |
||
158 | BLACK_KNIGHT = BLACK | KNIGHT, |
||
159 | BLACK_PAWN = BLACK | PAWN |
||
160 | } |
||
161 | Piece; |
||
162 | |||
163 | typedef enum |
||
164 | { |
||
165 | WHITE_BISHOP_DARK = 2, |
||
166 | WHITE_BISHOP_LIGHT = WHITE_BISHOP, |
||
167 | BLACK_BISHOP_DARK = 3, |
||
168 | BLACK_BISHOP_LIGHT = BLACK_BISHOP |
||
169 | } |
||
170 | BishopPiece; |
||
171 | |||
172 | typedef enum |
||
173 | { |
||
174 | NO_SQUARE = -1, |
||
175 | A1, B1, C1, D1, E1, F1, G1, H1, |
||
176 | A2, B2, C2, D2, E2, F2, G2, H2, |
||
177 | A3, B3, C3, D3, E3, F3, G3, H3, |
||
178 | A4, B4, C4, D4, E4, F4, G4, H4, |
||
179 | A5, B5, C5, D5, E5, F5, G5, H5, |
||
180 | A6, B6, C6, D6, E6, F6, G6, H6, |
||
181 | A7, B7, C7, D7, E7, F7, G7, H7, |
||
182 | A8, B8, C8, D8, E8, F8, G8, H8 |
||
183 | } |
||
184 | Square; |
||
185 | |||
186 | typedef enum |
||
187 | { |
||
188 | FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H |
||
189 | } |
||
190 | File; |
||
191 | |||
192 | typedef enum |
||
193 | { |
||
194 | RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8 |
||
195 | } |
||
196 | Rank; |
||
197 | |||
198 | typedef enum |
||
199 | { |
||
200 | NO_CASTLINGS = 0, |
||
201 | WHITE_00 = 1, WHITE_000 = 2, |
||
202 | BLACK_00 = 4, BLACK_000 = 8 |
||
203 | } |
||
204 | Castlings; |
||
205 | |||
206 | /** |
||
207 | * Functions |
||
208 | */ |
||
209 | |||
210 | #define pieceColor( piece ) ((Color) ( (piece) & 0x01 )) |
||
211 | #define pieceType( piece ) ((PieceType) ( (piece) & 0x0E )) |
||
212 | #define opponents( piece1, piece2 ) ( ((piece1)^(piece2)) & 0x01 ) |
||
213 | #define squareColor( square ) ((SquareColor)( (file(square) + rank(square)) % 2 )) |
||
214 | |||
215 | #define file( square ) ((File) ( (square) & 0x07 )) |
||
216 | #define rank( square ) ((Rank) ( (square) >> 3 )) |
||
217 | #define colorRank( color, square ) (Rank) \ |
||
218 | ( (color) == WHITE ? rank(square) : 7-rank(square) ) |
||
219 | #define squareIsValid( square ) ( (square) >= A1 && (square) <= H8 ) |
||
220 | #define getSquare( file, rank ) ((Square) ( (file) + ((rank) << 3) )) |
||
221 | #define getFlippedSquare( square ) \ |
||
222 | ( getSquare ( file(square), (RANK_8-rank(square)) ) ) |
||
223 | #define getHflippedSquare( square ) \ |
||
224 | ( getSquare ( (FILE_H-file(square)), rank(square) ) ) |
||
225 | #define fileName( file ) ( 'a' + (file) ) |
||
226 | #define rankName( rank ) ( '1' + (rank) ) |
||
227 | #define distance(sq1,sq2) (_distance[(sq1)][(sq2)]) |
||
228 | #define horizontalDistance(sq1,sq2) (_horizontalDistance[(sq1)][(sq2)]) |
||
229 | #define verticalDistance(sq1,sq2) (_verticalDistance[(sq1)][(sq2)]) |
||
230 | #define taxiDistance(sq1,sq2) (_taxiDistance[(sq1)][(sq2)]) |
||
231 | #define hasCastlings(color, castlings)(castlingsOfColor[(color)]&(castlings)) |
||
232 | #define upward(color, square)((square)+((color)==WHITE?8:-8)) |
||
233 | #define downward(color, square)((square)+((color)==WHITE?-8:8)) |
||
234 | |||
235 | /** |
||
236 | * Iteration shortcuts |
||
237 | */ |
||
238 | #define ITERATE(sq) for ( sq = A1; sq <= H8; sq++ ) |
||
239 | |||
240 | typedef struct |
||
241 | { |
||
242 | bool processModuleTest; |
||
243 | bool xboardMode; |
||
244 | bool dumpEvaluation; |
||
245 | char *testfile, *bookfile; |
||
246 | char *tablebasePath; |
||
247 | } |
||
248 | CommandlineOptions; |
||
249 | |||
250 | extern CommandlineOptions commandlineOptions; |
||
251 | |||
252 | #endif |