Introducing Lazy Move Generation
[purplehaze.git] / src / common.h
blobf56bad6a0407da51008e1733e9311e218e3c0de1
1 /* PurpleHaze 2.0.0
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/>.
18 #ifndef COMMON_H
19 #define COMMON_H
21 #include <list>
22 #include <vector>
24 #define BOARD_SIZE 128
25 #define MAX_DEPTH 128
26 #define INF 29999
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,
37 OUT
40 enum File : unsigned char {
41 FILE_A,
42 FILE_B,
43 FILE_C,
44 FILE_D,
45 FILE_E,
46 FILE_F,
47 FILE_G,
48 FILE_H
51 enum Rank : unsigned char {
52 RANK_1,
53 RANK_2,
54 RANK_3,
55 RANK_4,
56 RANK_5,
57 RANK_6,
58 RANK_7,
59 RANK_8
62 enum Direction {
63 NO_DIR = 0,
64 UP = 0x10,
65 RIGHT = 0x01,
66 DOWN = -UP,
67 LEFT = -RIGHT,
68 UP_RIGHT = UP + RIGHT,
69 DOWN_RIGHT = DOWN + RIGHT,
70 DOWN_LEFT = DOWN + LEFT,
71 UP_LEFT = UP + 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
82 enum Color : bool {
83 WHITE,
84 BLACK
87 enum PieceType : unsigned char {
88 EMPTY,
89 PAWN,
90 KNIGHT,
91 BISHOP,
92 ROOK,
93 QUEEN,
94 KING
97 enum MoveType : unsigned char {
98 QUIET_MOVE,
99 DOUBLE_PAWN_PUSH,
100 KING_CASTLE,
101 QUEEN_CASTLE,
102 CAPTURE,
103 EN_PASSANT,
104 NULL_MOVE, // warning: is_capture() will return true
105 KNIGHT_PROMOTION = 8, // is_promotion() { MoveType[3] }
106 BISHOP_PROMOTION,
107 ROOK_PROMOTION,
108 QUEEN_PROMOTION,
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] = {
167 {UP_LEFT, UP_RIGHT},
168 {DOWN_LEFT, DOWN_RIGHT}
171 #define assert_msg(x) !(std::cerr << "Assertion failed: " << x << std::endl)
173 #endif /* !COMMON_H */