2 * Copyright (C) 2007-2011 Vincent Ollivier
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #define BOARD_SIZE 128
28 enum Square
: unsigned char {
29 A1
=0x00, B1
, C1
, D1
, E1
, F1
, G1
, H1
,
30 A2
=0x10, B2
, C2
, D2
, E2
, F2
, G2
, H2
,
31 A3
=0x20, B3
, C3
, D3
, E3
, F3
, G3
, H3
,
32 A4
=0x30, B4
, C4
, D4
, E4
, F4
, G4
, H4
,
33 A5
=0x40, B5
, C5
, D5
, E5
, F5
, G5
, H5
,
34 A6
=0x50, B6
, C6
, D6
, E6
, F6
, G6
, H6
,
35 A7
=0x60, B7
, C7
, D7
, E7
, F7
, G7
, H7
,
36 A8
=0x70, B8
, C8
, D8
, E8
, F8
, G8
, H8
,
40 enum File
: unsigned char {
51 enum Rank
: unsigned char {
68 UP_RIGHT
= UP
+ RIGHT
,
69 DOWN_RIGHT
= DOWN
+ RIGHT
,
70 DOWN_LEFT
= DOWN
+ LEFT
,
72 UP_UP_RIGHT
= UP
+ UP_RIGHT
,
73 RIGHT_UP_RIGHT
= RIGHT
+ UP_RIGHT
,
74 RIGHT_DOWN_RIGHT
= RIGHT
+ DOWN_RIGHT
,
75 DOWN_DOWN_RIGHT
= DOWN
+ DOWN_RIGHT
,
76 DOWN_DOWN_LEFT
= DOWN
+ DOWN_LEFT
,
77 LEFT_DOWN_LEFT
= LEFT
+ DOWN_LEFT
,
78 LEFT_UP_LEFT
= LEFT
+ UP_LEFT
,
79 UP_UP_LEFT
= UP
+ UP_LEFT
87 enum PieceType
: unsigned char {
97 enum MoveType
: unsigned char {
104 NULL_MOVE
, // warning: is_capture() will return true
105 KNIGHT_PROMOTION
= 8, // is_promotion() { MoveType[3] }
109 KNIGHT_PROMOTION_CAPTURE
,
110 BISHOP_PROMOTION_CAPTURE
,
111 ROOK_PROMOTION_CAPTURE
,
112 QUEEN_PROMOTION_CAPTURE
115 // Used in movegen.cpp and attack.cpp
116 const int NB_DIRS
[] = { 0, 0, 8, 4, 4, 8, 8 };
118 const Direction NO_DIRS[8] = {
119 NO_DIR, NO_DIR, NO_DIR, NO_DIR, NO_DIR, NO_DIR, NO_DIR, NO_DIR
121 const Direction KNIGHT_DIRS[8] = {
122 UP_UP_RIGHT, RIGHT_UP_RIGHT, RIGHT_DOWN_RIGHT, DOWN_DOWN_RIGHT,
123 DOWN_DOWN_LEFT, LEFT_DOWN_LEFT, LEFT_UP_LEFT, UP_UP_LEFT
125 const Direction BISHOP_DIRS[8] = {
126 UP_RIGHT, DOWN_RIGHT, DOWN_LEFT, UP_LEFT, NO_DIR, NO_DIR, NO_DIR, NO_DIR
128 const Direction ROOK_DIRS[8] = {
129 UP, RIGHT, DOWN, LEFT, NO_DIR, NO_DIR, NO_DIR, NO_DIR
131 const Direction QUEEN_DIRS[8] = {
132 UP, UP_RIGHT, RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT
134 const Direction KING_DIRS[8] = {
135 UP, UP_RIGHT, RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT
138 const Direction PIECES_DIRS
[][8] = {
140 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
143 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
146 UP_UP_RIGHT
, RIGHT_UP_RIGHT
, RIGHT_DOWN_RIGHT
, DOWN_DOWN_RIGHT
,
147 DOWN_DOWN_LEFT
, LEFT_DOWN_LEFT
, LEFT_UP_LEFT
, UP_UP_LEFT
150 UP_RIGHT
, DOWN_RIGHT
, DOWN_LEFT
, UP_LEFT
,
151 NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
154 UP
, RIGHT
, DOWN
, LEFT
, NO_DIR
, NO_DIR
, NO_DIR
, NO_DIR
157 UP
, UP_RIGHT
, RIGHT
, DOWN_RIGHT
, DOWN
, DOWN_LEFT
, LEFT
, UP_LEFT
160 UP
, UP_RIGHT
, RIGHT
, DOWN_RIGHT
, DOWN
, DOWN_LEFT
, LEFT
, UP_LEFT
164 // Used in movegen.cpp and protocol.cpp
165 const Direction PAWN_PUSH_DIRS
[2] = { UP
, DOWN
};
166 const Direction PAWN_CAPTURE_DIRS
[2][2] = {
168 {DOWN_LEFT
, DOWN_RIGHT
}
171 #define assert_msg(x) !(std::cerr << "Assertion failed: " << x << std::endl)
173 #endif /* !COMMON_H */