1 /* Copyright (C) 2007-2012 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define VERSION "2.0.3"
26 static const int BOARD_SIZE
= 128;
27 static const int MAX_PLY
= 128; // Maximum search depth
28 static const int MAX_MOVES
= 256; // Maximum number of moves per position
29 static const int MAX_KILLERS
= 2;
30 static const int INF
= 29999;
31 static const int TT_SIZE
= 128 << 20; // 128 MB
32 static const int MT_SIZE
= 1 << 20; // 1 MB
34 static const std::string DEFAULT_FEN
=
35 "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
37 enum Square
: unsigned char {
38 A1
=0x00, B1
, C1
, D1
, E1
, F1
, G1
, H1
,
39 A2
=0x10, B2
, C2
, D2
, E2
, F2
, G2
, H2
,
40 A3
=0x20, B3
, C3
, D3
, E3
, F3
, G3
, H3
,
41 A4
=0x30, B4
, C4
, D4
, E4
, F4
, G4
, H4
,
42 A5
=0x40, B5
, C5
, D5
, E5
, F5
, G5
, H5
,
43 A6
=0x50, B6
, C6
, D6
, E6
, F6
, G6
, H6
,
44 A7
=0x60, B7
, C7
, D7
, E7
, F7
, G7
, H7
,
45 A8
=0x70, B8
, C8
, D8
, E8
, F8
, G8
, H8
,
49 static const Square SQUARES
[] = {
50 A1
, B1
, C1
, D1
, E1
, F1
, G1
, H1
,
51 A2
, B2
, C2
, D2
, E2
, F2
, G2
, H2
,
52 A3
, B3
, C3
, D3
, E3
, F3
, G3
, H3
,
53 A4
, B4
, C4
, D4
, E4
, F4
, G4
, H4
,
54 A5
, B5
, C5
, D5
, E5
, F5
, G5
, H5
,
55 A6
, B6
, C6
, D6
, E6
, F6
, G6
, H6
,
56 A7
, B7
, C7
, D7
, E7
, F7
, G7
, H7
,
57 A8
, B8
, C8
, D8
, E8
, F8
, G8
, H8
,
61 enum File
: unsigned char {
72 enum Rank
: unsigned char {
89 UP_RIGHT
= UP
+ RIGHT
,
90 DOWN_RIGHT
= DOWN
+ RIGHT
,
91 DOWN_LEFT
= DOWN
+ LEFT
,
93 UP_UP_RIGHT
= UP
+ UP_RIGHT
,
94 RIGHT_UP_RIGHT
= RIGHT
+ UP_RIGHT
,
95 RIGHT_DOWN_RIGHT
= RIGHT
+ DOWN_RIGHT
,
96 DOWN_DOWN_RIGHT
= DOWN
+ DOWN_RIGHT
,
97 DOWN_DOWN_LEFT
= DOWN
+ DOWN_LEFT
,
98 LEFT_DOWN_LEFT
= LEFT
+ DOWN_LEFT
,
99 LEFT_UP_LEFT
= LEFT
+ UP_LEFT
,
100 UP_UP_LEFT
= UP
+ UP_LEFT
103 #ifdef __INTEL_COMPILER
104 enum Color
: unsigned char {
111 static const Color COLORS
[] = { WHITE
, BLACK
};
112 inline Color
operator!(Color c
)
114 return static_cast<Color
>(!static_cast<bool>(c
));
117 enum PieceType
: unsigned char {
126 static const int NB_PIECE_TYPES
= static_cast<int>(KING
) + 1;
128 static const PieceType PIECE_TYPES
[] = {
129 PAWN
, KNIGHT
, BISHOP
, ROOK
, QUEEN
, KING
131 static const PieceType NOT_PAWN_TYPES
[] = {
132 KNIGHT
, BISHOP
, ROOK
, QUEEN
, KING
134 static const PieceType SIDE_TYPES
[] = {
137 static const PieceType MINOR_TYPES
[] = {
140 static const PieceType MAJOR_TYPES
[] = {
144 enum MoveType
: unsigned char {
151 NULL_MOVE
, // Warning: is_capture() will return true
152 KNIGHT_PROMOTION
= 8, // is_promotion() { MoveType[3] }
156 KNIGHT_PROMOTION_CAPTURE
,
157 BISHOP_PROMOTION_CAPTURE
,
158 ROOK_PROMOTION_CAPTURE
,
159 QUEEN_PROMOTION_CAPTURE
162 // Used in movegen.cpp and attack.cpp
163 static const int NB_DIRS
[] = { 0, 0, 8, 4, 4, 8, 8 };
164 static const Direction PIECES_DIRS
[][8] = {
166 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
169 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
172 UP_UP_RIGHT
, RIGHT_UP_RIGHT
, RIGHT_DOWN_RIGHT
, DOWN_DOWN_RIGHT
,
173 DOWN_DOWN_LEFT
, LEFT_DOWN_LEFT
, LEFT_UP_LEFT
, UP_UP_LEFT
176 UP_RIGHT
, DOWN_RIGHT
, DOWN_LEFT
, UP_LEFT
,
177 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
180 UP
, RIGHT
, DOWN
, LEFT
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
183 UP
, UP_RIGHT
, RIGHT
, DOWN_RIGHT
, DOWN
, DOWN_LEFT
, LEFT
, UP_LEFT
186 UP
, UP_RIGHT
, RIGHT
, DOWN_RIGHT
, DOWN
, DOWN_LEFT
, LEFT
, UP_LEFT
190 // Used in movegen.cpp and protocol.cpp
191 static const Direction PAWN_PUSH_DIRS
[] = { UP
, DOWN
};
192 static const Direction PAWN_CAPTURE_DIRS
[][2] = {
197 DOWN_LEFT
, DOWN_RIGHT
202 enum Bound
: unsigned char { EXACT
, LOWER
, UPPER
, UNDEF_BOUND
};
204 // Used in game.h, hashtable.cpp
205 // NOTE: sizeof(Material) + sizeof(Hash) must be a power of two
206 // for efficient material hashtable lookup.
207 typedef uint64_t Material
;
209 // Used for debugging
210 #define assert_msg(x) !(std::cerr << "Assertion failed: " << x << std::endl)
212 // Overload operators to solve ambiguous errors with Clang < 3.1
213 // TODO Find out if this could be better done
214 inline bool operator==(int i
, Rank r
)
216 return i
== static_cast<int>(r
);
218 inline bool operator<(Bound b
, int i
)
220 return static_cast<char>(b
) < i
;
222 inline int operator>>(Square s
, int i
)
224 return static_cast<int>(s
) >> i
;
226 inline int operator|(int i
, MoveType mt
)
228 return i
| static_cast<int>(mt
);
230 inline int operator&(Square s
, int i
)
232 return static_cast<int>(s
) & i
;
234 inline int operator*(Rank r
, Color c
)
236 return static_cast<int>(r
) * static_cast<int>(c
);
238 inline int operator*(int i
, Rank r
)
240 return i
* static_cast<int>(r
);
242 inline int operator*(int i
, Color c
)
244 return i
* static_cast<int>(c
);
246 inline int operator*(int i
, PieceType pt
)
248 return i
* static_cast<int>(pt
);
250 inline int operator+(int i
, File f
)
252 return i
+ static_cast<int>(f
);
254 inline int operator+(int i
, Square s
)
256 return i
+ static_cast<int>(s
);
258 inline int operator+(int i
, PieceType pt
)
260 return i
+ static_cast<int>(pt
);
262 inline int operator+(PieceType pt
, int i
)
264 return i
+ static_cast<int>(pt
);
266 inline int operator+(Square s
, int i
)
268 return i
+ static_cast<int>(s
);
270 inline int operator+(Square a
, Square b
)
272 return static_cast<int>(a
) + static_cast<int>(b
);
274 inline int operator+(Rank r
, int i
)
276 return static_cast<int>(r
) + i
;
278 inline int operator+(char c
, Rank r
)
280 return c
+ static_cast<char>(r
);
282 inline int operator+(Square s
, Direction d
)
284 return static_cast<int>(s
) + static_cast<int>(d
);
286 inline int operator-(Square a
, Square b
)
288 return static_cast<int>(a
) - static_cast<int>(b
);
290 inline int operator-(Square s
, int i
)
292 return static_cast<int>(s
) - i
;
294 inline int operator-(int i
, Square s
)
296 return i
- static_cast<int>(s
);
298 inline int operator-(int i
, PieceType pt
)
300 return i
- static_cast<int>(pt
);
302 inline int operator-(Rank a
, Rank b
)
304 return static_cast<int>(a
) - static_cast<int>(b
);
306 inline int operator-(Rank r
, int i
)
308 return static_cast<int>(r
) - i
;
310 inline int operator+(MoveType a
, MoveType b
)
312 return static_cast<MoveType
>(static_cast<int>(a
) + static_cast<int>(b
));
316 static const std::string color_red
= "\x1b[31m";
317 static const std::string color_green
= "\x1b[32m";
318 static const std::string color_reset
= "\x1b[0m";
320 #endif /* !COMMON_H */